Hallo, ich wollte einen Drehencoder (ALPS E12D mit Taster) mithilfe der
Routinen von PeDa ansteuern.
Leider komme ich nicht weiter. Da ich einen Atmega644 verwende, habe ich
die Timer-Routine angeändert:
1 | void encode_init( void )
|
2 | {
|
3 | int8_t new;
|
4 |
|
5 | new = 0;
|
6 | if( PHASE_A )
|
7 | new = 3;
|
8 | if( PHASE_B )
|
9 | new ^= 1; // convert gray to binary
|
10 | last = new; // power on state
|
11 | enc_delta = 0;
|
12 | TCCR0B = 1<<WGM01;
|
13 | ^1<<CS01^1<<CS00; // CTC, XTAL / 64
|
14 | OCR0B = (uint8_t)(F_CPU / 64.0 * 1e-3 - 0.5); // 1ms // F_CPU = 22.1Mhz
|
15 | TIMSK0 |= 1<<OCIE0B;
|
16 | }
|
17 |
|
18 |
|
19 | ISR( TIMER0_COMPA_vect ) // 1ms for manual movement
|
20 | {
|
21 | int8_t new, diff;
|
22 |
|
23 | new = 0;
|
24 | if( PHASE_A )
|
25 | new = 3;
|
26 | if( PHASE_B )
|
27 | new ^= 1; // convert gray to binary
|
28 | diff = last - new; // difference last - new
|
29 | if( diff & 1 ){ // bit 0 = value (1)
|
30 | last = new; // store new as next last
|
31 | enc_delta += (diff & 2) - 1; // bit 1 = direction (+/-)
|
32 | }
|
33 | }
|
Aber ich bekomme keine Ausgaben. Ich vermute mal, dass mein Timer-Gedöns
nicht stimmt.
Den Encoder habe ich mit PinA an PHASE_A(=PC3) und PinB an PHASE_B(=PC4)
angeschlossen. PinC=GND und PinE=VCC. PinD=PC2 (Taster). Stimmt die
Beschaltung?