PWM the most efficient way

Jun 14, 2006 9 Replies

Hi, I'm in need of help.. lets see if I'll manage to explain the problem..



I'm planning to build a mechanical arm that will be moved by 4 DC motors (6-50W, depends..) and 1 stepper, whole thing will be controlled by a microcontroller (AVR). The DC motors will be controlled by separate H-bridges together with somekind of PWM control.



Now, I've seen alot of pages using either a microcontroller to generate the PWM sequence or a separate circuit where the shape of signal is regulated with a potentiometer, like one circuit here:

formatting link



None of these solutions seems to suit.. First would take up much of the uC's time and one would not be able to move several motors at the same time. While, the second solution seems to be not suitable for an uC, because, there, I would need to generate a variable voltage to regulate the PWM output.. kinda tedious (would require DA converter..)..



I'm wondering if it's possible to make such a PWM circuit, in which I input a digital value (say a byte through one pin or through several pins) which is remembered and executed?



Say, I input 0001 and PWM circuit gives smallest pulses I input 0010 and PWM circuit increases the pulse width and so on, where 1111 would be the maximal pulse width..



Or, maby theres a nicer solution that includes automatic ramping of the puls width?



Also, would large DC motors be operated without problems from common



4-transistor or 4-MOSFET H-bridges, as long as I use high enough values of the components? I've only built H-bridges for

The ATTiny2313 has 4 PWM outputs built in, the AT90PWM3 has 10

these outputs are set-and-forget the processor is not involved in making the signal, only setting it up or changing the level.

Bye. Jasen

Whow, thanks alot! 4 pwm outputs, this is just what I need :)

By the way, my electronics supplier doesn't carry AT90PWM3.

Posted via Mailgate.ORG Server - http://www.Mailgate.ORG

Have you considered using off the shelp speed controllers for model cars? I'm more familiar with those for model aircraft but I think the car controllers take the same variable width pulse input (typically 1-2mS long) and turn it into PWM forward, brake and reverse.

About a year ago I downloaded a table listing the AVR range and what features they had from the atmel site and printed it out. The AT90PWM3 may be obsolete. There are other devices with 4 or more PWMs if the 2313's 1K word ROM is too small.

Bye. Jasen

I would probably have to order these for extra cost.. My electronics supplier carries the most common electronics parts.

Any idea if it's possible to automatically have a soft start/stop for the pwm signal in AVR? I mean so when the motor is turned on, it will increase the speed gradually and in the end decrease gradually..?

I tried to read the ATTiny2313's pdf manual but it didn't make me wiser :(

Posted via Mailgate.ORG Server - http://www.Mailgate.ORG

you'd need to slowly increase the trigger level for the PWM.

a interrupt driven soubroutine would that tweaks the level every N times through would be one way.

I epect if you google for -->>> AVR "soft start" PWM you'll find example code.

interrupts efficient, and effective, but are hard to debug, get plenty of practice with non-interrupt code first,

Bye. Jasen

Alright, searched the google for several hours and found some really useful assembler code for AVR, the page is catched by google:

formatting link

I haven't tested the code yet but it seems to be easy to understand.. They use hardware PWM and change the pulse width from the usual program loop.

As I see it now it would be probably easiest to setup one AVR just to generate software PWM signals.. since these uC's are very fast (4MHz) and motors would need maximum 1-5kHz PWM, one would easily set up say 10-20 independant PWM "channels" on any AVR chip. By independant I mean each "channel" can have own frequency, pulse width and possibility to be changed at any time.

Posted via Mailgate.ORG Server - http://www.Mailgate.ORG

formatting link

It's worth considering what the hardware will do if/when the microcontroller crashes. Some form of hardware watchdog timer which can shut off the motor supply without software involvement when the code crashes might be justified in some applications. This probably applies even if the microcontroller with built in hardware PWM generators is used. Chris

formatting link

yeah, that is why many controllers use an outboard reset able one shot timer from the uC In case the uC decides to stop generating the reset pulse . this would then terminate the one shot and disable the dangerous parts. and of course the reset pulse should be in a shoftware loop and not in a hardware timer.

Real Programmers Do things like this. http://webpages.charter.net/jamie_5

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required