Jump to content
Sign in to follow this  

Sine Wave Drive Full Bridge Inverter Circuit

Recommended Posts

I need to finish a program before I graduate. And I wrote one. However SIMULATOR displayed PWM CLOCK FASTER THAN FOSC When debugging. I cant found troubles. My code is given below. Hope someoone here can help me !

The datasheet of DSPIC30F2020

#include <p30F2020.h>
_FOSCSEL(FRC_PLL); //enable PLL,FRC crystal oscillator
_FOSC(CSW_FSCM_OFF&FRC_HI_RANGE); //ban clock to switch,High frequency mode
_FPOR(PWRT_128);//power on reset128MS
_FWDT(FWDTEN_OFF); //The watchdog timer is prohibited 
_FGS(CODE_PROT_OFF);//Code protection closed

unsigned int const pwmtab[200] = {0,631,1262,1892,2522,3152,3781,4409,5035,5661,6285,6908,7528,8147,8764,9379,
unsigned char num; //Look-up table order register
unsigned char sign; //Sine table output symbol
float  sin_l;
void PortInit()  
   // LATE= 0x0000;  // E pot reset 
    TRISE = 0x0000; //set E pot to output , 0: out, 1: in 
    TRISB = 0x0000; //set E pot to output, 0: out, 1: in 
    PORTE = 0x0000;  
    PORTB = 0x0000;  
    OSCCONbits.TSEQEN=0;//OSCTUN  TUN<3:0> in register adjust FRC oscillator
    OSCTUNbits.TUN = 0111; /* FRC时钟为15M */ 

void PWM_Config() 

FCLCON1=0X0003; // Disable the current limit and fault type

IOCON1bits.PENH = 1; /* PWM1H PWM module will control PWM output pin */ 

IOCON1bits.PENL = 1; /* PWM1L PWM module will control PWM output pin */ 

IOCON1bits.PMOD = 00; /* Complementary output mode */ 

IOCON1bits.POLH = 0; //Effective if PWMxH pin is high level

IOCON1bits.POLL = 0; /Effective if PWMxL pin is high leve

/* Load PDTR1 and ALTDTR2 register with preset dead time value */ 
DTR1 = 64; /* Dead band time Settings */ 

ALTDTR1 = 64; /* dead time */ 

/* PHASE1 register */ 
PHASE1 = 0; /* No phase shift */ 

/* PWM Time Base Control Register */ 
PTCONbits.PTEN = 1; // enable PWM module
PTCONbits.EIPU = 1; /Register/update immediately effective cycle 
PWMCON1bits.IUE = 1; //Update immediately effective pdc register
PWMCON1bits.MDCS = 0;//PDC provide duty ratio

    PTPER = 47620; //30mips为47620 ,cycle=(PTPER+1)/120MHZ 
    PDC1 = 0; //Duty ratio reset

     _PWM1IE=1;//Allow the interrupt request
_PWM1IF=0;//Interrupt flag reset
  _PWM1IP=6;    //set interrupt priority level to be 6
  _IPL=1;//CPU interrupt priority level is 1

int main() 

    num = 0;        // A variable initialization
sign = 0; 
PortInit() ;
while(1);//Have been circulating wait for interrupt

void __attribute__((interrupt, no_auto_psv)) _PWM1Interrupt(void)
      _PWM1IF=0;//Interrupt flag bit reset
    if (!num)        /fi num=0,mean that every sign invert the look-up table cycle, used to determine the positive and negative half cycle waveform      

  sign = ~sign; //0 to be 1
    ++num;        // Sine table order value
  if (num>=200)        //reset num after checking 200 pots
num = 0; 
    sin_l= pwmtab[num];
    PDC1=(unsigned char)sin_l;//The assignment
                                      {PORTBbits.RB5=0;}// reversing




Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...