ok,heres my program ,using interrupts..
the problems i'm encountering are below the code
..
Code:
DEFINE LOADER_USED 1
led VAR PORTB.7
old VAR BYTE
new VAR BYTE
direction_bit VAR BIT
counter VAR WORD
counter_1 VAR WORD
counter_2 VAR WORD
direction_store VAR BIT
adval VAR WORD ' Create adval to store result
potval VAR WORD
servo_val VAR WORD
difference VAR WORD
counter=32500
HPwm 0,150,20000
OPTION_REG = $7f
ON INTERRUPT GoTo myint ' Define interrupt handler
INTCON = $90 ' Enable INTE interrupt
loop: High led ' Turn LED on
LCDOut $fe,1,"count:"
LCDOut $fe,$c0,DEC counter
'Pause 10
GoTo loop ' Do it forever
' Interrupt handler
Disable ' No interrupts past this point
myint: Low led ' If we get here, turn LED off
enc: new= PORTB & %00000011
start_1:
old=new & %00000011
again:
new= PORTB & %00000011 'load new value of A/B channels into new by anding with HEX3
'IF new=old Then again
direction_bit=old.bit1 ^ new.bit0 'check direction
IF direction_bit = 1 Then
LCDOut $fe,1,"Last was CW"
counter = counter + 1 'increment counter
LCDOut $fe,$c0,DEC counter," ",BIN direction_bit
Else
LCDOut $fe,1,"Last was CCW"
counter = counter - 1 'decrement counter
LCDOut $fe,$c0,DEC counter," ", BIN direction_bit
EndIF
Pause 10
INTCON.1 = 0 ' Clear interrupt flag
Resume ' Return to main program
Enable
1>The interrupts are worng fine,however the code is still unable to distinguish between CW and CCW,because of which the counting goes awry..
2>if i remove the "if then " statement for CW/CCW direction and only put a
counter=counter+1,it works well
The whole problem seems to be the direction decoding part..
..i cant seem to find a solution to it..
Bookmarks