PWMPAL for dedicated servo control
Below is a sample program to control a Parallax/Futaba 360˚ servo by means of a BS2PX and ·two pushbuttons without a PWMPAL.
Is there someone how could push me in the right direction with converting the little piece of code to work but through the PWMPAL and the same 2 pushbuttons on a BS2PX
I’m a newby to this little new addition of my robot project and need some teachings…
Thanks...
' {$STAMP BS2px}
' {$PBASIC 2.5}
' {$PORT COM4}
'
'
'Hardware characteristics:
'
' BS2
' ===
' Hitec HS-5645MG basics:
' Absolute 0 degrees = 374 with 20ms pause
' Absolute middle = 746
' Absolute 140 degrees = 1120
'
' Futaba S148 Continues basics
' Motor stop = 760
' Motor cw = 600
' Motor ccw = 900
'
' BS2PX24
' =======
#SELECT $STAMP
· #CASE BS2, BS2E, BS2PE
··· Scale······ CON···· 500············ ' to ms for 2 us per unit
· #CASE BS2SX, BS2P, BS2PX
··· Scale······ CON···· 1250··········· ' to ms for 0.8 us per unit
#ENDSELECT
ServX·········· CON 12······················· 'Futaba 360
XPos··········· VAR Word
Stepping······· CON 20
LeftS·········· CON 1860
LeftF·········· CON 1800
Hold··········· CON 1873
RightS········· CON 1883
RightF········· CON 1943
MemXPos········ VAR Word
Main:
· GOSUB GetButtonValues
GOTO Main
Initialise:
· 'READ MemXPos, Word XPos
GOSUB Main
GetButtonValues:
· IF (IN5 = 1) OR (IN6 = 1) THEN
··· IF IN5 = 1 THEN
····· PULSOUT ServX,LeftS
··· ENDIF
··· IF IN6 = 1 THEN
····· PULSOUT ServX,RightS
··· ENDIF
··· PAUSE Stepping
· ELSE
··· 'PULSOUT ServX,Hold
· ENDIF
· IF (IN5 = 1) AND (IN6 = 1) THEN
··· DEBUG CRSRXY,0,0,"program aborted"
··· STOP
· ENDIF
RETURN
·
Is there someone how could push me in the right direction with converting the little piece of code to work but through the PWMPAL and the same 2 pushbuttons on a BS2PX
I’m a newby to this little new addition of my robot project and need some teachings…
Thanks...
' {$STAMP BS2px}
' {$PBASIC 2.5}
' {$PORT COM4}
'
'
'Hardware characteristics:
'
' BS2
' ===
' Hitec HS-5645MG basics:
' Absolute 0 degrees = 374 with 20ms pause
' Absolute middle = 746
' Absolute 140 degrees = 1120
'
' Futaba S148 Continues basics
' Motor stop = 760
' Motor cw = 600
' Motor ccw = 900
'
' BS2PX24
' =======
#SELECT $STAMP
· #CASE BS2, BS2E, BS2PE
··· Scale······ CON···· 500············ ' to ms for 2 us per unit
· #CASE BS2SX, BS2P, BS2PX
··· Scale······ CON···· 1250··········· ' to ms for 0.8 us per unit
#ENDSELECT
ServX·········· CON 12······················· 'Futaba 360
XPos··········· VAR Word
Stepping······· CON 20
LeftS·········· CON 1860
LeftF·········· CON 1800
Hold··········· CON 1873
RightS········· CON 1883
RightF········· CON 1943
MemXPos········ VAR Word
Main:
· GOSUB GetButtonValues
GOTO Main
Initialise:
· 'READ MemXPos, Word XPos
GOSUB Main
GetButtonValues:
· IF (IN5 = 1) OR (IN6 = 1) THEN
··· IF IN5 = 1 THEN
····· PULSOUT ServX,LeftS
··· ENDIF
··· IF IN6 = 1 THEN
····· PULSOUT ServX,RightS
··· ENDIF
··· PAUSE Stepping
· ELSE
··· 'PULSOUT ServX,Hold
· ENDIF
· IF (IN5 = 1) AND (IN6 = 1) THEN
··· DEBUG CRSRXY,0,0,"program aborted"
··· STOP
· ENDIF
RETURN
·
Comments
the technical info about the PWMPAL is scarse and not correct I think or is it me?
I'm in the dark here....
Maybe everybody is on vacation ......
;o)
The PWMPAL has a SERIN/SEROUT protocol that an attached BS2 uses to command the PWMPAL what pulses to send.
The PWMPAL is very well documented on the Parallax website. I'm sorry, I haven't used one myself.
Their chief advantage is that you don't have to 'refresh' the commands you send to the PWMPAL -- it will continue to maintain a servo's position (or speed) without further BS2 intervention.
Note that what you're trying to do should be REALLY REALLY simple for the PWMPAL -- worst case just replace the "PULSOUT" commands above with the appropriate "SEROUT" to tell the PWMPAL which channel and which pulse-width.
·
Thanks for your input. It is not news to me though about the capabilities of the PWMPAL, after all that is exactly why I'm using one.
·
To All the wise engineers:
·
First of all, I apologize to all you gents for my fuzzy description of my problems with the PWMPAL. I didn’t explain a thing...
Thought that by asking for an example program I would find out what I was doing wrong. So far I found that it wasn’t me.
The problems I see are not caused·by my inexperience but by the PWMPAL itself.
When I connect a scope to f.i. (P12) of·my BS2PX·I see intermittent pulses. It should give out 1500 µS·but gives 1503 µS·in general.
I can live with that. But when I enable a counter or·second pulse channel (P13) the channels give out 1503-1528·µS·randomly·leaving me with·the most terrible servo performance. It moans and crunches end wants to run out to the left or right depending on the random fluctuation of the pulse.
To me it seems that it's leaking parts of pulses to other channels. But than again I could be doing something wrong...
·
I am sure I found a glitch and it is not my pal yet…
So please anyone with PWMPAL experience, hop in this message and spread your wisdom…
·
Thanks
Daniël Komkommer
If that would be the case, what can I do about that and can you be a little more specific?
Thanks,
Dani
It's not really obvious, but all power supplies in the system MUST share a 'common ground' -- that is, the Vss of the PWMPAL, the ground of the Servo, and the VSS of the BS2, all must be connected somewhere.
Sounds like the VSS of your PWMPAL and the power ground of your Servo's aren't connected. The reason this is important is that the servo uses the voltage difference between the Control Signal and its local ground to control what it does. Now, the PWMPAL is putting a pulse on that Control Signal line referenced to ITS ground, while the PWMPAL is reading that signal based on ITS ground. Thus, the two grounds MUST be the same for reliable operation.
And you INSURE both grounds are at the same voltage by connecting them together.
Another possibility is how far away are your Servo's from your PWMPAL? And if they are more than 10 feet away, how shielded is the cable going to them?
I have a BS2PX and a PWMPAL directly on a USB-BOE. 2 parallax continues-servo's directly to the P12 and P13 of the BOE.
The powerunit is 300mA 9 volts from parallax.
Everything is connected to one power supply and the servo's·have a cable length of 20cm.
Now when I connect a pulse measuring device, also 20cm cable, and only 1 servo on the·BOE's·P12 without hardware control the pulse is good about 1500uS. When I enable hardware control and/or a counter·on that channel or any other channel P8,9,10,11 for that matter, the pulse is bad...
I'v measured P12,13,14,15 with or without hardware control and/or counters and every time I have a irradic pulse. So what do you say????
(Picture is of the BOE, BS2PX, PWMPAL and 1 servo)
Parallax is on vacation I guess..?
The big difference between the BS2 and the PWMPAL is that the BS2 doesn't have to 'refresh' the PWMPAL. If you ARE 'refreshing' the PWMPAL, it's possible your refresh is interferring with the PWMPAL's control of the servo.
Otherwise, it looks like your grounds are all connected, everything is correct. 300 mA seems low for more than one servo, so it's possible your Vdd is 'browning out' -- but you'd get a much more obvious symptom than a 'long' pulse should that happen.
I guess I'll have to leave it to Parallax at this point. Probably they haven't stepped in so far to give you and I a chance to work it out for ourselves.
Philip, there are no proven programs for 2 servo's and the program's dat do exist, one from nuts and volts about a DC motor, do not cover servo's.
Not sure what I can offer. The Parallax Servo Controller (PSC) is what I would normally recommend for servo control…You can use the PWMPAL, however one thing to note is that while it receives serial data there will be a momentary glitch in the PWM output. This is usually very small but if you’re sending constant streams of serial data it could become more pronounced. It has also been noted that at certain frequencies there is not a complete range of duty cycles available. This is normal. You should be sending out pulses of 1 ms to 2 ms spaced at 20 ms intervals. Is this what you’re seeing on the scope?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
CC:Philip,
every now and then, intermittent, I get pulses in between e.g.: 1475 1500 1525. I will explain a bit...
·
I use Futaba/Parallax Continues Servo's;
Center/Stop = 1500uS for the PWMPAL OnTime=60 OffTime=800
CCW ··········= 1475uS for the PWMPAL OnTime=59 OffTime=800
CW ············= 1525uS for the PWMPAL OnTime=61 OffTime=800
·
The PWMPAL can only generate pulses based on 0.000025 uS leaving me with gaps of a 25uS range I can not use to drive the servo's while they are capable of receiving smaller steps in time. On the scale it reasons like STOP, SLOW, FASTER,· TO FAST, WAY TO FAST, FLIGHING, etc.... I hope you get my point. For my project I need to go as slow as possible and the slowest with the PWMPAL seemed within the limits. But the problem is that the PWMPAL sends intermittent pulses somewhere in the range it can not be in (smaller than 0.000025uS) and the result of that is that the servo moves a little every now and then. This is deadly for my servo's and my own brain because of the extra strain on gears and spend time in programming against unforeseen jolts to the right or left. The PWMPAL is actually leaking pulses it spontaneous generates amongst the 4 servo pins. It occurs mainly when I am not sending serial data at all. When I send some serial data it is to move the servo’s and when a little glitch occurs on that moment it doesn’t matter. When the servo is positioned no serial data is send to the PWMPAL, the BS2PX is busy doing other things during that time. I investigated that with an extra DEBUG BELL in the Sub where the serial data would be send. It just does not beep!! But the servo is moving just a tiny little bit by itself. The scope sees the 20mS 0v and on average 1500uS stop pulse but it also shows the intermittent· 1..15->1500<+1..15 meaning a little less and a little more than what it should be. When the PWMPAL is programmed to 1500uS (stop for my servo) it shows clearly random pulses. The PWMPAL is the only one generating pulses to the servo’s. Oh yeah….!! I almost forgot…
When I do pulse out a led with the BS2PX on fi. Pin 3, it increases the PWMPAL’s random behavior !?.
·
Before I bought the PWMPAL I looked at the PSCusb, could you tell me if the PSCusb has a smaller time unit than the PWMPAL time unit of 0,000025 ? would I be better off to invest the extra little money and whould I get my money’s worth?
·
What I need de servo’s to do is slow small movements and stable pulsing….
·
Daniël
Ps: sorry for my poor use of language ;o)
·
I did what you suggested before with a lot of different off times too and now again but with 740.
Can you tell me why 740 in stead of 800?
I’m a bit confused in “nuts and volts – Get your motor running” it suggests to decrease the Off-time when increasing the On-time and increase the Off-time·when decreasing the On-time. But nowhere in the examples I found it is mentioned. It could be that I read beside the lines or so….
And what about other base frequencies?
·
I’ve attached a simple little program I wrote in order to understand the PWMPAL’s effect versus the regular PULSOUT in PBasic and where the problem occurs. It threw me off my chair for some time because I thought in that time that I was doing something wrong because of the servo moving just very slowly when I didn’t push one off the buttons. When I pushed I was a little disappointed because it went too fast but it actually did what it was supposed to do, sometimes after releasing the pushbutton I heard a soft “buzzing” sound, the servo moved very slow. It wasn’t supposed to do that, I thought (perhaps a jittering pushbutton or so), but it made me kind of happy because of the slow speed I was experiencing. Hours later I was disappointed again not being able to force this slow speed….
Back to reality….and the drawing board what is going on you think?
Daniël
thanks for your educational reply!.
New most of it and as i explained earlier tried all that even with different base frequencies but thanks for reminding me.
I posted a program showing that I do understand (http://forums.parallax.com/attachment.php?attachmentid=48283). Fact stays that the the measuring device (in stead of a servo) shows the spontanious little peaks when the pulse is set to the center (stop servo in my case 60:740).
Now with all base frequencies and configurations the measuring device shows the spontanious peaks not comming from anything else but the PWMPAL to my opinion·so you are completely right stating "This is typical of a servo not receiving the correct signal pulse, and/or pushing the servo beyond it's mechanical limit due to an incorrect signal pulse." Though the signal pulse comes from the PWMPAL intself and that has been the problem from the start!
So what can I do to get rid of this incorrect pulses ??? please!
I was having a random pulse problem trying to use the PWMPAL for audio tone generation.
I ended up curing it by adjusting the initial settings. (control/status bytes)
I don't remember the exact settings I ended up with, nor did I undestand why it was doing what it was doing, but it ended up stable. This may work for you since I was getting the same impression that you are in that there was some kind of bleedthrough on the chip. I think there was but the proper setup negates the problem.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
·
Hitsware,
·
With proper setup you mean something like?:
Change the setup in my example program (http://forums.parallax.com/attachment.php?attachmentid=48283)
To ;
Setup:
· SEROUT PWM_Pin, PWM_Baud, [noparse][[/noparse]"!PWMSP", %00000000]
· SEROUT PWM_Pin, PWM_Baud, [noparse][[/noparse]"!PWMSS", %00110011]
RETURN
·
Chris,
·
Would the above be what you mean?
Does the PSC have problems like this or is it save to get one?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
do you mean to say that what I am doing is against all logic? Am I overlooking something. That would be very possible but I am eager to learn!
Just ordered a PSCusb to be on the safe side. It has the same frame size as the BS2PX (if I am allowed to put it that way) looks promising...
Is it weird to ask if I could use a Schmitt Trigger on the pins P12-P15 to “polish” the intermittent pulses of the PWMPAL? Or am I talking nonsense now?
Dani
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
Below is what I ended up with.
As I remember it was a matter of setting all the control bits
high that would still allow the code to function.
I did it empiracally so you might experiment.
It was real frustrating for awhile (and Chris could
never repeat my problem) but it was (and is (I
just did a short run)) VERY real....
serout 0,6,[noparse][[/noparse]"!PWMSS",255]
serout 0,6,[noparse][[/noparse]"!PWMSP",240]
x var byte:y var byte
c var byte:n var nib
chord data 16,12,9,12, 12,12,9,12, 16,12,9,9
data 12,12,16,12, 16,12,9,12
notes data 1,4,3,4
dt var word:d1 var byte:d2 var byte
play
for x=0 to 19:for y=20 to 23
read x,c:read y,n
dt=3636/(c*n)
d1=dt//256:d2=dt/256
serout 0,6,[noparse][[/noparse]"!PWMM1",d1,d2,d1,d2]
freqout 1,250,c*22,c*33
next[noparse]:next:[/noparse]goto play
'listening to pin 12 (through a 680 Ohm resistor)
'summed with pin 1 (through a 220 Ohm resistor)
'plugged into a mono hi-fi (with attendent attenuation)
okay than... as soon that I get the PSC running I'll get back to you.
I agree about the right hardware thing and hope that the PSC will be a better choice.
Hitsware,
I am going to tryout your suggestion but not for long. Have been on this road for a while now and should get back to the order of the day. Will keep this thread updated about my progress and for the moment…. I would like to thank all of you for your input. It's great to find the right support when you’re in a dubious situation on a quest for knowledge.
Thanks again and good work!
Dani