Rickooo
Member level 3
Hi, If you wants to see wave using scope, I can show you. I don't have pcb with me today. I can show you tomorrow.Hi.
You want us to help. For this you need to provide information.
Did you read post#8? Show us the according scope pictures.
You tell it is 16kHz PWM. Maybe I'm wrong but I still see 400kHz. Please tell me how I can verify it is 16kHz.
Klaus
For 16kHz, I am using PIC controller to generate SPWM of 400Hz with switching frequency 16kHz. I used https://tahmidmc.blogspot.com/2012/10/generation-of-sine-wave-using-spwm-in_10.html blog to get the required wave.
Code:
#include <xc.h>
#define _XTAL_FREQ 20000000
unsigned char sin_table[25]={0,2,4,7,9,11,12,14,15,16,17,18,18,18,18,17,16,15,14,12,11,9,7,4,2};
unsigned int TBL_POINTER_NEW, TBL_POINTER_OLD, TBL_POINTER_SHIFT, SET_FREQ;
unsigned int TBL_temp;
unsigned char DUTY_CYCLE;
void interrupt tc_int (void){
if (PIR1bits.TMR2IF == 1){
TBL_POINTER_NEW = TBL_POINTER_OLD + SET_FREQ;
if (TBL_POINTER_NEW < TBL_POINTER_OLD){
CCP1CONbits.P1M1 = ~CCP1CONbits.P1M1; //Reverse direction of full-bridge
}
TBL_POINTER_SHIFT = TBL_POINTER_NEW >> 12;
DUTY_CYCLE = TBL_POINTER_SHIFT;
CCPR1L = sin_table[DUTY_CYCLE];
TBL_POINTER_OLD = TBL_POINTER_NEW;
PIR1bits.TMR2IF = 0;
}
}
void main() {
SET_FREQ = 205;
TBL_POINTER_SHIFT = 0;
TBL_POINTER_NEW = 0;
TBL_POINTER_OLD = 0;
DUTY_CYCLE = 0;
ANSEL = 0; //Disable ADC
CMCON0 = 7; //Disable Comparator
PR2 = 24;
TRISC = 0x3F;
CCP1CON = 0x4C;
PIR1bits.TMR2IF = 0;
T2CON = 4; //TMR2 on, prescaler and postscaler 1:1
while (PIR1bits.TMR2IF == 0);
PIR1bits.TMR2IF = 0;
TRISC = 0;
PIE1bits.TMR2IE = 1;
INTCONbits.GIE = 1;
INTCONbits.PEIE = 1;
while(1);
}
This is the code I have used
Last edited by a moderator: