Can you tell me how you are generating the SPWM;I used the same topology but me I want to use the guidance of Tahmid blog;unfortunately I don't understand how the sine table is designed and the value he called SET_FREQ;can you please help me on that signal generation.
For your information I saw that Tahmid used two signlas of 50Hz and generate the carrier signal which is a bit high comparing to the 50Hz he generated.
Consider the following links:https://tahmidmc.blogspot.com/2012/10/generation-of-sine-wave-using-spwm-in_10.html;https://tahmidmc.blogspot.com/2013/02/demystifying-use-of-table-pointer-in.html.
Please help on those calculations and consider the links provided for knowing how you connect diferents signals I think
on low side you might connect the carriers and high side you connect the two signals of 50Hz.
Thanks.
unsigned char sin_table[64]={0, 10, 21, 31, 41, 50, 59, 68, 76, 83, 89,
94, 99, 102, 105, 106, 107, 106, 105, 102, 99, 94, 89, 83, 76, 68, 59,
50, 41, 31, 21, 10};
unsigned int TBL_POINTER_NEW, TBL_POINTER_OLD, TBL_POINTER_SHIFT, SET_FREQ;
unsigned int TBL_temp;
unsigned char DUTY_CYCLE;
void interrupt(){
if (TMR2IF_bit == 1){
TBL_POINTER_NEW = TBL_POINTER_OLD + SET_FREQ;
if (TBL_POINTER_NEW < TBL_POINTER_OLD){
CCP1CON.P1M1 = ~CCP1CON.P1M1; //Reverse direction of full-bridge
}
TBL_POINTER_SHIFT = TBL_POINTER_NEW >> 10;
DUTY_CYCLE = TBL_POINTER_SHIFT;
CCPR1L = sin_table[DUTY_CYCLE];
TBL_POINTER_OLD = TBL_POINTER_NEW;
TMR2IF_bit = 0;
}
}
void main() {
SET_FREQ = 256;
TBL_POINTER_SHIFT = 0;
TBL_POINTER_NEW = 0;
TBL_POINTER_OLD = 0;
DUTY_CYCLE = 0;
//ANSEL = 0; //Disable ADC commenetd myself
// CMCON0 = 7; //Disable Comparator commenetd myself
//PR2 = 249;
PR2=187; ///for 16Khz at 12MHZ of quartz
// TRISC = 0x3F; commenetd myself
TRISB=0x3F;//defined myself for PWM output pins
CCP1CON = 0x4C;
TMR2IF_bit = 0;
T2CON = 4; //TMR2 on, prescaler and postscaler 1:1
while (TMR2IF_bit == 0);
TMR2IF_bit = 0;
TRISB=0; //defined my self for PWM out
// TRISC = 0; commenetd myself the PIC doesn't have portc
TMR2IE_bit = 1;
GIE_bit = 1;
PEIE_bit = 1;
while(1);
}
Yeah,this one I understand but when implementing I get wrong signals,why?
For example help me to design an H_Bridge controlling signal as Tahmid did with two terminals at 50Hz and two others at 18KHz for example tell me the following values in the sine table and let me know how you found them:
1.SET_FREQ=?
2.Number of sign table digits ;are they 32,64 or what?How many?
3.TBL_POINTER_SHIFT = TBL_POINTER_NEW >>?
Thanks you for example see what I did here below but I am getting wrong signal:PHP:unsigned char sin_table[64]={0, 10, 21, 31, 41, 50, 59, 68, 76, 83, 89, 94, 99, 102, 105, 106, 107, 106, 105, 102, 99, 94, 89, 83, 76, 68, 59, 50, 41, 31, 21, 10}; unsigned int TBL_POINTER_NEW, TBL_POINTER_OLD, TBL_POINTER_SHIFT, SET_FREQ; unsigned int TBL_temp; unsigned char DUTY_CYCLE; void interrupt(){ if (TMR2IF_bit == 1){ TBL_POINTER_NEW = TBL_POINTER_OLD + SET_FREQ; if (TBL_POINTER_NEW < TBL_POINTER_OLD){ CCP1CON.P1M1 = ~CCP1CON.P1M1; //Reverse direction of full-bridge } TBL_POINTER_SHIFT = TBL_POINTER_NEW >> 10; DUTY_CYCLE = TBL_POINTER_SHIFT; CCPR1L = sin_table[DUTY_CYCLE]; TBL_POINTER_OLD = TBL_POINTER_NEW; TMR2IF_bit = 0; } } void main() { SET_FREQ = 256; TBL_POINTER_SHIFT = 0; TBL_POINTER_NEW = 0; TBL_POINTER_OLD = 0; DUTY_CYCLE = 0; //ANSEL = 0; //Disable ADC commenetd myself // CMCON0 = 7; //Disable Comparator commenetd myself //PR2 = 249; PR2=187; ///for 16Khz at 12MHZ of quartz // TRISC = 0x3F; commenetd myself TRISB=0x3F;//defined myself for PWM output pins CCP1CON = 0x4C; TMR2IF_bit = 0; T2CON = 4; //TMR2 on, prescaler and postscaler 1:1 while (TMR2IF_bit == 0); TMR2IF_bit = 0; TRISB=0; //defined my self for PWM out // TRISC = 0; commenetd myself the PIC doesn't have portc TMR2IE_bit = 1; GIE_bit = 1; PEIE_bit = 1; while(1); }
Please help.Thanks.
- - - Updated - - -
Hello ratheeshvaram@yahoo.com,can you please help me to calculate the good values,because with the formula you provided I am getting wrong signal.
see the graphs on the attachment I am getting with my oscilloscope ,those are the output of The MOSFET Drive IC7667.!!
Please help
unsigned char sin_table[32]={0, 10, 21, 31, 41, 50, 59, 68, 76, 83, 89,
94, 99, 102, 105, 106, 107, 106, 105, 102, 99, 94, 89, 83, 76, 68, 59,
50, 41, 31, 21, 10};
unsigned int TBL_POINTER_NEW, TBL_POINTER_OLD, TBL_POINTER_SHIFT, SET_FREQ;
unsigned int TBL_temp;
unsigned char DUTY_CYCLE;
void interrupt(){
if (TMR2IF_bit == 1){
TBL_POINTER_NEW = TBL_POINTER_OLD + SET_FREQ;
if (TBL_POINTER_NEW < TBL_POINTER_OLD){
CCP1CON.P1M1 = ~CCP1CON.P1M1; //Reverse direction of full-bridge
}
TBL_POINTER_SHIFT = TBL_POINTER_NEW >> 11;
DUTY_CYCLE = TBL_POINTER_SHIFT;
CCPR1L = sin_table[DUTY_CYCLE];
TBL_POINTER_OLD = TBL_POINTER_NEW;
TMR2IF_bit = 0;
}
}
void main() {
SET_FREQ = 410;
TBL_POINTER_SHIFT = 0;
TBL_POINTER_NEW = 0;
TBL_POINTER_OLD = 0;
DUTY_CYCLE = 0;
PR2=107; ///for 28Khz at 12MHZ of quartz
TRISB=0x3F;//defined myself for PWM output pins
CCP1CON = 0x4C;
TMR2IF_bit = 0;
T2CON = 4; //TMR2 on, prescaler and postscaler 1:1
while (TMR2IF_bit == 0);
TMR2IF_bit = 0;
TRISB=0; //defined my self for PWM out
TMR2IE_bit = 1;
GIE_bit = 1;
PEIE_bit = 1;
while(1);
}
#include "16f1827.h"
//#device ADC=8
#fuses NOWDT,HS,NODEBUG,NOCPD,PUT,NOLVP
#use delay(clock=4000000)
void main()
{
set_tris_b(0x00);
output_b(0x00);
while(1)
{
/*output_high(PIN_B5);
output_low(PIN_B4);
delay_us(40);
*/
output_high(PIN_B3);
output_high(PIN_B7);
output_low(PIN_B5);
output_low(PIN_B6);
delay_ms(20);
output_low(PIN_B3);
output_low(PIN_B7);
output_low(PIN_B5);
output_low(PIN_B6);
delay_us(5);
output_low(PIN_B3);
output_low(PIN_B7);
output_high(PIN_B5);
output_high(PIN_B6);
delay_ms(20);
output_low(PIN_B3);
output_low(PIN_B7);
output_low(PIN_B5);
output_low(PIN_B6);
delay_us(5);
/*
output_low(PIN_B5);
output_low(PIN_B4);
delay_us(5); //it was 5us
output_low(PIN_B5);
output_high(PIN_B4);
delay_us(40);
output_low(PIN_B5);
output_low(PIN_B4);
delay_us(5); //it was 5us
*/
}
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?