i can get good positive results from an encoder but my negative results from anything but a crawl are off... not sure how to fix it..... I have uploaded sample results from my project running
Total Var sword ' all vars are Swords so that they can be negetive.
Work var sword 'Work is low byte
Work2 var sword 'Work2 is high byte
neg var sword
oldval var sword
Work2 = 0
Work = 0
Total = 0
OE con P10
SEL con P11
High SEL
pause 1
Low OE 'select high and OE low starts reset
pause 1
High OE 'select high and OE high completes reset. Counter should be zero
Dirl = $FF 'sets 0-7 pins to input
Main
Low SEL ' starting action of reading HCTL
pause 1
low OE ' select low and OE low sets inhitit, and allows high byte to be read.
work2 = INL
pause 1
High SEL 'select high and OE low sets it to read low byte and starts the reset.
Work = INL
pause 1
High OE 'Select high and OE high completes the reset logic and Counter should be Zero.
'neg = (work2 * 256) + work 'combines high and low bytes. first attempt at it
neg = (work2 << 8) + work 'combines high and low bytes.
if neg > 2047 then 'Test for negitive
neg = neg - 4096 'If negitive then subtract 4096 to make number negitive
endif
Total = Total + neg 'Add final number to total for use in program (displaying in debug window)
if total <> oldval then
serout S_out,I38400,["Total = ",sdec Total," High = ",bin work2," Low = ",bin work," neg = ",bin neg,13]
oldval = total
endif
neg = 0
Large = 0 'resetting variable to zero
Small = 0 'resetting variable to zero
Goto main 'loop program
Total Var sword ' all vars are Swords so that they can be negetive.
Work var sword 'Work is low byte
Work2 var sword 'Work2 is high byte
neg var sword
oldval var sword
Work2 = 0
Work = 0
Total = 0
OE con P10
SEL con P11
High SEL
pause 1
Low OE 'select high and OE low starts reset
pause 1
High OE 'select high and OE high completes reset. Counter should be zero
Dirl = $FF 'sets 0-7 pins to input
Main
Low SEL ' starting action of reading HCTL
pause 1
low OE ' select low and OE low sets inhitit, and allows high byte to be read.
work2 = INL
pause 1
High SEL 'select high and OE low sets it to read low byte and starts the reset.
Work = INL
pause 1
High OE 'Select high and OE high completes the reset logic and Counter should be Zero.
'neg = (work2 * 256) + work 'combines high and low bytes. first attempt at it
neg = (work2 << 8) + work 'combines high and low bytes.
if neg > 2047 then 'Test for negitive
neg = neg - 4096 'If negitive then subtract 4096 to make number negitive
endif
Total = Total + neg 'Add final number to total for use in program (displaying in debug window)
if total <> oldval then
serout S_out,I38400,["Total = ",sdec Total," High = ",bin work2," Low = ",bin work," neg = ",bin neg,13]
oldval = total
endif
neg = 0
Large = 0 'resetting variable to zero
Small = 0 'resetting variable to zero
Goto main 'loop program