Shop OBEX P1 Docs P2 Docs Learn Events
PWM and 4 motor control — Parallax Forums

PWM and 4 motor control

Macgman2000Macgman2000 Posts: 59
edited 2006-05-09 11:17 in General Discussion
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
·

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-05-04 01:12
    This thread is being moved from the BASIC Stamp Forum to the SX Forum.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Macgman2000Macgman2000 Posts: 59
    edited 2006-05-04 16:18
    I thought I posted to the SX/B forum...sorry about that.

    Nick
  • Guenther DaubachGuenther Daubach Posts: 1,321
    edited 2006-05-04 16:42
    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
  • Macgman2000Macgman2000 Posts: 59
    edited 2006-05-04 22:47
    Hello G
  • Guenther DaubachGuenther Daubach Posts: 1,321
    edited 2006-05-07 23:07
    Nick,

    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
  • BeanBean Posts: 8,129
    edited 2006-05-07 23:18
    Nick,
    · 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
    ·
  • Macgman2000Macgman2000 Posts: 59
    edited 2006-05-08 00:15
    I don't have a schematic, but it is very simple hardware. I have an N-channel power FET driving a small·DC motor single direction, it also has (added newly) a hall effect sensor·to send feedback tach pulses to the micro. So I use 2 I/O per motor.·I have added 3 copies of the above described for a total of 4 motors with feedback (8 I/O). I have been dabbling on a small scale with one motor and one hall effect sensor to get it to work. I am too embarrassed to post it, it didn't work. I can't get the PWM to work correctly, let alone "locking" the·desired RPM down with the hall effect feedback signal.

    ·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

    ·
  • BeanBean Posts: 8,129
    edited 2006-05-08 11:54
    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
    ·
  • Macgman2000Macgman2000 Posts: 59
    edited 2006-05-08 15:37
    Bean,

    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
  • BeanBean Posts: 8,129
    edited 2006-05-08 16:16
    Okay so 7000 RPM is 420KHz. Which is slightly slower than your PWM update frequency (500KHz), that is good.
    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
  • SteveWSteveW Posts: 246
    edited 2006-05-09 08:57
    >Okay so 7000 RPM is 420KHz

    Err, you sure about that?
    Seems more likely to be 7000/60 , or 117Hz, rather than your rather more scary 7000*60...

    Steve
  • BeanBean Posts: 8,129
    edited 2006-05-09 11:17
    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
    ·
Sign In or Register to comment.