Jump to content
43oh

Incremental Rotary Encorder on MSP430


Recommended Posts

Hallo guys,

I am working on MSP430 and want to use incremental rotary encoder to control the menu, that I will later make.

I decide to try to flicker the both LED first to see if I have the right programm to take input from the rotary encoder. 

I have the A_Output (CLK) and B_Output (DT) on Pins 2.1 and 2.2

#include "msp430g2553.h"

char c_P2IN;

void main(void)
{
    WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
    P2OUT |= 0x07;
    P2REN |= 0x07;
    P1DIR |= 0x41; // Set P1.0 and P1.6 to output direction
    P2IE |= 0x07; // P2 (Bit0, Bit1 und Bit2) interrupt enabled
    P2IFG = 0x00; // P2IFG cleared
    _BIS_SR(LPM4_bits + GIE); // Enter LPM4 w/interrupt
    
    while(1)
    {
        c_P2IN = P2IN; //Monitoring the P2IN;
    }
}

// Port 1 interrupt service routine
#pragma vector=PORT2_VECTOR
__interrupt void Port_2(void)
{
    if(P2IFG&BIT1)
    {
        if (!(c_P2IN&BIT2))
        {
            P1OUT^= BIT6;
            _delay_cycles(100);
            P2IFG = 0x00;
        }
    }

	if(P2IFG&BIT2)
    {
        if (!(c_P2IN&BIT21))
        {
            P1OUT^= BIT0;
            _delay_cycles(100);
            P2IFG = 0x00;
        }
    }

}

It works for maybe 4-5 turns, and then it doesn't for 2 turns, and for the next few turns it works again. 

Can you please give me idea how to do it?

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...