| ??? 07/26/00 21:11 Read: times |
#3999 - RE: Rotary knob and INT in C |
Hy Sylvan,
I used also a mechanical knob. Yes you need a debouncing on these. On my knob I get all 4 phases on every step. E.g. if you connect it to P1.0 and P1.1 you get the following sequences: CW: 0-1-3-2-0-1-3-2-0-1 Val:5-6-6-6-6-7-7-7-7-8 CCW: 0-2-3-1-0-2-3-1-0 Val: 5-5-5-5-4-4-4-4-3 To read it out, I scan it with the timer interrupt every 256 cycle (T0 in mode 3). And if the last reading was 0 and the current was 1 the value was incremented, but if changing from 1 to 0 the value was decremented. But how was the debouncing done ? Its already included ! A mechanical contact vibrate and can give the following reading: CW: 0-1,0,1-3,1,3-2,3,2-0,2,0 You can see 2 changes 0-1, and also 1 change 1-0. This result in 2 increasing and 1 decreasing and result so only in 1 pulse, how it was wanted. The C program: char val; void digital_pot(void) interrupt 1 { static char old = 4; char tmp; tmp = P1 & 3; // mask P1.0 and P1.1 if( old == 0 && tmp == 1 ) val++; else if( old = 1 && tmp == 0 ) val--; old = tmp; } Peter |
| Topic | Author | Date |
| 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 |



