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.

Implementation of a three phase VFD with PIC16F1937

Status
Not open for further replies.

jean12

Advanced Member level 2
Joined
Aug 27, 2013
Messages
529
Helped
5
Reputation
12
Reaction score
6
Trophy points
18
Activity points
5,497
Hello,I would like to implement a VFD with PIC16F1937 and mainly IR21362 and Power MOSFET ,could you please help me to deal with those Codes,I made a 120degrees phase shift but the capabilities of making the frequency and amplitude adjustable remain difficult for me,please help,find the codes here below:

PHP:
#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() {


    SET_FREQ=171;
    T2CON = 0x0C;
    PR2 = 249;
    TMR2IE_bit = 1;
    INTCON = 0xC0;

     Delay_ms(2);
     APFCON = 0x00;
     ADCON1 = 0X20;
     ADCON0=0X19;
     delay_us(20);
     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 
    
        ADCON0.ADIF=0;
     //while(ADIF==0)
     
     ADCON0.ADIF=0;
     ADCON0.ADIE=1;
     PIE1.ADIE=1;
     INTCON.GIE=1;
     INTCON.PEIE=1;
     delay_us(20);
    // ADCON0.F2=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;
          }
     }
 

Hello,I would like to implement a VFD with PIC16F1937 and mainly IR21362 and Power MOSFET ,could you please help me to deal with those Codes,I made a 120degrees phase shift but the capabilities of making the frequency and amplitude adjustable remain difficult for me,please help,find the codes here below:

PHP:
#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() {


    SET_FREQ=171;
    T2CON = 0x0C;
    PR2 = 249;
    TMR2IE_bit = 1;
    INTCON = 0xC0;

     Delay_ms(2);
     APFCON = 0x00;
     ADCON1 = 0X20;
     ADCON0=0X19;
     delay_us(20);
     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 
    
        ADCON0.ADIF=0;
     //while(ADIF==0)
     
     ADCON0.ADIF=0;
     ADCON0.ADIE=1;
     PIE1.ADIE=1;
     INTCON.GIE=1;
     INTCON.PEIE=1;
     delay_us(20);
    // ADCON0.F2=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;
          }
     }

Attached here is the screenshot of simulation of the three phase signals on which I want the potentiometer to act upon.

Please help.
 

Attachments

  • Simulation Screenshot 3.png
    Simulation Screenshot 3.png
    139.9 KB · Views: 103

To change frequency you have to change timebase for timer2.
To change amplitude you have to shift PWM value to some bits right for example to reduce duty cycle for 2, 4, 8 and e.t.c. times.
 

Dea Easyder83,could you help me with the above codes and implement what you advised with working codes?

Thx
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top