PIC16F877 PWM (2 channel) code and Proteus simulation
This post answers the question, “How to make a pulse width modulator using PIC16F877” ?
Also, using PIC16 simulator (Proteus) you can verify this PWM code and change it according to your needs. You can download the complete project code and Proteus simulation from the ‘Downloads‘ section at the bottom of this page.
This PIC16F877 microcontroller tutorial provides the 2 channel PWM code (using C language) and Proteus simulation ( written using MPLAB and HI-TECH C compiler ). There are many uses for PWM signal, e-g you can control dc motor speed using PWM. CCP is the name for the built in PWM module in PIC16F877. There are 2 built in PWM modules available, namely CCP1 and CCP2. This code is using both CCP1 and CCP2 modules to generate 2 separate PWM signals.
It is assumed that you know how to blink an LED with PIC16F877 microcontroller. If you don’t then please read this page first, before proceeding with this article.
The following diagram (made in Proteus) shows the PWM generator circuit diagram.
A crystal of 20MHz is used here with PIC16F877. As we know that any PIC micro controller has an architecture which executes an instruction in 4 CPU cycles, hence this 20Mhz crystal makes this PIC16F877 run at 5MIPS (Million of instructions per second). In the above figure, it is clear that a PWM of 4.9kHz frequency with 50% duty cycle is being generated at RC2/CCP1 pin and a PWM of 4.9kHz frequency with 75% duty cycle is being generated at RC1/CCP2 pin.
The code for main function is shown below.
2 channel PWM code using PIC16F877 was compiled in MPLAB v8.85 with HI-TECH C v9.83 compiler and simulation was made in Proteus v7.10. To download code and Proteus simulation click here.
For more detail: PIC16F877 PWM (2 channel) code and Proteus simulation
JLCPCB – Prototype 10 PCBs for $2 + 2 days Lead Time
China’s Largest PCB Prototype Enterprise, 300,000+ Customers & 10,000+ Online Orders Per Day
Inside a huge PCB factory: https://www.youtube.com/watch?v=_XCznQFV-Mw
Current Project / Post can also be found using:
- language pic16f877a like arduino
- LM35 WITH PIC16F877A PROTEUS
- proteus generator usb signal
- pwm code pic16f877a