Please help! PWM

I've been looking for help in the forums for a week. PLEASE read this before replying. I have a L298N motor controller, and I'm trying to get PWM mode turned on so I can have variable speed control. Nothing is wrong with the wiring or code. Apparently the timer isn't set to "PWM mode". I've read the tutorials, analogWrite documentation & all the L298N docs. I just need to know how to turn PWM mode on. Thanks in advance.

PWM is not a "mode" and you don't turn it on/off you just use analogWrite().


The timers are all pre-configured for PWM when programming through the Arduino IDE - the init() function in wiring.c (line 241 through 353) sets all the timers on the MCU for PWM mode.

You only have to configure timers for PWM if you're not using the Arduino IDE, or you need some exotic kind of PWM - in that case, see the datasheet for details.

If the pin is not in PWM mode, your code (maybe a library that uses timers?) is configuring it that way.

Assuming it's not that, you're doing something else wrong. You should post your code, schematic, and which board/mcu you're using.

Also, you've crossposted this in a million places - can you please stop posting it elsewhere?

PWM is not a "mode" and you don't turn it on/off you just use analogWrite().


Actually, timers do have a mode, and it does need to be set for PWM output in order for analogWrite() to work - see the section "Modes of Operation" in the datasheet under each corresponding timer. But as I said above, if you're programming with the Arduino IDE (which you are, if you're using analogWrite()), this is already done for you.

Cross post.
Thread locked.

I'm getting bored now.

Topic closed - go here