Hi, this is my first message, and I hope my problems isnt too stupid..
Anyway, I'm building something with RC-servos and stumbled upon PBP wich looked like an very easy way for me to control them, however, my first little test aint working, and I have no idea why, I given up with my original code and hammered it down to just some testroutine that, in my opinion SHOULD work..
Here is the testcode:
Code:
@ device INTRC_OSC_NOCLKOUT,MCLR_OFF,LVP_OFF,WDT_OFF,PROTECT_OFF
'@ device HS_OSC,MCLR_OFF,LVP_OFF,WDT_OFF,PROTECT_OFF
DEFINE OSC 4
ct var byte
ct = 150
pause 250
low portb.1 ' force the status-LED off.
pulsout portb.0, ct ' this should place the servo in middle position.
pause 1000 ' Wait a while..
loop:
for ct = 1 to 255 step 1
pulsout portb.0, ct ' put the value of the counter to the servo.
Next ct
high portb.1 ' turn the status-LED on.
pause 1000 ' Wait..
low portb.1 ' Turn the status-LED off again.
goto loop
..This little code would in my opinion first put my servo in middle position, wait 1000, and then start to step it from one end position to the other. ..Then the status-LED should light up, wait 1000, and then go black again, and after than it should start to move the same again.
..This is not what happens, the servo does NOT enters the middle position, its goes to a position very near one end, then it moves back and forward a few millimeters, the LED acts as excpected.
Why ? ..first I thought that it was the internal oscillator that was the problem so I put a xtal with two caps at pin 15 and 16, and changed the first line to use an external clock, no difference at all.
Any idea ?
..Even more strange is that if I try to set the servo to 150 permanently it goes to one endstop and stops there ?
..I have a feeling that everything kinda works, but are completly " off scale", and I have no idea why.
..Oh, forgot, the pic is an 16F628A and the xtal is 4MHz.
Bookmarks