PWMPAL Servo Control
homesch00lkid
Posts: 20
I have searched everywhere and I can't find anything that really covers this. How exactly do you control a servo with·the PWMPAL? Can anyone help? Thanks.
Comments
·PWMPAL can control servos or DC motors, but I would only use it for the later.. but that is me
SEROUT Sio, Baud, [noparse][[/noparse]"!PWM1", 60, 0, $20, $03]
The math:
To center a servo we send it a 1.5 ms pulse. The PWMPAL pulse widths are specified in units of 25 uS, or 0.025 ms. Take 1.5/0.025 and you get 60. This is the on-time value. The off time is 20 ms, so 20/0.025 = 800 (hex $0320). Remember that values passed to the PWMPAL go low-byte, then high-byte.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas, TX· USA
BTW, you MUST make sure that the BASIC Stamp pin that corresponds to your PWMPAL output pin is an input; if it's an output low (like after a PULSOUT) then the PWMPAL output will be swamped.· There are resistors on the PWMPAL that prevent pin burn-out, but they're so small (220) that they'll look like a short to your servo.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas, TX· USA
Post Edited (Jon Williams) : 1/2/2005 9:33:00 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas, TX· USA
Post Edited (Jon Williams) : 1/2/2005 10:35:18 PM GMT
The problem with this program was that the ir sensing part of the program took too long, that resulted in the driving of the boe bot to be very jerky, as it would stop the servos compleatly between each pulse.·
This week i ordered a PWMPAL to·continue·sending the same pulses while the·stamp·controler was analyzing the ir.· I really didn't understand the syntax·for the PWMPAL and the waves.· I played around with diferent commands and found an old post (below).· I also found an attached program that worked great, but i just can't get·the syntax to work in my own programs.· One thing i really don't understand is the Lowbyte Hibyte and byte0 byte1· hows that work, whys it do that, what's the low-byte pass, and the high byte pass?· i can use windows calculator to convert 800 to 302 but it converts 60 to something else.· So i guess what i'm really looking for is an explaination of the byte0. and byte1. commands, and how to use them.
thx,
Jonathan
The key with the PWMPAL is that it used Word (16-bit) values, but serial communication is with bytes.· What this means is that we have to split the word variable into two bytes for serial transmission to the PWMPAL.· Lucky for us, PBASIC makes this pretty simple with LOWBYTE and HIGHBYTE -- these are the constituent portions of a Word variable.· Chapter 4 in the PBASIC manual covers variables and you may want to review this as well, it will help.
You can use use the Windows calculator for fixed values -- and convert to hex so you can see the high and low bytes.· The key to remember is that transmission is low byte, then high byte, so if you get $0320 from the Windows calculator the order in the SEROUT block is going to be $20, then $03.
It will also be helpful for you to post the program(s) that is giving you trouble.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
2. In general, are the specifications of the type of information sent, i.e. Binary, Decimal, or Hex? If so, how do you know which type to send when?
Another questions about commands to and from the PWMPal: (based on sample commands found in PWMPAL documentation, downloaded from the Parallax website)
3. When using the "SS" command to set motor control/status, how is the status byte determined? The documentation gives this example:
"SEROUT 0, 6, [noparse][[/noparse]"!PWMSS", %00010000]
The example above enables PWM output channel 1 (P12). The PWM output will begin immediately with the frequency and duty cycle as set with the "Mn" command." And gives the table Control/Status Byte Definitions Table. If you convert that Binary number to a decimal number you get 16.
How do you use the numbers in the table to translate to a status byte to send to the PWMPAL?
4.If you wanted to put PWM output channel 1 (P12) to hardware control, how would you set control channel 1 (P8) high?
Post Edited (Casey_SCU) : 7/10/2006 10:33:27 PM GMT