Definition in file encoder.h.
#include "global.h"
#include "encoderconf.h"
Go to the source code of this file.
Defines | |
#define | IMSK GIMSK |
Typedefs | |
typedef struct_EncoderState | EncoderStateType |
Encoder state structure. | |
Functions | |
void | encoderInit (void) |
encoderInit() initializes hardware and encoder position readings | |
void | encoderOff (void) |
encoderOff() disables hardware and stops encoder position updates | |
s32 | encoderGetPosition (u08 encoderNum) |
encoderGetPosition() reads the current position of the encoder | |
void | encoderSetPosition (u08 encoderNum, s32 position) |
encoderSetPosition() sets the current position of the encoder |
|
To keep track of the encoder position in software, we connect PhaseA to an external processor interrupt line, and PhaseB to any I/O pin. We set up the external interrupt to trigger whenever PhaseA produces a rising edge. When a rising edge is detected, our interrupt handler function is executed. Inside the handler function, we quickly check the PhaseB line to see if it is high or low. If it is high, we increment the encoder's position counter, otherwise we decrement it. The encoder position counter can be read at any time to find out the current position. |