[sdiy] [SOLVED] Need goog working rotary encoder in C code..

Jean-Pierre Desrochers jpdesroc at oricom.ca
Sat Aug 7 23:46:57 CEST 2021


Hi all,

I found my problem  (I think).

No interrupts for this job.

The following polling code works very well.

 

while(1)

{

. 

.

   ////////// read rotary encoder here /////////////   

   currentStateCLK = ROTARY_B;

   if (currentStateCLK != lastStateCLK  && currentStateCLK == 1)

    {

     if (ROTARY_A != currentStateCLK)   

         {

       scale_counter --;

       // currentDir ="CCW";

      } 

     else 

      {

       // Encoder is rotating CW so increment

       scale_counter ++;

       //currentDir ="CW";

      }   

    }

 

  // Remember last CLK state

  lastStateCLK = currentStateCLK; 

 

 __delay_us(500);  

.

.

.

}

 

Now everything works well even with a 1msec interrupt  on TIMER1.
Blinking a variable every 200 interrupts.
When the encoder moves it bilnks the choice on an LCD
at a rate of 1/(2x200msec) => 2,5Hz rate.
When the encoder's push button is pressed
change is then accepted and the display stops blinking.
Polling the encoder's A & B pins. No encoder missed counts so far..

 

THANK YOU FOR YOU ALL !

JP

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://synth-diy.org/pipermail/synth-diy/attachments/20210807/c7538a89/attachment.htm>


More information about the Synth-diy mailing list