Sorry das es so lang gedauert hat, hier meine funktinierende Lösung:
Wenn es um 2 stellen springt, also 00->11 oder 11->00, dann ergibt sich
aus meiner links/rechts abfrage für beides eine 1, ich gehe zum else.
Dort wird die letzte Absolute Position überprüft.
(Wenn er dann nur zwischen 2 zahlen pendelt, muss ich pins tauschen/ bzw
+- in dieser else routine vertauschen)
Ich hoffe ihr versteht was ich mein
@Lothar Miller, danke ;)
1 |
|
2 | // Change in State on both important positions?
|
3 | if ( (enc_1.buffer_new_state ^ enc_1.last_count) == ((1<<Increment_1_A )|(1<<Increment_1_B)) )
|
4 | {
|
5 | enc_1.time2 ++; // for fast counting
|
6 |
|
7 | // right or left turn?
|
8 | if ( (enc_1.buffer_new_state ^ enc_1.last_state) == (1<<Increment_1_B ) )
|
9 | {enc_1.delta += enc_1.add;}
|
10 |
|
11 | else if ( (enc_1.buffer_new_state ^ enc_1.last_state) == (1<<Increment_1_A ) )
|
12 | {enc_1.delta -= enc_1.add;}
|
13 | else
|
14 | /**/
|
15 | // This Part is normaly not required.But the rotary encoder in use has this Graycode: 00-10-11-00-10-11-00
|
16 | // Therefore it evaluetes the last position to determine the turn-direction
|
17 | // In case of failure, change + and - in the following
|
18 | /**/
|
19 | {
|
20 | if(enc_1.last_state != 0)
|
21 | enc_1.delta += enc_1.add;
|
22 | else
|
23 | enc_1.delta -= enc_1.add;
|
24 | }
|
25 |
|
26 | enc_1.last_count = enc_1.buffer_new_state; // save Bitcombination of last count
|
27 | }//if
|
28 |
|
29 | enc_1.last_state = enc_1.buffer_new_state; // save last state
|