# Algorithm for a program to generate pwm signals using pic 16f877

Discussion in 'Embedded Systems and Microcontrollers' started by varunkumhar, Jan 8, 2010.

1. ### varunkumhar Thread Starter New Member

Jan 8, 2010
2
0
hi.i am currently working on a project which converts a 50 hz frequency input into 800hz frequency output.the principle employed is to first convert the input ac to dc using a rectifier and then to use an inverter to convert this dc to the ac output at the required frequency. i am planning to implement the inverter using a mosfet bridge which is triggered by pwm signals supplied by means of pic 16f877 microcontroller. please help me with the pic programming. i would be very thankful if anyone could post the program or algorithm

2. ### beenthere Retired Moderator

Apr 20, 2004
15,815
283
Why do the up conversion? Use some fixed oscillator to generate a frequency and divide it down to 800 Hz.

3. ### varunkumhar Thread Starter New Member

Jan 8, 2010
2
0
hi thanks for your reply.mine is an industrial project.the company requires 800hz for transformer testing purposes.please help me with the pic programming to generate pwm signals to trigger the mosfet.

4. ### SgtWookie Expert

Jul 17, 2007
22,183
1,729
Well, if you take a 50Hz AC signal and run it through a full-wave bridge, the output will be DC with 100Hz ripple.

What are you trying to do; create a pseudo-sinewave output via PWM? Or are you trying to simply perform a push-pull conversion?

5. ### Markd77 Senior Member

Sep 7, 2009
2,803
594
You should be able to get 800Hz with a 4MHz clock.
Just use the formulas in section 8.3 of the datasheet, ie:
PWM period = [(PR2) + 1] • 4 • TOSC • (TMR2 prescale value)
With 4 MHz clock TOSC would be 0.00000025
and 800Hz is 0.00125
PR2 should be 77 (decimal) and TMR2 prescale should be 16
This gives 801.28 Hz
You will need to do a similar calculation for the duty cycle.

6. ### Art Distinguished Member

Sep 10, 2007
797
61
The 16F877 has a hardware PWM pin.
You can just set it and your program can run at the same time.