I removed the "AND" functions and replaced them with direct port readings and added 100ms delays between motor commands. I have also added a command to set the inputs to digital. The problem still persists, though my memory usage has greatly reduced.
Anybody have any other ideas that may work to resolve this issue?
It may be the hysterisis of the potentiometer, but I am scratching my head on how to eliminate this in code as each comparator is set high.
Thanks for the help,
Paul Cox
here is my updated code:
TRISA=%11111000 'make A0, A1 & A2 outputs
TRISB=%11101111 'make B0, B1, B2, B3, B5, B6 & B7 inputs
CCWDRV var PortA.0 'change port name
CWDRV var PortA.1 'change port name
LED var PortA.2 'change port name
CNTR var PortB.0 'change port name
PT1 var PortB.7 'change port name
PT2 var PortB.6 'change port name
PT3 var PortB.5 'change port name
PT4 var PortB.3 'change port name
PT5 var PortB.2 'change port name
PT6 var PortB.1 'change port name
CMCON = 7
cycle:
if PortB=%00000000 then '000 000 right stop
low LED
pause 50
high LED
pause 500
low LED
pause 500
goto cycle
endif
if PortB=%11101110 then '111 111 left stop
low LED
pause 50
high LED
pause 500
low LED
pause 500
goto cycle
endif
if PortB=%00000001 then '000 000 center from right stop
low LED
pause 50
high CCWDRV
pause 500
gosub CCWCENTER 'go to sub-routine to center from right
goto cycle
endif
if PortB=%11101111 then '111 111 center from left stop
low LED
pause 50
high CWDRV
pause 500
gosub CWCENTER 'go to sub-routine to center from left
goto cycle
endif
if PortB=%00000011 then '100 000
low LED
pause 50
high CCWDRV
pause 500
gosub CCWCENTER 'go to sub-routine to center from right
goto cycle
endif
if PortB=%00000111 then '110 000
low LED
pause 50
high CCWDRV
pause 500
gosub CCWCENTER 'go to sub-routine to center from right
goto cycle
endif
if PortB=%00101111 then '111 100
low LED
pause 50
high CWDRV
pause 500
gosub CWCENTER 'go to sub-routine to center from left
goto cycle
endif
if PortB=%01101111 then '111 110
low LED
pause 50
high CWDRV
pause 500
gosub CWCENTER 'go to sub-routine to center from left
goto cycle
endif
GOTO cycle
CCWCENTER
if PortB=%00001111 then
low CCWDRV 'stop motor at 111000 position
pause 1000 'change to 250ms after debugging
high CCWDRV 'start motor for last leg of travel
pause 2000 'run time to go from 15 degrees to center CCW
low CCWDRV
endif
return
CWCENTER
if PortB=%00001111 then
low CWDRV 'stop motor at 111000 position
pause 1000 'change to 250ms after debugging
high CWDRV 'start motor for last leg of travel
pause 2000 'run time to go from 15 degrees to center CW
low CWDRV
endif
return
end
Bookmarks