SparkFun Forums 

Where electronics enthusiasts find answers.

Discussions on the software and hardware for Atmel's STK standard.
By davbeck
#69463
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.
User avatar
By leon_heller
#69472
Transients from the motor are probably doing something nasty to the AVR. You need to redesign your PCB.

Leon
User avatar
By bigglez
#69482
davbeck wrote: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?
By davbeck
#69523
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?
User avatar
By leon_heller
#69530
You can't drive a motor directly from an output pin! Use a suitable BJT or MOSFET.

Leon
User avatar
By bigglez
#69551
davbeck wrote: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.
By davbeck
#69595
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%.
User avatar
By bigglez
#69645
davbeck wrote: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!
By davbeck
#69647
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.
User avatar
By leon_heller
#69649
davbeck wrote: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
User avatar
By bigglez
#69655
davbeck wrote: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.
User avatar
By bigglez
#69656
davbeck wrote: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?
By signal7
#69785
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.
By davbeck
#69798
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
User avatar
By leon_heller
#69800
Most power MOSFETs have it built-in.