Hello all,
I'm using a 2 phase quadrature increamental rotary encoder, with open collector NPN output and 600 pulses per revolution. I'm sensing both A and B values at ports 1.2 and 1.4. The program is shown below,
#include <msp430g2553.h>
#define PHASEA BIT2
#define PHASEB BIT4
int clockwise;
int anticlockwise;
void update(void);
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
clockwise = 0;
anticlockwise= 0;
P1DIR &= ~(PHASEA + PHASEB); // Set P1.2 and P1.4 as inputs
P1IFG &= ~(PHASEA ); // clear interrrupt flags for P1.2
P1IE |= PHASEA ; // P1.2 interrupt enabled
P1IES &= ~PHASEA ; // interrupt arises on rising edge
__enable_interrupt(); // enable all interrupts
}
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
if (PHASEA != PHASEB)
{ clockwise++; }
else { anticlockwise++; }
P1IFG =0;
}
When the encoder shaft is rotated 360 degree clockwise, variable clockwise shows the exact count of 600. But when rotated 360 degree in counter clockwise direction, variable clockwise shows 1200.Variable anticlockwise doesn't change but clockwise does.Any suggestions ?