SwingeyP
Member
Hello again,
Things have been moving steadily with my 40 meter transceiver project but I am back at a stumbling block which has been present throughout.
As Eric suggested in the beginning of this project the ENCODER routines just aren't cutting it.
I have moved away from the birds nest now and have some homebrew PCB's in a nice enclosure but this encoder thing sis just driving me nuts.
I made a vero board version of this :
http://letsmakerobots.com/content/how-use-quadrature-encoder?page=2
and it appears to work as expected. I get a pulse (checked with logic probe) every time the encoder turns (which triggers the interrupt). The A and B lines are toggling as the encoder is turned.
The problem is no matter what I always seem to count down. I added a debug line t display the value of direction (which is a bit) hence the << and >>. These ARE changing so the value must change. However I always seem to count down :-(
In simulation if you set the values of the encoder inputs high and low accordingly the code counts up and down as expected.
I'm guessing this is a timing issue in the time it takes the interrupt to run and update the LCD but I may (and probably am) wrong.
Can someone take a look please.
The Interrupt
The count up / down
Many thanks - Paul
Things have been moving steadily with my 40 meter transceiver project but I am back at a stumbling block which has been present throughout.
As Eric suggested in the beginning of this project the ENCODER routines just aren't cutting it.
I have moved away from the birds nest now and have some homebrew PCB's in a nice enclosure but this encoder thing sis just driving me nuts.
I made a vero board version of this :
http://letsmakerobots.com/content/how-use-quadrature-encoder?page=2
and it appears to work as expected. I get a pulse (checked with logic probe) every time the encoder turns (which triggers the interrupt). The A and B lines are toggling as the encoder is turned.
The problem is no matter what I always seem to count down. I added a debug line t display the value of direction (which is a bit) hence the << and >>. These ARE changing so the value must change. However I always seem to count down :-(
In simulation if you set the values of the encoder inputs high and low accordingly the code counts up and down as expected.
I'm guessing this is a timing issue in the time it takes the interrupt to run and update the LCD but I may (and probably am) wrong.
Can someone take a look please.
The Interrupt
Code:
'----------------------------------------------------------------
'ON INTERRUPT
'----------------------------------------------------------------
On Interrupt
Save System
PIR1.TMR1IF = 0 'clear the overflow
INTCON.INTF = 0 'clear interrupt on RB0.
INTCON.RBIF = 0
intrcnt = intrcnt + 1
intflag = 1
'old = new;
'New = digitalRead (inputA) * 2 + digitalRead (inputB); // Convert binary Input To decimal value
'out = qem [old * 4 + new];
direction = encodera Xor encoderb
Lcdcmdout LcdLine3Pos(1)
If direction = 1 Then
Lcdout "Direction >>"
Else
Lcdout "Direction <<"
Endif
Resume
The count up / down
Code:
'----------------------------------------------------------------
'Sub Routines
'----------------------------------------------------------------
check_inband:
Select Case freq_step
Case 1 'step = 1
If direction = 1 Then 'increment
hz = hz + 1
If hz > 9 Then
hz = 0
khz = khz + 1
If khz >= bandwidth_upper Then
khz = bandwidth_upper
Endif
Endif
Else 'decrement
hz = hz - 1
If hz < 0 Or hz > 9 Then '>9 trap for -1 overflow as using byte variable
hz = 9
khz = khz - 1
If khz <= bandwidth_lower Then
khz = bandwidth_lower
Endif
Endif
Endif
Case 10 'step = 10
hz = 0 'set this to zero as it looks nicer
If direction = 1 Then 'increment
khz = khz + 10
If khz >= bandwidth_upper Then
khz = bandwidth_upper
Endif
Else 'decrement
khz = khz - 10
If khz <= bandwidth_lower Then
khz = bandwidth_lower
Endif
Endif
EndSelect
Return
Many thanks - Paul