Hi, I tried to make my quadrature incremental encoder to respond immediatly when rotation occurs.
I used Interrupts for this.
But somehow it only react on half of the pulses!?
A 1 1 0 0
B 0 1 1 0
This is just some demo code to visualize the encoder with some variables of the PICAXE chip on the "PICAXE Editor 6" debug screen.
What's wrong here with the code?
I used Interrupts for this.
But somehow it only react on half of the pulses!?
A 1 1 0 0
B 0 1 1 0
This is just some demo code to visualize the encoder with some variables of the PICAXE chip on the "PICAXE Editor 6" debug screen.
- incA and incB are the interrupt pins,
- EncoderA and EncoderB are variables to display pins state,
- InterruptCounter should just increase on every next turn of the Rotary encoder.
- This only result in 2 times increase and 2 times no increase!?
Code:
#PICAXE 20X2
SetFreq M8
Init:
'PIN's.
Symbol incA = pinB.0
Symbol incB = pinB.1
'VARIABLES.
Symbol InterruptCounter=b1
Symbol EncoderA=b2
Symbol EncoderB=b3
'INTERRUPT.
Timer = $FFFF
SetTimer t1s_8
hintsetup %00000110
Gosub Interrupt_Init
Main:
Debug
'Encoder pins debug visualisatie.
If pinB.0=1 Then
EncoderA=1
Else
EncoderA=0
EndIf
If pinB.1=1 Then
EncoderB=1
Else
EncoderB=0
EndIf
Goto Main
Interrupt:
If hInt1Flag = 1 OR hInt2Flag = 1 Then
hInt1Flag = 0: hInt2Flag = 0
End If
Inc InterruptCounter
Debug
Gosub Interrupt_Init
Return
Interrupt_Init:
SetIntFlags Or %0000110, %00000110
Return