How to program L298N using PIC 16f877


Joined Jan 6, 2004
Yes, you may easily. Read the datasheet and see what settings you need at reset.

Then, check what pins need to change from high to low (or vicerversa) for every desired output.

The one to program is the micro not the L298.

JUst in case I forgot, read the datsheet. Have you?

Thread Starter


Joined Dec 18, 2008
ya i have go trough the datasheet, but the problem is I don't know how to program PWM inside the motor driver? can you teach me some technique?


Joined Apr 2, 2009
You're PIC will generate the required PWM pulses to your motor driver. Read the PWM section of the PIC data sheet and figure out the duty cycle you want to achieve. In your driver data sheet, you'll find how to interface the PIC with the L298. I suspect you might need to isolate your PIC from your motor driver because of a much higher current flow in the driver.


Joined Feb 22, 2010
Let's try a simple test. You dont have to think about PWM yet. Just assert 5V to the enable pin and test if your motor driver can work. This is the simple way to use L298N.

The PWM signal driven out by your PIC to the motor driver (enable) pin. PIC16f877 have a built-in pwm. You need to read about CCP module, which letter 'P' belongs to PWM. There are a lot of thread discuss about PWM issue..You can search for it.