Search code examples
embeddedgpionoise-reduction

Read noisy data from GPIO


In an embedded programming project for FreeRTOS/ARM, I attempted to read 24 bits of data on a noise GPIO signal. While idle, the signal has a lot of random noises; during the actual data, the noise is suppressed and only the signal data will be read. The data signal consists of a preamble of 300us HIGH (1) followed by 31x300us LOW (0) and then each bit 1 is a 900us HIGH and 300us LOW and bit 0 is 300us LOW followed by 900us HIGH.

I did measurements using a simple tight GPIO read loop that shows an average 388 reads in 300us.

So I attempted to count my reads, with an epsilon of +/- 15 reads, of HIGH and LOW and determine if I read the preamble or the bits following that using a state machine. But I can't detect any preamble or data. I suspect that additional codes in the real reading codes, even though not too complex, would result in different read frequency compared to the simple measuring loop. What would be the correct way to read such data?


Solution

  • I figured out. The method is sound. The problem are

    1. even though it is an RTOS, attempt to print debug information on the console during the I/O loop is a no-no, even if very little data are printed; it would quickly disturb the timing. Once I removed the debugging output in the loop, it works correctly.
    2. the relative timing between the short and long signals are correct but the exact timing can still vary greatly (even after removing the debug output.) In my case, the short time span can range from 180 to 288 reads.