styx1.618
Junior Member level 3
- Joined
- Oct 1, 2011
- Messages
- 27
- Helped
- 2
- Reputation
- 4
- Reaction score
- 2
- Trophy points
- 1,283
- Activity points
- 1,492
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Hello Tahmid may I have the codes in CCS C compiler which control the H-Bridge of MOSFET at high frequency in order to make a switched Mode DC-AC Converter?
For those applications of DC-AC Converters with PIC where does the 50Hz/60Hz of the output comes from? Because the H-Bridge is controlled at high frequency?
I read your blogs on :**broken link removed** and on **broken link removed** but I am not getting well the point perhaps I have to take more time.
So please can you help on the control of H-Bridge with those Sinusoidal signals,I have PIC16F1827 or PIC16F876A which I have to use for the purpose.The transformer I am suing is the high frequency transformer.
Thanks.
Regarding frequency and any other doubts, you should get your answers here: https://tahmidmc.blogspot.com/2013/02/demystifying-use-of-table-pointer-in.html
I don't use CCS C. All the codes are in mikroC. For someone who uses CCS C, the conversion shouldn't be too difficult. Feel free to ask if there's any doubt in the mikroC codes or statements.
Hope this helps.
Tahmid.
Dear Tahmid,is it possible that I can make modifications for using PIC16F1827 for this SPWM generation for my H-bridge?With the datasheet I saw that 16F1827 has only 2 ECCP modules (are those enough?),if I use 16f876A so I have to use the syntax you use on https://http://tahmidmc.blogspot.com/2013/02/generation-of-sine-wave-without-eccp_16.html
I am using a quartz of 4Mhz,this will not affect the calculations?
Where will I change if I want to use 30Khz for example and then found 50Hz at the output?
Thanks.
unsigned char sin_table[32]={0, 25, 50, 75, 99, 121, 143, 163, 181,
198, 212, 224, 234, 242, 247, 250, 250, 247, 242, 234, 224, 212, 198,
181, 163, 143, 121, 99, 75, 50, 25,0};
unsigned int TBL_POINTER_NEW, TBL_POINTER_OLD, TBL_POINTER_SHIFT, SET_FREQ;
unsigned int TBL_temp;
unsigned char DUTY_CYCLE;
sbit MOSA at Rb0_bit;//with PIC16F876A
sbit MOSB at Rb1_bit;//with PIC16F876A
sbit MOSC at Rb2_bit;//with PIC16F876A
sbit MOSD at Rb3_bit; //with PIC16F876A
unsigned char FlagReg;
sbit Direction at FlagReg.B0;
//0 -> MOS A + D
//1 -> MOS B + C
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
if (Direction == 0){
MOSA = 0;
MOSD = 0;
MOSB = 1;
MOSC = 1;
Direction = 1;
}
else{
MOSB = 0;
MOSC = 0;
MOSA = 1;
MOSD = 1;
Direction = 0;
}
}
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;
//SET_FREQ = 430;
PORTB = 0;
TRISB = 0;
//PR2 = 249; // 16kHz
PR2=49; //for 20KHz
//PR2=55; for 18KHz Generation
CCPR1L = 0;
CCP1CON = 12; //PWM mode
TRISC = 0xFF;
TMR2IF_bit = 0;
T2CON = 0x04; //TMR2 on
while (TMR2IF_bit == 0);
TMR2IF_bit = 0; //Clear TMR2IF
PORTC = 0;
TRISC = 0;
TMR2IE_bit = 1;
GIE_bit = 1;
PEIE_bit = 1;
while (1);
}
unsigned char sin_table[32]={0,25,49,73,96,118,137,
159,177,193,208,220,231,239,245,249,250,249,245,
239,231,220,208,193,177,159,137,118,96,73,49,25};
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 = 512;
TBL_POINTER_SHIFT = 0;
TBL_POINTER_NEW = 0;
TBL_POINTER_OLD = 0;
DUTY_CYCLE = 0;
PR2=187; ///for 16Khz at 12MHZ of quartz
TRISB=0x00;
CCP1CON=0x4D; //Configuration for PWM out on P1A,P1B,P1C,P1D
TMR2IF_bit = 0;
T2CON = 4; //TMR2 on, prescaler and postscaler 1:1
while (TMR2IF_bit == 0);
TMR2IF_bit = 0;
TRISB=0;
TMR2IE_bit = 1;
GIE_bit = 1;
PEIE_bit = 1;
while(1);
}
Hello Tahmid here are the codes I want to use with 16f1827 but I am not succeeding about the frequencies,can you please help me for calculations?and explain I read your blog I followed the calculations overs there but I am getting nothing new.Regarding frequency and any other doubts, you should get your answers here: https://tahmidmc.blogspot.com/2013/02/demystifying-use-of-table-pointer-in.html
I don't use CCS C. All the codes are in mikroC. For someone who uses CCS C, the conversion shouldn't be too difficult. Feel free to ask if there's any doubt in the mikroC codes or statements.
Hope this helps.
Tahmid.
unsigned char sin_table[32]={0,25,49,73,96,118,137,
159,177,193,208,220,231,239,245,249,250,249,245,
239,231,220,208,193,177,159,137,118,96,73,49,25};
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;
//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);
}
I'm getting the right frequency - 50Hz.
What are you getting?