Trying to teach my robot class some PWM DC motor control...Please Help
scidog
Posts: 4
Hi All,
I am trying to make some better code to drive a simple DC motor interface baord.
(For those interested, here they are. I like them.) http://www.sparkfun.com/products/9457
So, I am looking for a way to drive the duty cycle for the DC speed control of both motors simultaneously.
I want a way that strikes a decent balance between efficient and easy-to-learn. Assembly is great and all, but try teaching that to some 8 year olds...
Anyway, I just use the bit bang technique right now; where one does something like:
repeat
waitcnt(dutyON+cnt)
!outa[2] '(where "2" is the PWM input to the motor driver)
waitcnt(dutyOFF+cnt)
I would really like a more efficient way to control two DC motors using a variable percentage duty cycle.
Usually the frequency for the whole wave form is about 4000Hz for the DC motors I have.
So, 10% power is on for 10% of one PWM squarewaveform period and the off for 90% of that same period (the whole PWM waveform period of course covering 1/4000 of a second).
For those more knowledgeable than myself, I think I may have explained things adequately.
Anyone have any code snippets that would show me ways to output 2 simultaneous, variable duty cycle PWM squarewave forms that are at 4000HZ total output frequency?
Just want to control my two DC motors. Any help is appreciated.
Thanks in advance,
John
PS
Prop Fundamentals book mentions some kind of dual PWM stuff in the Objects section, but I am fuzzy. Is this a direction i should go?
I am trying to make some better code to drive a simple DC motor interface baord.
(For those interested, here they are. I like them.) http://www.sparkfun.com/products/9457
So, I am looking for a way to drive the duty cycle for the DC speed control of both motors simultaneously.
I want a way that strikes a decent balance between efficient and easy-to-learn. Assembly is great and all, but try teaching that to some 8 year olds...
Anyway, I just use the bit bang technique right now; where one does something like:
repeat
waitcnt(dutyON+cnt)
!outa[2] '(where "2" is the PWM input to the motor driver)
waitcnt(dutyOFF+cnt)
I would really like a more efficient way to control two DC motors using a variable percentage duty cycle.
Usually the frequency for the whole wave form is about 4000Hz for the DC motors I have.
So, 10% power is on for 10% of one PWM squarewaveform period and the off for 90% of that same period (the whole PWM waveform period of course covering 1/4000 of a second).
For those more knowledgeable than myself, I think I may have explained things adequately.
Anyone have any code snippets that would show me ways to output 2 simultaneous, variable duty cycle PWM squarewave forms that are at 4000HZ total output frequency?
Just want to control my two DC motors. Any help is appreciated.
Thanks in advance,
John
PS
Prop Fundamentals book mentions some kind of dual PWM stuff in the Objects section, but I am fuzzy. Is this a direction i should go?
Comments
There is a discussion about dual motor control in this thread:
-- http://forums.parallax.com/showthread.php?133897-could-somebody-help-me-find-a-bug-in-my-method