
Originally Posted by
HenrikOlsson
Hi,
Just realised I misunderstood you a bit. I thought you were trying to use the 12F1840 with this code, then I realised you're actually using the 16F1825 that's in the schematic...duh...
Anyway, I've breadboarded a 12F1840 (don't have any 18F1825) and now have an encoder counting properly, sending the count over the USART. I simulated the EEPROM write by adding a PAUSEUS xxx in the handler and found that the limit for correct response - in my case - is around 500us. Anything above that it starts missing edges, coutning the wrong way etc.
So, if the EEPROM write takes even remotely as long as 10ms then that is most likely the issue.
/Henrik.
Ok, it works now - mostly. What's weird is the 'MotorRPM' as displayed on the LCD jumps by 3-4 (i.e. current setting is '120' and then one click of the encoder makes it '124'). The only thing I did was comment out the WRITE line (and the PAUSE 100 too, of course). Sometimes, it misses incrementing the click completely (although only rarely).
Does this have something to do with the comparison logic?
Code:
' ***************************************************************
' [IOC - interrupt handler]
' ***************************************************************
RotEncAdjust:
New_Bits = PORTA & (%00000011)
IF (New_Bits & %00000011) = (Old_Bits & %00000011) Then DoneRotEnc
RotEncDir = New_Bits.1 ^ Old_Bits.0
IF RotEncDir = 1 Then
; CW rotation - increase speed but only to a max of 'MaxDuty'
IF MotorRPM < MaxDuty then MotorRPM = MotorRPM + 1
Else
' CCW rotation - decrease speed to a min of 0
IF MotorRPM > 0 Then MotorRPM = MotorRPM - 1
EndIF
; WRITE EE_MotorRPM, MotorRPM
; pause 100
DoneRotEnc:
Old_Bits = New_Bits
IOCAF.0 = 0 ' Clear interrupt flags
IOCAF.1 = 0
@ INT_RETURN
Bookmarks