|
|
View previous topic :: View next topic |
Author |
Message |
cybanical
Joined: 10 Apr 2008 Posts: 6 Location: Oakland, CA
|
thanks |
Posted: Tue Apr 15, 2008 10:00 am |
|
|
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
|
Rotary Encoder (Fast and Slow Mode) |
Posted: Tue Aug 26, 2008 10:06 am |
|
|
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
|
|
Posted: Tue Aug 26, 2008 10:23 am |
|
|
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
|
|
Posted: Tue Aug 26, 2008 10:44 am |
|
|
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
|
|
Posted: Tue Aug 26, 2008 2:56 pm |
|
|
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
|
|
Posted: Tue Aug 26, 2008 3:27 pm |
|
|
Maybe, a little more explain to what I'm working is welcome
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 |
|
|
|
|
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
|