PWM and 4 motor control
Macgman2000
Posts: 59
Hello,
I have an application that deals with controlling the speed of 4 DC motors simultaneously. So I need 4 PWM ports and·4 input ports·for measuring RPM speed of each motor and controlling it such that it maintains that set speed (for all 4 motors). This is a dynamic system.
Basically it is a closed control loop on all 4 motors. Can this be done with the SX, I am using serial input to set motor speeds.
Best Regards,
nick
·
I have an application that deals with controlling the speed of 4 DC motors simultaneously. So I need 4 PWM ports and·4 input ports·for measuring RPM speed of each motor and controlling it such that it maintains that set speed (for all 4 motors). This is a dynamic system.
Basically it is a closed control loop on all 4 motors. Can this be done with the SX, I am using serial input to set motor speeds.
Best Regards,
nick
·
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Nick
for one of my customers, I have developed a triple PWM motor controller with the SX28 (see www.parallax.com/sx/projects/projects_pwm.asp for more details). In the beginning of the project, I even provided four motor channels but later, it turned out that they only needed three. I'm not using the motor tacho pulses for speed control but to control the motor positions relative to reference points. Besides generating the PWM signals with soft-start ramps, and counting the tacho pulses, the SX also checks each channel for over-current situations, reads end and reference sensor inputs, handles the code for an I²C slave for communication with a master controller, and runs a timer to handle time-out conditions, i.e. all motors stop when the controller does not periodically receive commands from the master.
Although your project is different, there are some similarities, so I'm pretty sure that it can be handled by a single SX28.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greetings from Germany,
Günther
sorry for my late answer. My PWM application is in assembly. I have checked all existing versions of my code but all of them handle three motors only. As far as I understand, the motors you are using don't have tacho pulse generators, so you have to derive the commutation pulses with extra hardware.
Please understand that I have developed this application for one of my customers, so I can't disclose the full source code to the public in this forum. Nevertheless, I'm ready to share with you parts of it via private eMail g.daubach@mda-burscheid.de).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greetings from Germany,
G
· What is the width of the pulses at maximum speed ?
· Do you have a schematic you can post ?
· Can you post your code ?
· Don't make us beat the information out of you [noparse];)[/noparse]
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap 4-digit LED display with driver IC·www.hc4led.com
COMING SOON "SD DATA LOGGER" www.sddatalogger.com
"I reject your reality, and substitute my own." Mythbusters
·
·I want to run the PWM output at·510us period (about 2Khz), ON pulse width in·steps of 2us (255·steps·x 2us = 510us, for 100% duty cycle). Eventually·I want to have this on all 4 motors (independant duty cycle on each, same period).
I have been spoiled by PIC because of the on board HWPWM. I set the hardware up, use a scaling factor to adjust duty cycle and adjust it as I monitor the pulses in main in a tight loop. I have learned it is much more involved in creating "virtual hardware" in software.· I recognize the power of the SX and want to utilize it. Any help would be greatly appreciated.
Best Regards,
Nick
·
If the PWM is not working, then that is your first task. There is no sense trying to get a closed loop system working unless the PWM is working properly.
What does the tach signal look like ? Is it a positive pulse or a negative pulse ? What is the maximum tach frequency ?
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap 4-digit LED display with driver IC·www.hc4led.com
COMING SOON "SD DATA LOGGER" www.sddatalogger.com
"I reject your reality, and substitute my own." Mythbusters
·
The pulse is positive going. I measured the motor RPM at 100% duty cycle (shaft assembly with 4" diameter disk) using an photo-tachometer, 7,000RPM. I disassembled the motor/hall effect, the mounting was not to my satisfaction. I will remount it and look at the pulse train at full voltage. Since it is 1 hall effect, I remember it was A-symetrical pulses...meaning The high going was narrow compared to the low going pulse.
Best Regards,
Nick
Here is how I would go about it:
· Connect the tach signal to port B pins so you can use the WK_Pend register as a latch to see if a tach signal occured.
· Create an interrupt to occurs every 2uSec.
· In the interrupt:
··· Update the PWM
··· See if WK_Pend is set if it is increase a counter
In the main code (not in the interrupt). Check to see if the counter is too high or too low and adjust the PWM value using PID or whatever you want.
If you run at 50MHz you will have 100 instruction to use in the interrupt (really less than that). Which means the interrupt code will probably have to be assembly.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap 4-digit LED display with driver IC·www.hc4led.com
COMING SOON "SD DATA LOGGER" www.sddatalogger.com
"I reject your reality, and substitute my own." Mythbusters
Post Edited (Bean (Hitt Consulting)) : 5/8/2006 4:19:36 PM GMT
Err, you sure about that?
Seems more likely to be 7000/60 , or 117Hz, rather than your rather more scary 7000*60...
Steve
Thanks, I knew when I wrote that that something didn't seem right.
Of course you are correct. It should be 7000/60 = 117 Hz
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap 4-digit LED display with driver IC·www.hc4led.com
COMING SOON "SD DATA LOGGER" www.sddatalogger.com
"I reject your reality, and substitute my own." Mythbusters
·