Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
07/27/00 10:50
Read: times


 
#4012 - RE: Rotary knob and INT in C
Hi Sylvain,

> Also there isn’t polling.

You can mix it. After some seconds (or minutes) polling without changing, you go to idle or power down.
And wake up at the next 1-0 transition.
This can cause, that the knob must be turned more then 1 step
to wake up again. But I think this can be tolerated since it only occur, if the knob was not moved a longer time.


> static char old =4

The static statement works in the follwing way:
1.
the variable (old) was set only 1 time during initianization before main() was called.
2.
the variable (old) was not affected until the next call of the function.

So the 1st call see the initial value (4) and all next see the
value from the previous call.


> It’s not natural to have click, click, click, click for 1 step.

It seems, your knob differ from mine. I get only 1 click
on a 4 phase cycle (0-1-3-2-0) and 10 clicks per turn.

But I think your knob can also be used in a similiar way with a little more code.
The fastest solution, I think, combine old and new to a 4 bit value
and use a table (16 entries).
E.g.:

tmp = P1 & 3;
char code steps[16] = { 1, -1, 0, ... }; // not right now !
val += steps[(old<<2) | tmp];
old = tmp;



> If the knob is turned slowly the frequency is incremented by 10kHz ; if it’s turned faster the frequence is incremented from 500kHz (for example).

To do it you need also a timer interrupt e.g. every 100ms. Then get the counter value, and clear it. These counts per 100ms represent the speed and on comparing with a defined thresold you can decide slow and fast moving. On fast moving multiply it by 5 and add it to the value which must be changed.
This calculations must be done on signed numbers to serve also the reverse direction.


> my C51(Keil V3.07) doesn’t support the comment with //)

I use Keil: MS-DOS C51 COMPILER V5.02
It support //.


Peter


List of 13 messages in thread
TopicAuthorDate
Rotary knob and INT in C            01/01/70 00:00      
RE: Rotary knob and INT in C            01/01/70 00:00      
RE: Rotary knob and INT in C            01/01/70 00:00      
RE: Rotary knob and INT in C            01/01/70 00:00      
RE: Rotary knob and INT in C            01/01/70 00:00      
RE: Rotary knob and INT in C            01/01/70 00:00      
RE: Rotary knob and INT in C            01/01/70 00:00      
RE: Rotary knob and INT in C            01/01/70 00:00      
RE: Rotary knob and INT in C            01/01/70 00:00      
RE: Rotary knob and INT in C            01/01/70 00:00      
RE: Rotary knob and INT in C            01/01/70 00:00      
RE: Rotary knob and INT in C            01/01/70 00:00      
RE: Rotary knob and INT in C            01/01/70 00:00      

Back to Subject List