08M controlling a single servo problem

mikie_121

Member
Hi

I am looking for any ideas about why my 08M is giving me the wrong outputs.

I want the 08M to respond to a 2 bit input (connected to pins 3 and 4) and output a corresponding servo command.
The problem is that the first command in the loop doesn't work. I have re-arranged the code a number of times and the first servo command always gives the wrong output.
Here is my code:

main:
if pin3 = 0 and pin4 = 0 then
low 1
pause 12
elseif pin3 = 1 and pin4 = 1 then
low 1
pause 12
servo 1, 122 'reverse slow
elseif pin3 = 0 and pin4 = 1 then
low 1
pause 12
servo 1, 105 'forwards fast
elseif pin3 = 1 and pin4 = 0 then
low 1
pause 12
servo 1, 118 'forwards slow

endif
goto main

All outputs work when the corresponding input is applied, except the first one which will output a pulse of about 500 microseconds every 16ms.
I have tried another chip with the same results so it must be in the code.

The 12ms pause is necessary to prevent what appear to be overlapping signals.

Any help would be great.

Thanks
Mike
 
Last edited:

Wrenow

Senior Member
<scratching head> I presume you are controlling an ESC (Electronic Speed Control) instead of an actual servo? Regardless, you are running the servo on 1, right? Why the Low 1?

The servo command sends the pulse every 20ms as required by the servo (or ESC) electronics. If you update the servo command more frequently, you can create issues (16ms).

Also, the settings you are using don't seem to make sense. I am uncertain exactly shat is happening.

On an ESC with Forward and Reverse, the general centerpoint (stop) is NOT no signal, but is a pulse of 150ms. Forward is generally from 151-200, reverse being 149-100 (both bing slower to faster). This corresponds to servo positions of 100-200 stop to stop with 150 being dead center. Now, if your ESC is set up backwards, with a centerpoint of 120, it kind of makes sense.

Wreno
 

mikie_121

Member
I am controlling a single servo which has been modified for continuous rotation. It's a Futaba S3003 and for some reason the centre point is 119. The resistors I used are 1% 2k2 Ohm, so the centre point should be 150 but it isn't. None of my servos (modified or not) have a centre point of 150. I am actually using two 08Ms, one for each wheel. The left side works perfectly with exactly the same code (the servo numbers are different obviously) and I want to know why the right side won't work.

I have used the 'low 1' to reset the servo output because I get very weird outputs if I don't. My guess is because I am continuously writing a new servo command that something is getting mucked up. The 12 ms pause seems to give a clean output. Without it I get pulses of the right width but the period is about 5ms, which is way too short.

I am using an oscilloscope to view these outputs, in case anyone wants to know.

I might just try a couple of pulseout commands and make sure the timing is right.
 

hippy

Technical Support
Staff member
Not sure what you mean exactly with "first servo command always gives the wrong output" or why the same code should work in one 08M but not another. That suggests a problem external to the 08M.

Using the LOW, PAUSE and SERVO commands will almost certainly give some strange results. A better way of doing this is to read the input pins and when they change from what they were select a new SERVO setting rather than keep repeating SERVO commands. Something like -

Code:
b1 = 1 ' Force first reading to be different
Do
  b0 = pins & %11000 ' Get pins 4 and 3
  If b0 <> b1 Then
    b1 = b0
    Select Case b0
       Case %00000 : something ' Pin4=0, Pin3=0
       Case %01000 : something ' Pin4=0, Pin3=1
       Case %10000 : something ' Pin4=1, Pin3=0
       Case %11000 : something ' Pin4=1, Pin3=1
    End Select
  End If
Loop
 

mikie_121

Member
Yeah, I know the problem is not in the chip because two chips do the same thing. I needed to have the value of a servo update very quickly, but I think that it is just too fast for the servo command to handle.
I have found a solution that works, and it works FAR better than the servo command ever did. Use pulsout and pause the rest of the required period.
I have no more problems.

Thanks guys
 

boriz

Senior Member
"I needed to have the value of a servo update very quickly"

Just how long do you think Hippys code takes to 'update the value'?

The servo&#8217;s internal circuitry will make controlling the rotation speed problematic. You would prolly get better results using a normal geared motor and an H-bridge with PWM. Or maybe just remove all the servo circuitry and use that with an H-bridge.
 

Wrenow

Senior Member
Mike, I was going to suggest going with pulsout for your situation. One thing you will find that may be a problem is servo drift with a fixed resistor bridge.

Another issue is that speed is touchy and hard to adjust (servos are generally not designed in the direction of variable speed), although there are instructions on the web to hack the amplifier board to allow better speed range. What a lot of the guys in R/C Model Warship Combat do is remove the amplifier board altogether and just use an antweight ESC to control two servos. http://www.robotmarketplace.com/marketplace_antweights.html

Another solution is the Radio Shack Vex Robotics Motor, which is a continuous rotation servo-like gearbox (in fact, it is pretty myuch identical to the Vex Servo, but for the electronics within) with an ESC installed. Cost is about the same as a servo, but designed as a motor with full speed control. Standard output is via a 1/8" square shaft instead of servo-type splined hub.

Hippy's code will probably execute as quickly as the pulsout if not faster, methinks.

Still don't understand the Low 1 being in your application. All it seems to do is screw with the servo command.

Good luck,

Wreno
 

mikie_121

Member
I had to use the low 1 command in the original loop because none of the servo commands made the wheels stop completely. The resolution just wasn't high enough.

I demonstrated the robot today and it was one of two that worked in a class of 8. Many people used the Lego NXT none of which worked!

I didn't fully understand hippy's code (I do now) and I wanted to eliminate the servo commands anyway.

thanks for all of the help and long live picaxe.

Mike
 
Top