This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C1237E6PM: How fast can I read an input pin with GPIO_PinRead?

Part Number: TM4C1237E6PM

I am trying to read input PA2 on the TIVA device every 100ms, using a SW timer, storing the 1/0 value in a 16-bit shift register.  I am sending in a 5Hz square wave from a frequency generator.  The shift register toggles between 0xAAAA and 0x5555, but every so often a string of 0's is read and the shift register changes to 0x0000.  I've logged a max of 22 consecutive 0's from the read.  The consecutive 0's occur randomly, sometimes only 7 seconds apart, and sometimes 65 seconds apart.

The PA2 pin is defined this way in file pin_mux.c

// Enable pin PA2, PA3, PA4, PA5, PA6 for GPIOInput
MAP_GPIOPinTypeGPIOInput(GPIO_PORTA_BASE,
(GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6));

The pin is read this way

BT_stat_val = ((GPIOPinRead(GPIO_PORTA_BASE, PA2_BLUETOOTH_STAT) & PA2_BLUETOOTH_STAT) >> 2);
if (BT_stat_val == 0)
consecutive_0s++;
else
consecutive_0s = 0;

I'm looking for a reason why GPIOPinRead is reading the sequence of 0's.  I've verified the input signal on a scope and it's a continuous square wave.  Is it possible I'm trying to read the input too fast?

  • Hi Chuck,

      First of all the 5Hz input means 200ms on a period. Suppose the input is 50% duty cycle on the high phase and low phase then each phase is 100ms.  If it is not 50% then it will be even worst. For example, the high phase is 10ms and the low phase is 190mS. You are trying the sample the input at 100ms and this will be a problem as you violate the Nyquist criterion where a repetitive waveform can be correctly reconstructed provided that the sampling frequency is greater than double the highest frequency to be sampled. If your input cannot be slowed down, then I will suggest you increase your sampling frequency from 100ms to something like 50ms or faster assuming the input is 50% duty cycle. If the high phase is like 10ms then your sampling frequency needs to be 50ms or faster. 

     Another question is how are you creating the 100mS using SW timer? Are you using the SysCtlDelay()? I will strongly suggest you use the hardware timer for this job. The SW timer you create can be subject to interrupts that causes extra latency which will result in inaccuracy..