Post Go back to editing

ADuC360 - Button rotary encoder

Category: Software
Product Number: ADUCM360BCPZ128

Hello,

i have a project where i need to interface a rotary encoder with 2 signals. 

This is used for user incrementing/decrementing values inside the software.

Since this is my first aproach to work with this microcontroler, i was wondering what is the recomended way to use in such way.

On other uc types i usually interface the 2 encoder signals to some timer input capture pins. But i am wondering how to manage this on the ADuCM360.

Thank you.

  • Hi,

    A rotary encoder might not be the best option for you if you are just starting with the microcontroller. I will recommend using two push buttons for now and using the interrupt functions of the ADuCM360 to record each press on the push buttons 

    regards,

    Mark

  • Hi Mark,

    in the end i used the button logic, because the rotary encoder is somehow forming a sequence of switches being pushed or not.

    Using the external interupts available on ADuC360 i came up with this code, maybe it wil be usefull for others aswell


    void Ext_Int6_Handler ()
    {
    AB= (DioRd(pADI_GP1) & 0x60);
    AB=AB>>5;

    if((eflag==0)&&(AB==0x02)) //1st time and 10 pattern?
    {
    eflag=1;
    AB=0; // reset value
    }
    else if((eflag==0) && ( AB==0x3))
    {

    eflag=1;

    }

    if((eflag==1)&&(AB==0x01)) //2nd time 01 pattern - dir CW
    {
    eflag=0;
    eDir=1; //cw flagv
    }
    else if((eflag==1) && ( AB==0x3))//2nd time, pattern 00 - dir CCW
    {
    eDir=2; // ccw flag
    eflag=0;

    }

    if((eflag==0)&&(AB==0))
    {
    eflag=0; // keep flag 0 until a valid pattern is read from gpio
    eDir=0; // keep direction in reset
    }

    EiClr(EXTINT6);
    }

    // Function to be called where you need
    int Encoder_Get_Status(void) {

    if (eDir ==1 ) {
    eDir=0;
    return 1;
    }
    else if(eDir==2)
    {
    eDir=0;
    return -1;
    }
    else
    {
    eDir=0;
    return 0;
    }


    }