PDA

View Full Version : How to generate PWM signal using AVR?



04-04-2005, 11:24 PM
[1]
I want to control speed of DC motors by giving PWM signal of variable duty cycle to the motor driver's enable pin.
If I want to generate a PWM of frequency f and duty cycle d using an AVR (ATmega162) how do i go about it ?

[2]
I had tried PWM speed control using parallel port, it worked well at low frequencies (the motors were a lil jerky though) , but at high frequncies the motor used to run at full speed irrespective of duty cycle.
It appeard to me that the voltage didnt drop from HIGH to LOW at the motor driver's enable pin in accordance with the signal, and LOGIC 1 was maintained all the time. maybe theres another reason.
neways let me know solution coz the same problem might bug me while working with the uc.

I use CodeVision AVR to write code in C and convert it to asm, then use asm for simulation in AVR studio 4. Target uc: ATmega162

yogi
04-05-2005, 03:40 AM
Why are u applying PWM to enable pin
Apply directly to motor pins. Use electronic differential to ur motors

IF you use PWM of higher frequencies the pbm is that
your motor has a specific inductance, it require some time to charge to peak of voltage . IF you apply high frequency motor won't be able to charge to full current. So you apply low frequencies. I applied only about 10mS.



bibinjohn
www.bibinjohn.tk

04-05-2005, 08:55 AM
What is electronic differential?
The motors take 1.5 to 3 A a uc cant supply that much, so i am using a motor driver.

yogi
04-06-2005, 05:18 AM
i meant applying 48% cycle to one motor
and 52% to other one

this is almost like mechanical differential

samrat189
04-06-2005, 12:09 PM
ya yogi u r right. as frm my exp i got that if u apply pwm to enable pin mtr wont stop sudnly(brake) due to inetia.so apply pwm directly to u r motr pins.and give logic 1 1 to stop.

and at high frqn ur motr coil is not able to get that signal.so it wont give correct output.so if u want to apply high frqn,apply voltage more than than the rated voltage to u r motor.but make sure that the effetive current in the motr is not more tahn rated value( adust the freqncy). for this u can se a current sensing resistor( go through the old posts).


i hope this may help u

technojunk
04-09-2005, 11:53 PM
as frm my exp i got that if u apply pwm to enable pin mtr wont stop sudnly(brake) due to inetia.so apply pwm directly to u r motr pins.and give logic 1 1 to stop.


samrat wat u said is wrong both theoritically and practically.... giving 1 1 or high at both ends wont cause breaking action!! ... we did a lot many exp on PWM and finally as u said inertia was the leading problem which forced us to use discrete voltage level stepping or short the motor terminals ( in order to cause breaking action ) .

1 1 will mean that potentail diff is zero and its almost same as open circuit ..... but with a lille resitance to back emf!

04-12-2005, 11:07 PM
hey ice in u r site in u parallel port tutorial also u mentioed that logic 00 is stop and logic 11 is also stop.then wat is the difference btwn these two stops...

samrat189
04-13-2005, 12:13 AM
hai junk

i am sure that logic 11 in ur driver ic causes braking i'll give a theoritical and practical proof for it
for theoritcally:logic 11 in u r driver ic provides two equal voltage values to u r motor pins(which is not done in u r free state) which locks the armature
practically:simply apply a positive voltage to both pins of u r motor and try to rotate it

i may not able to explain clearly but its true taht motor'll brake by the application of logic 11 in u r driver ic

ice
04-13-2005, 10:00 AM
u mentioed that logic 00 is stop and logic 11 is also stop.then wat is the difference btwn these two stops...

00 switches off power to the motor...The motor brushes do not get any voltage...u can freely move the shaft with your hand

11 applies voltages to both brushes,locking the shaft[possible with a motor driver]...u may be able to move it when the motor is non-geared[but with some resistance]..
Try it with a geared motor ,it locks in place...


theres another parallel link running
http://roboticsindia.com/modules.php?name=Forums&file=viewtopic&t=560

04-16-2005, 07:38 PM
if i decide to apply PWM to motor pins then i'll have to write 00 (or 11) on motor pins add delay then write the code for desired motion on the pins n add delay.
this can b done only thru software which will make the process slow. i want to use the hardware PWM feature on the uc.
i cant apply harware PWM to motor pins coz they would interfere with the uc's signals which control direction of rotation.

I had read an article on motor drivers in which the author had mentioned that the enable pins are mainly used for PWM speed control.

how do u guys contol speed?

i was also thinking of using 4 motor drivers in parallel (ie with all corresponding pins shorted) except the enable pins which would be connected to different pins on the uc. by enabling 0 or 1 or 2 or 3 or all 4 ICs i can get 5 different speeds.
how is the idea?

ice
04-18-2005, 10:53 AM
I use the enabe pins to control PWM for the L293d..a fequency of around 20Khz does the job.

I use the harware PWM feature of my PIC for PWM generation in the background.


except the enable pins which would be connected to different pins on the uc. by enabling 0 or 1 or 2 or 3 or all 4 ICs i can get 5 different speeds.

BackPacking the drivers one on top of the other [which would mean a parallel config]..wont give u different speeds,but will allow for higher curent handling.

nice idea BTW..never thought abt it bfore