Shop OBEX P1 Docs P2 Docs Learn Events
Generate Sinosoid signal into a PWM signal to drive a servo — Parallax Forums

Generate Sinosoid signal into a PWM signal to drive a servo

EdmondEdmond Posts: 7
edited 2008-04-01 23:19 in BASIC Stamp
I am trying to use the Basic Stamp to generate a sinosoid signal into a PWM signal to drive a servo so it will move along with the shape of the sinosoid signal. It seems there is no way I can generat a sinosoid signal using BS. Have any ones done that before? Any ideas ?

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2008-04-01 19:42
    The control signal for a servo is a 1 mSec to 2 mSec (depending on what position you want the Servo in) pulse, repeated every 20 to 50 milliseconds. While TECHNICALLY that's "PWM", usually when people talk about "PWM" they mean "50% high, 50% low", or "25% high, 75% low", or something like that for controlling the intensity of an LED or the speed of an H-Bridge controlled motor.

    Bottom line -- you don't really WANT a "sinusoid" signal, because the Servo wouldn't know what to do with a "sinusoid" signal. Now, what you CAN do is vary the pulse-width you're sending to the Servo in a "sinusoid" pattern.

    Assuming that's what you want to do, you can 'simulate' this with more or less precision. I've done something similar just by implementing a "triangle" pattern -- 1 mSec to 2 mSec, then 2 mSec down to 1 mSec, and repeat. I believe there ARE "sine" functions in the BS2, though I've never used them.
  • EdmondEdmond Posts: 7
    edited 2008-04-01 20:19
    Hi Allanlane5 :

    May be I didn't make it clear on my first post but what you said is exactly what I tried to do. I am not sending the sinusoid signal directly to the servo. Instead, as you mentioned, I need to vary the pulse-width of the PWM signal such that the ultimate output of the servo is a sinusoid signal.

    I looked at the BS2 command list, it doesn't have any command to generate a sinusoid signal. I may able to write a program to simulate a sinusoid signal but I am afraid
    that is not very accurate and easy to implement a sinusoid signal artificially. However, if that is the only way I can do it, that may be I have to live with that.

    Thanks !
  • LilDiLilDi Posts: 229
    edited 2008-04-01 21:24
    Servos can receive a new command pulse every 20 ms. Not any sooner than that. The best you can hope for is a step pattern with 20ms plateaus at each step. It may visually appear to be sinusoidal, but it doen't sound that way as you hear the servo chattering like there's something wrong with it at each 20ms plateau. Another words, the servo will move position, pause 20ms then move, then pause 20ms, etc. Having said that. the code is simple.
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-04-01 21:34
    Well, actually, the Servo doesn't move that fast. 20 mSec is 50 times a second -- so it takes 2 or 3 repetitions or more (unless you're moving a VERY small distance) for the servo to REACH the commanded position. It'll take some experimentation to find out exactly how fast the Servo can move.
  • LilDiLilDi Posts: 229
    edited 2008-04-01 23:19
    Sorry. I guess I didn't make myself very clear either. I assumed Edmond wants to move the servo slowly from one end of travel to the other, one step at a time.
    Edmond, If you wish to move the servo as fast as possible from one end to the other, then as allanlane5 said, two or three identical command pulses will quickly and smoothly move the servo from one end to the other in a sinusoidal pattern. One end would be two or three 2ms pulses every 20ms, and the other end of travel would be two or three 1ms pulses every 20ms. Center position is 1.5ms. Few, I hope your not confused by all this Edmond.
Sign In or Register to comment.