CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

need help for rotary encoder
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
cybanical



Joined: 10 Apr 2008
Posts: 6
Location: Oakland, CA

View user's profile Send private message

thanks
PostPosted: Tue Apr 15, 2008 10:00 am     Reply with quote

Great, thanks for the direction, that makes sense. I found the memory organization charts in the data sheets (table 5.1 for the 18f4520), I had looked before but didn't really know what i was looking for.

I made an R/2R ladder last night and managed to turn my encoder into a pot. Next for me is to determine velocity and turn that into a velocity.
_________________
cybanical == cyber+mechanical
EC



Joined: 26 Aug 2008
Posts: 3
Location: Belgium

View user's profile Send private message

Rotary Encoder (Fast and Slow Mode)
PostPosted: Tue Aug 26, 2008 10:06 am     Reply with quote

Ttelmah wrote:

Code:

int16 position;

#int_global
void myint(void) {
   static int old;
   static int new;
   static int value;
   //Here I have an edge on one of the quadrature inputs
   new=portb;
   /*Now I have to decode the quadrature changes. There are four
   possibilities:
   I can have a rising or falling edge, on each of the two inputs. I have to
   look at the state of the other bit, and increment/decrement according to
   this. */
   value=new^old;
   //'value', now has the bit set, which has changed
   if (value & 0x10) {
      //Here the low bit has changed
      if (new & 0x10) {
         //Here a rising edge on A
         if (new & 0x20) --position;
         else ++position;
      }
      else {
         //Here a falling edge on A
         if (new & 0x20) ++position;
         else --position;
      }
   }
   else {
      //Here the high bit (B) must have changed
      if (new & 0x20) {
         //Here a rising edge on B
         if (new & 0x10) ++position;
         else --position;
      }
      else {
         //Here a falling edge on B
         if (new & 0x10) --position;
         else ++position;
      }
   }
   old=new;
   bchanged=0;
#asm
   //Here the 'fast' exit.
   RETFIE  1
#ENDASM
}




Hello,

I'm use a rotary encoder switch from ALPS (EC12 series) and the code from Ttelmah works perfectly with it! But, I'd like have two levels when I'm increase or decrease a counter variable.
Like this: in Normal(slow) mode, I'm increase/decrease per one unit and in Fast mode, per ten units.
How can I change the code to do what I want?

Thanks in advance,

EC
Ttelmah
Guest







PostPosted: Tue Aug 26, 2008 10:23 am     Reply with quote

You would need to do something like:
Code:

int16 position;
int1 big_increment=FALSE;

#int_global
void myint(void) {
   static int old;
   static int new;
   static int value;
   //Here I have an edge on one of the quadrature inputs
   new=portb;
   /*Now I have to decode the quadrature changes. There are four
   possibilities:
   I can have a rising or falling edge, on each of the two inputs. I have to
   look at the state of the other bit, and increment/decrement according to
   this. */
   value=new^old;
   //'value', now has the bit set, which has changed
   if (value & 0x10) {
      //Here the low bit has changed
      if (new & 0x10) {
         //Here a rising edge on A
         if (new & 0x20) {
              if (big_increment) position-=10;
              else --position;
         }
         else {
              if (big_increment) position+=10;
              else ++position;
         }
      }
      else {
         //Here a falling edge on A
         if (new & 0x20) {
              if (big_increment) position+=10;
              else ++position;
         }
         else {
              if (big_increment) position-=10;
              else --position;
         }
      }
   }
   else {
      //Here the high bit (B) must have changed
      if (new & 0x20) {
         //Here a rising edge on B
         if (new & 0x10) {
             if (big_increment) position+=10;
             else ++position;
         }
         else {
             if = (big_increment) position-=10;
             else --position;
         }
      }
      else {
         //Here a falling edge on B
         if (new & 0x10) {
             if (big_increment) position-=10;
             else --position;
         }
         else {
             if (big_increment) position+=10;
             else ++position;
         }
      }
   }
   old=new;
   bchanged=0;
#asm
   //Here the 'fast' exit.
   RETFIE  1
#ENDASM
}

Then set 'big_increment' to true when you want the fast increment, and false, when not.

This will slightly reduce the maximum speed the encoder can be handled, but for a normal rotary wheel shouldn't matter.

Best Wishes
EC



Joined: 26 Aug 2008
Posts: 3
Location: Belgium

View user's profile Send private message

PostPosted: Tue Aug 26, 2008 10:44 am     Reply with quote

Ttelmah wrote:
You would need to do something like:
Then set 'big_increment' to true when you want the fast increment, and false, when not.


Hi Ttelmah,

First, thanks for your quick answer.
I understand the principle with "big_increment" but at which moment must I set or clear this flag?

Best regards,
EC
Ttelmah
Guest







PostPosted: Tue Aug 26, 2008 2:56 pm     Reply with quote

When you want the larger increment.....
You have not said how you want to trigger this. I'd assume you are going to use a button or something?.

Best Wishes
EC



Joined: 26 Aug 2008
Posts: 3
Location: Belgium

View user's profile Send private message

PostPosted: Tue Aug 26, 2008 3:27 pm     Reply with quote

Maybe, a little more explain to what I'm working is welcome Smile

I'd made a Countdown Timer with a rotary encoder switch (EC12 from ALPS) and a relay.

I have also two buttons: one for start/stop and other one for Reset timer.

The principle of "Fast" and "Slow" mode then I'd like reproduce, It's like the "big button" of a generator functions to choose the Frequency. In this case, if you turn slowly, it's increment/decrement per unit but if you turn faster, it's increment/decrement per 10 or whatever without triggered with a button.

I hope You see my goal with the rotary encoder.

Best Regards,
EC
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group