Strangly enough, it kinda work now.. a bit out of scale and so on, but mostly work, after the 'low bortb.0'
HOWEVER..
Now I got to the next part, trying to actually being able to move the servo myself.. so I wrote a bit of code that I thought should work.
Code:
@ device HS_OSC,MCLR_OFF,LVP_OFF,WDT_OFF,PROTECT_OFF
DEFINE OSC 4
'Use b1 to hold pulse width variable for servo 1
b1 var byte
'initialize variables
b1 = 150
low portb.0 ' put the servoport low.
main:
pulsout portb.0, b1 'send current servo 1 position out
if porta.0 = 0 then left1 'check for pressed switch 0
if porta.1 = 0 then right1 'check for pressed switch 1
pause 18
goto main
left1:
b1 = b1 + 1
if b1 >254 then max1
goto main
right1:
b1 = b1 - 1
if b1 <75 then min1
goto main
max1:
b1 = 75
goto main
min1:
b1 = 254
goto main
..I have pullup-resistors (10k) on a0 and a1 and wiring them to ground when I activates them.
..Well, the problem is that the servo just goes to one endposition and stay there regardless what I do with a0 and a1 ?
..HOWEVER.. if I comment out theese two lines:
Code:
if porta.0 = 0 then left1 'check for pressed switch 0
if porta.1 = 0 then right1 'check for pressed switch 1
..The servo "works", it put itself in the middle position (well not really middle but more or less.)
Why ? ..I could think that my subroutines are destroying the timing, bit it aint working even if I dont touch the inputs ?
Bookmarks