bengun
Joined: 13 Apr 2010 Posts: 1
|
3 phase sinusoidal PWM using 18F4431 |
Posted: Thu Apr 15, 2010 12:48 am |
|
|
Anybody can help me in programming the power pwm pins?
I write this code example for one phase:
Code: |
/*
3 channels power PWM for 3 phase sinewave
*/
#include<18F4431.h>
#use delay(clock=8M)
#define POWER_PWM_PERIOD 3332 // 0.6 KHz pwm freq with 8 MHz osc.
int i=0;
///////////////////////////// SIN table ////////////////////////////////
int16 A[6]={1666,2886,3330,3330,2886,1666};
#int_PWMTB
void PWMTB()
{
///////////////////// power PWM0 for phase 1 ///////////////////////
if(i<6) /////////////////////////////// 1st half period
set_power_pwm0_duty(4*A[i]);
else ////////////////////////////////2nd half period
set_power_pwm0_duty(4*3332-4*A[i-6]);
i++;
if(i==12) i=0;
clear_interrupt(int_PWMTB);
}
void main()
{
enable_interrupts(GLOBAL);
enable_interrupts(INT_PWMTB);
setup_power_pwm_pins(PWM_COMPLEMENTARY ,PWM_OFF,PWM_OFF,PWM_OFF);
setup_power_pwm(PWM_FREE_RUN, 1, 0, POWER_PWM_PERIOD, 0, 1,0);
for(;;);
}
|
My purpose is to complement the pwm signal generated by PWM1 pin in the second period.
In case of second period: I must see the duty cycle at the end of pwm period not in the first (FREE_RUN_MODE generate it at the beginning of PWM pulse).
If I apply this method for 3 phase full bridge inverter, this may cause damage in transistors of the same leg, since for a while they are both ON.
Please if there is a solution in program tell me. |
|