PWM?

I'm trying to get a robot moving using a L298N driver. The PWM signals I'm sending aren't being interpreted correctly. I've checked the code & wiring, and I'm sure they're correct. I've tried PWM pins 5 & 6, and 10 & 11 - if I set them to "HIGH" with digitalWrite, the driver works correctly. "analogWrite(10, 255);" doesn't work right - one motor spins, in one direction only, and the other just hums a bit. The indicator LEDs on the driver don't show the normal pattern, either. Again, if I swap the analogWrite with a digital "HIGH" in the code,everything works perfectly... Could something be wrong with multiple PWM pins??

Hi. Show us to what you connected pins 5/6 and/or 10/11. Best would be to show the whole hardware setup, because the trouble could very well be a combination of problems. And while you're at it: show the entire code too.

And the code - you might be using a library that uses timer1.

if you don't have an oscilloscope handy, as a simple test, hook up some led's to your pwm pins and their brightness will be proportional to the pwm pulse length. if they're lighting correctly with varying values then you may have a hardware problem. if they're acting weird, we can narrow it down to software.

In my opinion, you should first measure voltage by increasing pwm with a voltmeter. If your motor are 12V, and suppply voltage are 12V then you should see approx 6V when you apply 128 to PWM signal. If there is sth wrong with values then, as said above, it may be a timer issue.

PWM of 10 out of 255 is unlikely to do more that make the motor hum - you have to provide a minimum level of drive to overcome friction.

Normally you'd not expect a linear response to PWM duty cycle unless you use synchronous rectification mode at a high enough frequency. Try 50% duty cycle.

Don't forget that a 298 is going to eat at least 2 of your volts, up to (iirc) almost 5 at higher current.....

MarkT, as understand it, the first value in the analogWrite command is the pin#. To clarify, I'm testing at a value of 255, or "full on". Again, the code & electronics work fine if I swap "digitalWrite(10, HIGH)" for "analogWrite(10,255)". I can use both motors, change motor directions, and the LED's work the way it seems they're supposed to. (The bridge indicator LED's on the L298 board)

Doh, I must have been dozey! Must be the timer's not in PWM mode.

Now that sounds like it could be the problem... I don't suppose there's an easy way to turn PWM mode on?

Cross-post. Thread locked

Let's unlock this one and keep it active in Motors & Mechanics vs Programming, etc. Crow, Please post your schematic and wiring diagram - Reply and use the Attach feature under the message area. Every one's been guessing as to your problem, but you've provided little to go on. I''ll close out some of the other topics you started in the meantime.

@CrossRoads FYI: The link you posted in the locked thread http://forum.arduino.cc/index.php?topic=335075.0 is badly mangled http://"http//forum.arduino.cc/index.php?topic=332656%22

Pete

The forum seems to keep screwing that up, adding extra http and spaces stuff. Thought I had it fixed, but maybe not.

Please see the response I posted here - http://forum.arduino.cc/index.php?topic=335047.0

Hi,

What model arduino are you using?

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you please post a copy of your complete sketch, using code tags?
They are made with the </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

We need to see what you are working with.

WHY???
You have the project infront of you, we don’t.
You know how it is wired, we don’t.
You know how you are powering the motor and arduino, we don’t.
You know how you are outputting digital logic to the H-Bridge, we don’t.

Sorry for all the requests and WHY?? but we have had so many forum threads start without enough information and they go on for PAGES, only to find that one piece of info was not offered that could have saved PAGES, to help solve a problem.

The model arduino is important as not all pins are the same on all models.

Tom… :slight_smile:

These questions have been asked before, they were already in the 1st reply. So take time to answer them. Stop telling that you've done everything correct, because in that case it would be working. You are missing something, and are asking (desperately) for a solution. So show what you've got. We know by now what you want and what you think you are doing. Now we need to know what you actually are doing.