Discussion forum for the BasicX family of microcontroller chips.
|
hello, listen - i know im sounding like a complete loser when i ask this - but I am really just beginning with the BASICX board and servos and am kinda lost. I have a servo set up with the 5V supply and I am sending a signal to the servo to move, however, no response is found. But, if i pull the connector to the servo off then back on then off again, the servo jerks - this leads me to believe that i have the timer off. here is my code now: do Call PulseOut(12,1382,1) Call Sleep(30) loop its suppose to sleep for 30ms so i know that the last sleep call is wrong but how do i fix it? thanx in advance The TRUE beginner - Matt |
|
|
|
I think all of your times are wrong. Servos have a limited range of motion and the pulse has to be pretty short - under 2ms. The other thing is you may not have enough power; you should be running the servo off of a different power source or at least separate regulator from the BX24, with a common ground and the signal wire only connecting to the BX24 (in your case, pin 12.) I've written a little library for my own servo management, because I wanted it to manage itself while handling a bunch at once. It's a bit complex to read (most good multitasking code is, and since mine handles essentially arrays of servos, it's more like good C than Basic-X) and longish, but if you're curious, I'll post it. Here are some useful bits though. First, this function returns the pulse value needed by a servo, given the degrees you want it to go to. Call this as: PositionVariable =ServoPosCalc(45) The function is: >Function ServoPosCalc(ByVal Pos As Integer) As Single > ' Calculates the Position value for > ' Pos is the position to move to, in degrees > ' The pulse width is between 1 and 2 ms. > Dim Position As Single > Debug.Print "Adjusting to ";CStr(Pos);" degrees"; > Position = CSng(Pos)/90.0 ' Translate to a decimal value > ServoPosCalc = 0.001 + (0.001 * Position) > Debug.Print "Equates to ";CStr(CInt((0.001 + (0.001 * > Position))*10000.0));" ms*10" >End Function ' ServoPosCalc You then use the PositionVariable directly in the PulseOut as in my example below. My ServoHold function uses a delay, not a sleep, and I don't delay as long. The code below is simplified from mine for readability. ServoDelay is defined as: Public Const ServoDelay As Single = 0.02 >Public Sub ServoHold() ' (ByVal ServoPin As Byte, ByVal Width As Single) > do > Call PulseOut(ServoPin, PositionVariable, 1) > Call Delay(ServoDelay) > loop > ' End Sub also terminates the task, if it was CallTask'd >End Sub ' ServoHold So, copying from my code to fix up your code, we might do this: Dim ServoPos As Single Dim ServoDegrees as Integer ServoDegrees = 45 ' Just some legal value ServoPos = 0.001 + (0.001 * (CSng(ServoDegrees)/90.0 ) do Call PulseOut(12, ServoPos, 1) Call Delay(0.02) loop Or you could use my approach of named variables/constants for everything, which will simplify your life later. At 09:28 PM 11/8/2001 -0500, Matthew Mangione wrote: >hello, > listen - i know im sounding like a complete loser when i ask this > - but I >am really just beginning with the BASICX board and servos and am kinda lost. >I have a servo set up with the 5V supply and I am sending a signal to the >servo to move, however, no response is found. But, if i pull the connector >to the servo off then back on then off again, the servo jerks - this leads >me to believe that i have the timer off. here is my code now: > >do > Call PulseOut(12,1382,1) > Call Sleep(30) >loop > >its suppose to sleep for 30ms so i know that the last sleep call is wrong >but how do i fix it? thanx in advance > >The TRUE beginner - Matt |
|
|
|
thank you very much. i do have a separate power source connected to the servo while it didn't work - that made it move the first time finally. your code seems very useful - i may ask you again for it in its entirety if i need it. i shall try your solution next class - it sounds like it will most definitely work. thanx alot. matt |
|
From: "Matthew Mangione" <> > [...] I am really just beginning with the BASICX > board and servos and am kinda lost. [...] Also check out the servo application note, file Servo_BX24.zip: http://www.basicx.com/appnotes/bx-24appnotes.htm -- Frank Manning -- NetMedia, Inc. |
|
the jerk is caused ONLY by suppling the power & removing it again. this will happen without the signal line conected. it does show that you have a good servo. --- Matthew Mangione <> wrote: > hello, > listen - i know im sounding like a complete loser when i ask this - but I > am really just beginning with the BASICX board and servos and am kinda lost. > I have a servo set up with the 5V supply and I am sending a signal to the > servo to move, however, no response is found. But, if i pull the connector > to the servo off then back on then off again, the servo jerks - this leads > me to believe that i have the timer off. here is my code now: > > do > Call PulseOut(12,1382,1) > Call Sleep(30) > loop > > its suppose to sleep for 30ms so i know that the last sleep call is wrong > but how do i fix it? thanx in advance > > The TRUE beginner - Matt > > > ===== Tony Brenke North Tacoma, WA __________________________________________________ |