37637598 on 25/7/2009 at 06:35
I'm completely changing my post cuz I figured out my previous problem. My new question is; How does one go about making a servo spin clockwise, then counter-clockwise through the same pin via PBASIC 2.5 language in a PIC microcontroller, without adding any extra circuitry?
Briareos H on 25/7/2009 at 08:47
I know nothing about higher level PIC programming since we used to do that in assembly, but you probably want the code to look a bit more like that :
Code:
pulse:
IF xaxis <> x THEN
low 1
pulsout1, 300
pause 10
goto pulse
ENDIF
Unless labels work differently than in every language I know (with your example, the program loops sending impulses forever)
37637598 on 25/7/2009 at 10:04
Sorry for changing it on you, I didn't think anyone had even read it yet. I do see what you're saying though, but in a loop, doesn't it read the 'IF' statement every time it loops? Thus when the 'if' suddenly changes from true to untrue, the loop would be ignored and the else would be utilized, making it GOTO a new string... do correct me if i'm wrong, because it's been a long time since I've done this stuff.
pulse:
DO
IF xaxis <> x THEN
low 1
pulsout1, 300
pause 10
else
goto newstring
ENDIF
LOOP
Reguardless, your method is correct, but I simply must know if this would also work, for the sake of knowing.
Briareos H on 25/7/2009 at 13:05
yep that would work !
As for your clockwise / counterclockwise question, I imagine you'd have to look at the datasheet for your servo driver to see what kind of signal controls that parameter.
Al_B on 25/7/2009 at 14:38
Without knowing what circuit you're using it's pretty difficult to answer your new question.
37637598 on 25/7/2009 at 19:42
ah good point. Here's the basic idea:
DO
turnclockwise:
PULSOUT 8, 40 ' turn servo clockwise 40º
PAUSE 2000
GOTO turncounterclockwise
turncounterclockwise:
PULSOUT 8, -40 ' turn servo counter clockwise 40º
PAUSE 2000
GOTO turnclockwise
LOOP
The above code obviousle won't work because you can't just send a negative number to a servo and expect it to turn the opposite direction of a positive number. The servo is a very simple 3-wire 6 volt 180º turning ratio servo with a black wire (ground), a red wire (VCC), and a white wire (potentiometer data).
I'm assuming the only way to accomplish this is to use 2 different output pins from the micro controller. One for a clockwise, and one for a counter-clockwise signal. Then to wire in a circut that reverses the polarity of the servo based on which pin is sending a signal... I'm just trying to use as little amount of external componants as possible to cut cost.
Al_B on 25/7/2009 at 22:03
Hmmm.... The second parameter to the PULSOUT command is a time, not a number of degrees. Of course, if your servo turns in a constant number of degrees per time unit then it could correspond. The biggest problem you'll have is that you're not trying to specify a negative number as the second paramter - you're attempting to specify a negative time.
If the potentiometer data line can be used to specify the direction of the motor then you could use DAC or just a PIC PWM output with a low pass filter (simple resistor and cap may be good enough - although you may need to use an op-amp to buffer it.). However, it sounds as if you may need to reverse the servo's power to reverse its direction (but please check the spec sheet or post a link to it here first).
If you need to control the supply polarity to the motor then you can do it from one output with a combination of MOSFETs (or a suitable driver) but it may be easier from two outputs.
37637598 on 25/7/2009 at 22:53
The best specs sheet I can find is here (
http://chd.hk/boupload/DownLoad/2009031801271050607.pdf)
It's the HD-1440A. I searched for a spec sheet specific to the part number but nothing better came up.
You're right about the output being a time, I was just pretending that a 40ms pulse would make it turn 40º, though obviously the world isn't that perfect , and the negative time thing was just a brain fart. The servo is analog but it has a chip inside of the casing and I'm afraid that if I change the polarity, it will burn things up, assuming there's no reverse polarity protection. I just don't want to have to buy more parts to get a servo to change direction. I'm stumped.
Al_B on 26/7/2009 at 08:43
It's unfortunate that they don't have a spec sheet for any of their analogue servos. I wouldn't reverse the servo supply polarity - from what I've seen it's not the right approach.
I would be inclined to do some testing without the PIC being involved. Can you get the servo to reverse direction by changing the voltage on the white wire? A 1k or similar pot connected with the wiper to the white wire and the outer ends to the two supplies would allow you to test this.
If this works and you have a multimeter to hand then note down the voltages that correspond to the two directions of travel and which voltage corresponds to the 'neutral' position in the middle. Then, the task boils down to getting the PIC to generate a suitable voltage which can be done to an approximation using PWM.
37637598 on 26/7/2009 at 09:47
I found the input specs in a book just now, I'll post them tomorrow. Basically the servo is looking for a specific pulse. A 1ms pulse is counter clockwise, a 1.5 second pulse is idle, or center, and a 2 second pulse is clockwise. I'll elaborate when I wake up. I'm smashed and tired.