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.

CCP mode for PIC16F873 to generate SPWM

Status
Not open for further replies.

sme7000

Newbie level 6
Joined
Dec 16, 2009
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
malaysia
Activity points
1,387
CCP mode for PIC16F873

i want to generate Sinusoidal pulse width modulation(SPWM), what mode is a suitable choice? CCP mode contain capture, compare and PWN mode. the SPWM is generated by comparing 2 signal wave that is sinusoidal and triangle wave. the intersection of that wave is the point where the PWM is generate '0' or '1'. i plan to use a compare mode to generate this SPWM. it is the right mode?
 

Hi,
Choose PWM mode. Set PR2 as per the required frequency and after every specified interval, load the value of CCPR1L with a value from a sine table. Use an L/C filter at the output and you have a sine wave.
 

how can i made a counter for PR2? if i use a compare mode the PR1 can made a counter but cannot define the frequency of triangle wave..this is really confuses me.
 

Hi,
Take for example, you are running at 16MHz crystal, ie, 16/4 = 4MHz system clock, and you want the frequency for SPWM to be 16kHz, then, set PR2 as:
(System clock / desired clock) - 1,
= (4MHz/16kHz) - 1
= 250 - 1
= 249
So, you have the frequency of 16kHz. Then use a sine table with n variables to set the required duty cycles and set frequency at 50Hz.
 

the duty cycle for SPWM is change..the pulse is generated when triangle wave is greater than sinusoidal wave. how can i set time in one cycle for triangle wave? the result of pulse occurs when the the counter from triangular wave is greater than the sine table point in a register. that why the frequency for SPWM is change and not fixed..
 

can you please explain it more and if you can ,please post the code of spwm 50 hz for pic18......
 

You can find details on the method here:

tahmidmc.blogspot.com/2011/01/generation-and-implementation-of-sine.html
Tahmid's blog

Hope this helps.
Tahmid.
 

great document and thanks for posting the link......
 

whats wrong with this code ..can any one help...



#include <p18cxxx.h>
#include <delays.h>

#pragma config OSC = HS /* Sets the oscillator mode to HS */
#pragma config WDT = OFF /* Turns the watchdog timer off */
#pragma config LVP = OFF /* Turns low voltage programming off */
#pragma config DEBUG = OFF /* Compiles without extra debug code */
//LCD Control pins




const unsigned char sinetable[10] = {0,77,147,202,237,250,237,202,147,77};
int i=0;




void main(void)
{
TRISC=0xFB;
LATC=0;

CCP1CON=0x0C;
PR2=234;
T2CON=0x00;

while(1)
{
i=0;


for(i=0; i < 10; i++)
{
CCPR1L= sinetable;
TMR2=0x0;
PIR1bits.TMR2IF=0;
T2CONbits.TMR2ON=1;
while(PIR1bits.TMR2IF ==0);
}
}
}
 

hi.....i am new here. i want to make SPWM by comparing a sinusoidal wave with a triangle wave. the sine wave should be external which will come from grid by voltage transformer. i already make the ADC program for for that sine wave and i got the digital value. Now i want to make a triangle wave and then want to compare with that digital value. I want to make the triangle wave by using counter. Is it possible to make the triangle wave of 16kHz and then compare with that digital value? I dont want to use DAC because i don't need the analog triangle. I just want to compare with two digital values and want to get a pulse. can anybody give the program for triangle wave using counter.

monir
 

hi.....i am new here. i want to make SPWM by comparing a sinusoidal wave with a triangle wave. the sine wave should be external which will come from grid by voltage transformer. i already make the ADC program for for that sine wave and i got the digital value. Now i want to make a triangle wave and then want to compare with that digital value. I want to make the triangle wave by using counter. Is it possible to make the triangle wave of 16kHz and then compare with that digital value? I dont want to use DAC because i don't need the analog triangle. I just want to compare with two digital values and want to get a pulse. can anybody give the program for triangle wave using counter.

monir

If you're using a microcontroller, you don't need to go through all this hassle. You can just generate the SPWM signals digitally. Use the PWM module of the microcontroller to generate the SPWM signals.

Hope this helps.
Tahmid.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top