Luciano,
when i try the program u recommended [12th april] as below,
there are alot of instances when the program gets confused with direction,
so it sometime increments and decrements.Im not using interrupts
when i move the motor slowly,the problem still persists.
Code:
old_val VAR BYTE
new_val VAR BYTE
direction_bit VAR BIT
enc_counter VAR WORD
adval VAR WORD ' Create adval to store result
potval VAR WORD
servo_val VAR WORD
difference VAR WORD
TRISB=%11111111
enc_counter=32500
HPwm 0,100,20000
new_val = PORTB & %00000011
start:
old_val = new_val
again:
new_val = PORTB & %00000011
'LCDOut $fe,1,"no move"
IF new_val = old_val Then again
direction_bit = old_val.bit0 ^ new_val.bit1
IF direction_bit = 1 Then
LCDOut $fe,1,"Last was CW"
enc_counter = enc_counter + 1
LCDOut $fe,$c0,DEC enc_counter
Else
LCDOut $fe,1,"Last was CCW"
enc_counter = enc_counter - 1
LCDOut $fe,$c0,DEC enc_counter
EndIF
GoTo start
Thank you for your responses
Bookmarks