Search   
Home  Print View  

 

P112

Branch Content

GPI reading and debouncing

Reading and debouncing GPIs is handled by routine ReadGPI which is called continuously in the Main Loop. As a user, your only concern about whether flag F_GPI_READY (bit 0 of variable FLAGS) is set indicating that GPI reading is stable (debounced).

The ReadGPI routine works as following:

All GPIs are read at once from ports PORTA and PORTB. Literals GPIO_CFG_A and GPIO_CFG_B are used to mask GPOs. This is important to know because those literals are defined in user code (file user.h).

Values read from the ports are stored in temporary variables and virtual timer VT0 is started. As a consequence of this, flag F_VT0_BUSY (bit 1 of variable FLAGS) is set indicating that VT0 is counting.

When the ReadGPI routine is called again in the Main Loop, it returns immediately as this routine checks the F_VT0_BUSY flag. If set, it does nothing, just returns.

VT0 time out occurs 10 milliseconds later causing the F_VT0_BUSY flag to clear. The next time ReadGPI is called from the Main Loop, GPIs are read again from PORTA and PORTB, then compared with previos values. If they match, flag F_GPI_READY is set completing the job. If not, the new values are stored in temporary variables again and VT0 is started to give it another try.

This process is tried three times. If no two consecutives reading can be obtained, the alarm LED is turned on and reading is aborted all together.

Online Manuals -- this software is based on Help Books running at melissa