Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

SPWM generation using microcontroller

Status
Not open for further replies.

sriblue7

Member level 1
Joined
May 6, 2011
Messages
41
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Chennai
Activity points
1,614
Hi all!!!
I am trying to generate SPWM signal for the inverter using Atmega8.
The following are the parameters i have fixed.
PWM carrier frequency=31.25k(8M/(1*256)---->No prescalar and fast PWM.
Aim is to get 50Hz sine output.
I have used two different sine wave tables for simulation
1)I have used 255 variables for half period of sine.So the output frequency would be 31.25K/510=62Hz(approx.).here is the prog(pwm1) and simulated result(sim1 and sim2).
View attachment pwm1.txt sim1.JPGsim2.JPG
2)I have used 255 variables for one full period of sine.So the output frequency will be 31.25k/255=123Hz.To get 50 hz i have to send each value of the sine table thrice.here is the prog(pwm2) and simulated result(sim3)
View attachment pwm2.txtsim3.JPG

1)are my calculations and programs correct?
2)Which one is correct 1 or 2?
3)Though i have used the common sine table in net for 2,i am not getting a clean desired sine wave?
4)do i need any other output from microcontroller to drive H-bridge apart from the two out of phase signals at OC1A and OC1B?
5)how can i get a frequency between 50-60hz,as for any prescalars i am getting a frequency only out of this range.
 

You refer to Tahmid blog,there are interresting and you discover all of what youant with the SPWM.

For me I am repairing a DC-AC which was using 28KHz for controlling the H-Bridge,because this command baord was bad I made another one using PIC16F876A but I am not coming to generate the 28Khz which I want.(can you give me an idea on this).

With Tahimid's blog you get all calculations for getting 50Hz at the output.
The program also in MikroC are there:https://tahmidmc.blogspot.com/2013/02/demystifying-use-of-table-pointer-in.html

Good Luck
 

There are various ways to change your output frequency, depending on what kind of resolution and accuracy you want. One option is to implement a software DDS where you have a phase accumulator and a very large lookup table. That requires a great deal of ROM, but can be very fast. Alternatively you can actually calculate the duty cycle dynamically using a sin function, though this requires more computing power (but may still be workable with an atmega8).
 

Id work it this way,
Carrier signal=31.25kHz = 32uS = period
Half wave @ 50Hz=20ms/2=10mS
10mS/32uS= 312.5 divisions/half cycle
312.5/4=78 values of sine repeated four times

180 degrees/78 divisions = 2.304 degrees/division

use excel to make a table with 1-78 in column a, column b = sin(a*pi()/180) (converts from radians), column c = b*(PR2-1) (pr2=255 in your case)

copy and paste for all divisions and column c is the sine table values.

Dale
 

Why don,t you use another timer like timer(0) to interrupt after 10ms where you select your upper half phase and together with your sine table repeat this process for the lower half phase too. this will give you freedom to select any frequency for your spwm as timer0 will take care for the real frequency of 50Hz. For full bridge you would need four signals to drive. This is just the beginning of the journey as after accomplishing this task you will need to correct your table dynamically for changing loads and battery depletion.
Search here as someone already had given code for this but in Bascom however you can catch the idea.
Hope for your success.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top