Hi all this might be better asked in a vb group, but i would like to ask here as well.. I am controlling servos via lpt with VB Just giving servo 5v and pulsing out lpt line to servo with following code
Dim icount As Integer For icount = 1 To 75 Call PortOut(888, 1) Threading.Thread.Sleep(0.8) Call PortOut(888, 0) Next icount Return
Everything works great when i run project within VB
but the servos do not work correctly if i run from a Build or Publish of project,, any ideas? TIA Mike
Didn't find your answer? Ask the community — no account required.
T
The Real Andy
What version of VB are you using?
P
Poxy
Forgive me if I'm missing something - I'm not a VB programmer, but servos want a +ve pulse time of between 1ms and 2ms (the range varies with different servos, but the mid point is generally around 1.5ms), with a -ve time of around 10ms or longer. From the look of that code, the output goes high for 0.8ms, then low and immediately loops and goes high again - it may be that the low time is insufficient.
I'd suggest adding another Sleep command, after the output goes low, perhaps
10ms, but shorter may well work if you need it to. You also need to make sure 0.8ms doesn't exceed the range of travel of your servo or you might strip the gears.
A
Andy Wood
. . .
Are you trying to run it on the same system you built it on?
Andy Wood snipped-for-privacy@trap.ozemail.com.au
M
Mitch__
yes same system
M
Mitch__
vb 2005
M
Mitch__
hmm im using sleep for 0.8 to turn motor one way and 1.0 to move it the other way,, but i do believe i am not controlling the servo correctly, because i am just moving it one way or another for an amount of time, when what i should be doing is pulsing properly and the servo will move to its position and stay there,, i think you are on to something for me here,, i am going to put a second sleep in. thanks
P
Poxy
servos
a -ve
goes
may
perhaps
You are using common R/C servos? In that case, yes, they are designed to move to a fixed position depending on the +ve pulse width - a 1ms pulse is one extreme of the output shaft's travel, a 2ms pulse is the other extreme and a 1.5ms pulse is halfway.
B
Brenden Ede
Hi Mitch, The real problem you're going to have with VB or any Windows operating system is that they're not 'real time' designed. The operating system doesn't give any program an exact number of cycles per second and thus controlling servos, which require an accurately timed signal, is really an uphill battle.
The normal method is to offload the 'real time' elements to a microcontroller. There are lots of microcontroller based servo driver boards that run from a serial RS232 port and even some USB ones.
If you would like I can give you firmware for a servo driver that runs on a really cheap PIC12C50x or PIC12F50x and runs 4 servos. This runs from 2400/4800 baud serial that can come from a serial port or USB-Serial converter unit.
Then just use MSCOMM to send serial bytes to the port and the microcontroller takes care of all the timing critical servo signal generation.
For parts and postage cost I could send you the chips, pre programmed.
If you want some of these, please correct the deliberate spelling error in my email and remove the nospam.
Regards, Brenden Ede
Poxy wrote:
T
The Real Andy
You can get pretty damn close if you know where to look in the API. If it is a hobby application then windows should suffice. Do a google for performance counters, its well documented around the net. IIRC i have also read about multimedia timers being quite accurate, but I know nothing about them.
One point is worth mentioning, do it all by polling on a single thread, not with events. :) ALso set thread priority to high!
Join the Discussion
Have something to add? Share your thoughts — no account required.
Didn't find your answer?
Ask the community — no account required
Report Content
You are reporting this content to the moderators. They will look at it
ASAP.