Hello everybody,I would like to control the frequency of my Three Phase DC-AC Inverter with the variable frequency so that the VFD can be implemented using PIC16F1937,I have the codes here in attachment I tried to implement the adc reading capability with interrupts but I am not coming at the stage where the frequency can be variable,I want it to be adjustable with the voltage at the output of the three phase DC-AC Inverter.Please could you help?so that the frequency and amplitude changes proportionally with my PIC here,I am using the IR21362 so that I need the output at P1A,P2A and P3A of the PIC which through the driver IR21362 gives the complete cycle (360degrees for each phase).
Codes
Thanks
Moderators note: please use code tags for pices of code
Codes
C:
#define NUMBER_OF_TABLE_ENTRIES_FOR_180_DEGREES 64
#define FACTOR_TO_GET_360_DEGREES
char i = 0;
double value_adc;
unsigned int sin_table[64] = {125,137,149,161,173,184,194,204,
213,222,229,235,240,245,248,249,
250,249,248,245,240,235,229,222,
213,204,194,184,173,161,149,137,
125,113,101,89,77,66,56,46,
37,28,21,15,10,5,2,1,
0,1,2,5,10,15,21,28,
37,46,56,66,77,89,101,113
};
unsigned int TBL_POINTER_NEW[3], TBL_POINTER_OLD[3], TBL_POINTER_SHIFT[3], SET_FREQ = 0;
unsigned int ADC_VAL = 0, PREV_ADC_VAL = 0;
char DUTY_CYCLE[3];
//Timer2
//Prescaler 1:1; Postscaler 1:2; TMR2 Preload = 249; Actual Interrupt Time : 100 us
//Place/Copy this part in declaration section
void InitTimer2() {
T2CON = 0x0C;
PR2 = 249;
TMR2IE_bit = 1;
INTCON = 0xC0;
}
void interrupt()
{
if(TMR2IF_bit==1) {
TBL_POINTER_NEW[0] = TBL_POINTER_OLD[0] + SET_FREQ;
if (TBL_POINTER_NEW[0] < TBL_POINTER_OLD[0]) {
CCP1CON.P1M1 = ~CCP1CON.P1M1;
}
TBL_POINTER_SHIFT[0] = TBL_POINTER_NEW[0] >> 10;
DUTY_CYCLE[0] = TBL_POINTER_SHIFT[0]*value_adc; //check this for multiplicity of value with read data from potentiometet
CCPR1L = sin_table[DUTY_CYCLE[0]];
TBL_POINTER_OLD[0] = TBL_POINTER_NEW[0];
// Phase2
TBL_POINTER_NEW[1] = TBL_POINTER_OLD[1] + SET_FREQ;
if (TBL_POINTER_NEW[1] < TBL_POINTER_OLD[1]){
CCP2CON.P2M1 = ~CCP2CON.P2M1;
}
TBL_POINTER_SHIFT[1] = TBL_POINTER_NEW[1] >> 10;
DUTY_CYCLE[1] = TBL_POINTER_SHIFT[1]*value_adc;
if((DUTY_CYCLE[1] + 42) < 64)DUTY_CYCLE[1] += 42;
else DUTY_CYCLE[1] -= 22;
CCPR2L = sin_table[DUTY_CYCLE[1]];
TBL_POINTER_OLD[1] = TBL_POINTER_NEW[1];
//Phase 3
TBL_POINTER_NEW[2] = TBL_POINTER_OLD[2] + SET_FREQ;
if (TBL_POINTER_NEW[2] < TBL_POINTER_OLD[2]) {
CCP3CON.P3M1 = ~CCP3CON.P3M1;
}
TBL_POINTER_SHIFT[2] = TBL_POINTER_NEW[2] >> 10;
DUTY_CYCLE[2] = TBL_POINTER_SHIFT[2]*value_adc;
if((DUTY_CYCLE[2] + 21) < 64)DUTY_CYCLE[2] += 21;
else DUTY_CYCLE[2] -= 43;
CCPR3L = sin_table[DUTY_CYCLE[2]];
TBL_POINTER_OLD[2] = TBL_POINTER_NEW[2];
TMR2IF_bit = 0;
}
}
//Interrupt for ADC Value recording ,reading the
void interrupt_ADC()
{
if(ADIF_bit==1)
{
value_adc=ADRESH;
//value_adc=ADRESL;
ADIF_bit=0;
}
}
void main() {
Delay_ms(2);
APFCON = 0x00;
ADCON1 = 0X20;
ADCON0=0X19;
delay_ms(2);
ADCON0.GO=1;
FVRCON = 0x00;
ANSELA =0X3F;
LATA=0X00;
CM1CON0 = 0x00;
CM2CON0 = 0x00;
TRISA = 0x01;
TRISB = 0xDF;
TRISC = 0xF9;
PORTB = 0x00;
PORTC = 0x00;
LATA = 0x00;
//Initiailization ADC reading modules
ADIF_bit=0;
while(ADIF==0)
ADIF_bit=0;
ADIE_bIT=1;
GIE_bit=1;
PEIE_bit=1;
ADC_Init();
//loop for cycles repeating
for(i = 0; i < 3; i++)
{
TBL_POINTER_SHIFT[I] = 0;
TBL_POINTER_NEW[I] = 0;
TBL_POINTER_OLD[I] = 0;
DUTY_CYCLE[I] = 0;
}
PWM1_Init(10000);
PWM2_Init(10000);
PWM3_Init(10000);
PWM1_Set_Duty(0);
PWM2_Set_Duty(0);
PWM3_Set_Duty(0);
PWM1_Start();
PWM2_Start();
PWM3_Start();
InitTimer2();
while(1)
{
ADC_VAL=value_adc;
SET_FREQ=171;
}
}
Thanks
Moderators note: please use code tags for pices of code
Last edited by a moderator: