AVR PWM Motor Control

How do I control the speed of a motor (not servo, not stepper) with the ATMega168? When I try to use PWM like I do to dim an led, the motor locks up and emits a high pitched noise.

Transients from the motor are probably doing something nasty to the AVR. You need to redesign your PCB.

Leon

davbeck:
How do I control the speed of a motor (not servo, not stepper) with the ATMega168? When I try to use PWM like I do to dim an led, the motor locks up and emits a high pitched noise.

What size motor? (voltage and stall current) Is the motor

Connected directly to the uC pins?

I have it connected directly to the microcontroller. Do I need to put a diode in between so it doesn’t break and just coasts?

You can’t drive a motor directly from an output pin! Use a suitable BJT or MOSFET.

Leon

davbeck:
I have it connected directly to the microcontroller. Do I need to put a diode in between so it doesn’t break and just coasts?

What size motor? (voltage and stall current?)

Until we know this data there is no way to know if you

can direct connect it to an AVR IO pin.

I tried a few motors I salvaged. The key is that it will run on the output pin just not when I try PWM on even 90%.

davbeck:
I tried a few motors I salvaged. The key is that it will run on the output pin just not when I try PWM on even 90%.

Nope. The key is this:

What size motor? (voltage and stall current?)

Third request!

You have not provided enough basic facts to help you!

My point was I didn’t know the specs of the motors I was trying because I they didn’t come with a data sheet.

I got it working with a transistor but I don’t think it was the voltage increase but the fact that it wasn’t being ground out on the low side of the PWM and breaking.

davbeck:
My point was I didn’t know the specs of the motors I was trying because I they didn’t come with a data sheet.

I got it working with a transistor but I don’t think it was the voltage increase but the fact that it wasn’t being ground out on the low side of the PWM and breaking.

The second para is completely incomprehensible!

Leon

davbeck:
My point was I didn’t know the specs of the motors I was trying because I they didn’t come with a data sheet.

So use a DMM or VOM to measure the motor in your hands today.

davbeck:
I got it working with a transistor but I don’t think it was the voltage increase but the fact that it wasn’t being ground out on the low side of the PWM and breaking.

Sorry, can't follow your text. Can you

post a schematic of how you wired up your

motor and the transistor?

I’d suggest taking a look at some other motor control circuits online. At a minimum, you’ll want to have a transistor/mosfet with a clamping diode to protect the uController from transient spikes that occur when the transistor/mosfet turns off. Also, a decoupling capacitor on the line supplying power to the motor/transistor/diode portion of the circuit would further help to stabilize the power supply. If you hook an oscilloscope up to your motor and look at what happens when the PWM signal turns off, you’ll probably see a big voltage spike that you didn’t expect.

I’m looking for what you mean by clamping diode and can’t seem to find anything online. Do you mean a diode between the micro and transistor?

Thank you for your help

Most power MOSFETs have it built-in.

davbeck:
I’m looking for what you mean by clamping diode and can’t seem to find anything online. Do you mean a diode between the micro and transistor?

No. The clamping diode, which may also be called a

[[u]back-EMF[/u] diode, [[u]catch diode[/u], or even [[u]snubber[/u] diode,

is in parallel with the load (motor). Alternatively it

may connect in parallel with the load switch (FET).

Its role is to [[u]clamp[/u] unwanted energy from the load

(your motor) that may feedback into and upset the

other circuitry.

One should not rely on the internal diode of a PMOSFet,

which is an artifact of the transistor’s construction. Often

the diode is inferior to the FET, and abuse may lead to

failure of the transistor.

A schematic of your intended circuit would go a long

way to helping us help you, by cutting out the guess

work on both sides. Really.](Clamper (electronics) - Wikipedia)](Snubber - Wikipedia)](Flyback diode - Wikipedia)](Counter-electromotive force - Wikipedia)

It’s also called a freewheeling, supressor, or flyback diode. It’s connected across the motor windings to prevent an inductive spike when the field in the motor windings collapses.

http://en.wikipedia.org/wiki/Flyback_diode

I’ve spent a lot of time reading wikipedia electronics posts lately. I’m amazed at the wealth of information on the subject posted there. It almost invalidates my text books from when I was in college.