Hi, Glenn
Just try
LOW PortB.0
just before the PULSOUT Command ...
Alain
Hi, Glenn
Just try
LOW PortB.0
just before the PULSOUT Command ...
Alain
************************************************** ***********************
Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
************************************************** ***********************
IF there is the word "Problem" in your question ...
certainly the answer is " RTFM " or " RTFDataSheet " !!!
*****************************************
try just a simple code to make sure your servo is functioning correctly. I found a servo that seemed to drift. I thought it was my code. So i wrote a simple code that sets my pulse widths to left, center and right limits.
Yes I do violate the 20ms refresh rate but if all you care about is moving to positions to verify servo operation this is quick and dirty.
start:
portd.0=1
pausus 1000
portd.0=0
pause 2000
portd.0=1
pausus 1500
portd.0=0
pause 2000
portd.0=1
pausus 2000
portd.0=0
pause 2000
goto start
Nick
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.
..I have pullup-resistors (10k) on a0 and a1 and wiring them to ground when I activates them.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
..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:
..The servo "works", it put itself in the middle position (well not really middle but more or less.)Code:if porta.0 = 0 then left1 'check for pressed switch 0 if porta.1 = 0 then right1 'check for pressed switch 1
Why ? ..I could think that my subroutines are destroying the timing, bit it aint working even if I dont touch the inputs ?
Btw, thanks for all help, I'm completly stuck, and I know noone else that uses PBP![]()
This should go left with one button, go right with the other button, and if no buttons are pressed, should 'walk' back to center.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: low portb.0 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 if b1 > 150 then b1 = b1 - 1 else b1 = b1 + 1 endif 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 END
Note the BOLDED statements
Hi,
Just place
PAUSE 18
just after PULSOUT command ...
instead of Before " GOTO Main" .
Alain
************************************************** ***********************
Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
************************************************** ***********************
IF there is the word "Problem" in your question ...
certainly the answer is " RTFM " or " RTFDataSheet " !!!
*****************************************
Ok, try this...
This should do nothing more than swing the servo back and forth, from endpoint to endpoint. It'll probably hang up for a bit at the endpoints and might even move too fast or jerk around a bit trying to catch up to the program.Code:@ device HS_OSC,MCLR_OFF,LVP_OFF,WDT_OFF,PROTECT_OFF DEFINE OSC 4 temp var byte main: for temp = 0 to 255 pulsout portb.0, temp pause 18 next temp for temp = 255 to 0 step -1 pulsout portb.0, temp pause 18 next temp goto main END
If it doesn't, you've got something else going on.
It all boils down to breaking it down to it's simplest form and building it back up again.
Try it and report back...
Ok, that's good...at least you know stuff is working.
Now take the program and modify it to 'pull the endpoints' in a bit until you get to the actual endpoints.
When it 'stops for awhile', the program is probably trying to drive the servo past it's endpoints. The program goes to 0ms pulse width, but the servo can only actually drive to a 1ms pulse width, actually it'll probably drive farther than that, a lot farther, just not all the way to zero, or by the same token, won't drive all the way to 2.55 ms pulse width.
Decrease the 100 until it starts pausing at one end (meaning the PIC is trying to over-drive the servo) and increase the 200 until it starts pausing at the other end (again, meaning the PIC is trying to over-drive the servo in the other direction).Code:@ device HS_OSC,MCLR_OFF,LVP_OFF,WDT_OFF,PROTECT_OFF DEFINE OSC 4 temp var byte main: for temp = 100 to 200 pulsout portb.0, temp pause 17 'try lower numbers until it starts acting even stupider than it's acting now next temp for temp = 200 to 100 step -1 pulsout portb.0, temp pause 18 'try lower numbers until it starts acting even stupider than it's acting now next temp goto main END
Bookmarks