|
Forum Index : Microcontroller and PC projects : Problem with SERVO
| Author | Message | ||||
| Frank N. Furter Guru Joined: 28/05/2012 Location: GermanyPosts: 1146 |
Hello, can someone please help me with the servo command? Unfortunately, I can't find any examples, and I'm not sure how to use the command correctly. I have a model-building micro servo (S18JST) connected to GP0. The servo should be able to move through an angle of about 170°. I use PicoMiteRP2040V6.03.00.uf2 Why do I get a syntax error when I enter values greater than 120 and less than -20? But my servo still only moves a little more than 90°. I'd probably need values even lower than -20 to cover the entire range. At values greater than 110, the servo stops moving - that seems to be the upper limit. Here is my test program: Option explicit SetPin 1, PWM0A Dim Zaehler Integer Do While 1 Links Rechts Loop Sub Links For Zaehler=-20 To 110 Step 5 Servo 0, Zaehler Pause 50 Next Zaehler End Sub Sub Rechts For Zaehler=110 To -20 Step -5 Servo 0, Zaehler Pause 50 Next Zaehler End Sub Would it be better to use the PWM command? Frank P.S.: I use GFXterm Linux-64, and [?7h] always appears when I'm outside the editor?!? |
||||
| matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 11678 |
|
||||
| matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 11678 |
Note you can test it is working by connecting the servo output pin to a count pin and checking the frequency and duty cycle (pulsin) |
||||
| Frank N. Furter Guru Joined: 28/05/2012 Location: GermanyPosts: 1146 |
Okay, I missed the part about -20 and 120. Unfortunately, that doesn't cover the entire range the servo is capable of. I'll try the PWM command. Frank |
||||
| matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 11678 |
Frank: something is not right. I'm not aware of any servos that won't run their full range when given 1-2mSec. That is the spec for a servo. Even allowing the +/- 20-% that I do isn't really correct. |
||||
Grogster![]() Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 10005 |
Cheap nasty servo units perhaps? Where did you get your ones from, Frank? AliExpress and eBay are flooded with super-cheap servo units, and many of the REALLY cheap ones(one or two bucks or so each) are just junk. Slightly more expensive ones would probably work fine, if you happen to be using some of the really cheap ones. I've used servos before, and I also never had any issue with getting them to do full travel using the standard SERVO command. But you do have to have a servo that is at least minimum spec compliant. Smoke makes things work. When the smoke gets out, it stops! |
||||
| phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 3329 |
Looked up the specs of "micro servo (S18JST)" and they indicate it is a 60° unit. |
||||
| Frank N. Furter Guru Joined: 28/05/2012 Location: GermanyPosts: 1146 |
@Grogster: It is a micro-servo from a well-known distributor in Germany. It measures just 13.5 x 16 x 6 mm. @phil99: Good point! If you can read, you have a clear advantage! Even so, it covers a range of about 135° when I control it using PWM. Unfortunately, that doesn't work with the SERVO command... Frank |
||||
Grogster![]() Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 10005 |
OK. Smoke makes things work. When the smoke gets out, it stops! |
||||
| Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 6004 |
1/ the servo travel of 60 degrees in above servo is the standard way uou specify the speed (60 degrees in xx ms). Same as for cars 0-60mph in 9 seconds. Does not say the car cant go over 60 mph. 2/ in my rc days I have come accross so many cheap and expensive servo's, and they all do +/-60 degrees from mid position. With luck +/- 90. Unless it is a cont.rotation servo. 3/ the 0 to 90 spec in the servo command does not match my thinking of +/-. So I use the PWM command to drive servo's. 4/ the limits 800us and 2.2ms are correct. You hardly get below 700us and above 2.4ms without limit. Volhout P.s. high end servo s are digital interface. Not pwm anymore. And they are configurable (pid). Edited 2026-07-29 17:22 by Volhout PicomiteVGA PETSCII ROBOTS |
||||
| Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 8986 |
First, I have no experience of servos, so I have no preconceptions about them. I've come to look at the SERVO command and the examples and, to be quite honest, I can't figure it out at all. I assume that Position A and Position B are the start and end angles required, in which case you can't set a servo for 0-180 degrees or -90 to +90. You are limited to -20 to +120 degrees, surely? The examples aren't clear for a newcomer at all. Could someone enlighten me please, and maybe suggest some more meaningful examples for the manual? Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
| phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 3329 |
The way I read it the SERVO command just outputs pulses of 0.8mS to 2.2 mS at a 50Hz rate. What angle that represents is up to each servo manufacturer. 1 to 2mS for full travel appears to be the standard but apparently some manufacturers don't stick to it. Maybe if the manual read "nominal percentage of full travel" it might be more obvious. The above has been edited. Edited 2026-07-29 18:43 by phil99 |
||||
| Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 8986 |
Ah, thanks Phil. That makes a lot more sense to me now. So, SERVO can operate from -21% to 120% of what a "standard" servo would expect over its full end to end travel, giving room to maneuver a bit. How does the <position> value work? I assume that 0 woll be at Position 1, but is it in degrees or % of rotation to Position 2? Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
| matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 11678 |
The number is the percentage of "normal" 1-2msec |
||||
| Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 6004 |
If you throttle a motor, then 0 and 100% make sense. When you do elevation, pitch, roll eveything focusses around mid position, which is 50 % in the servo command. So there is no good or bad, one way or the other you have to do some math. I personally use PWM since the math is not more complex, and it transfers nicely to other hardware. Volhout P.s. don't forget there is always center trim. The arm can be mounted in few discrete angles to the servo. Edited 2026-07-29 23:13 by Volhout PicomiteVGA PETSCII ROBOTS |
||||
| Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 6004 |
Also: software limits at 0.8 and 2.2ms are VERY smart. When you run a servo into its mechanical limits, it will eithe burn out, or it will drain your battery in minutes. Volhout PicomiteVGA PETSCII ROBOTS |
||||
| Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 8986 |
Thanks everyone. :) Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2026 |