Hii,
I am making a AC drive with the help of TIVA launchpad. Its a single phase experiment. And the concept is to fire a thyristor by PWM with getting synchronised with zero crossing pulses which we get from the supply given to thyristor.
My code is attached here. The problem is, Line frequency is varying and my PWM frequency is set at 50 Hz (Indian Power supply). So my output voltage is being periodic. First its coming high. Than coming down to zero. It will stay zero for sometime and than again coe to high and cycle goes on.
It seems like mismatch in the frequency. Please help me on this issue.
Thank you.
#include <stdbool.h> #include <stdint.h> #include "inc/hw_ints.h" #include "inc/hw_memmap.h" #include "driverlib/gpio.h" #include "driverlib/pin_map.h" #include "driverlib/pwm.h" #include "driverlib/interrupt.h" #include "driverlib/sysctl.h" void gpio_pin_int(void) { uint32_t freq1; freq1=(8*PWMGenPeriodGet(PWM0_BASE,PWM_OUT_0))/10; GPIOIntClear(GPIO_PORTF_BASE,GPIO_PIN_4); PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0,freq1); PWMOutputState(PWM0_BASE,PWM_OUT_0_BIT|PWM_OUT_1_BIT, true); PWMGenEnable(PWM0_BASE, PWM_GEN_0); GPIOIntEnable(GPIO_PORTF_BASE,GPIO_PIN_4); } void PWM_INT_HAND(void) { PWMGenIntClear(PWM0_BASE,PWM_GEN_0,PWM_INT_CNT_ZERO); PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2,(2*PWMGenPeriodGet(PWM0_BASE,PWM_OUT_0))/10); PWMOutputState(PWM0_BASE,PWM_OUT_2_BIT, true); PWMOutputInvert(PWM0_BASE,PWM_OUT_2_BIT,true); PWMGenEnable(PWM0_BASE, PWM_GEN_1); } //***************************************************************************** //***************************************************************************** int main(void) { uint32_t freq; while(1) { SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); SysCtlPWMClockSet(SYSCTL_PWMDIV_32); SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // for input pins gpio GPIOPinConfigure(GPIO_PB6_M0PWM0); GPIOPinConfigure(GPIO_PB7_M0PWM1); GPIOPinConfigure(GPIO_PB4_M0PWM2); GPIOPinTypeGPIOInput(GPIO_PORTF_BASE,GPIO_PIN_4); GPIOIntRegister(GPIO_PORTF_BASE,gpio_pin_int); GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_4,GPIO_RISING_EDGE); GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_6); GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_7); GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_4); PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN |PWM_GEN_MODE_NO_SYNC); PWMGenConfigure(PWM0_BASE, PWM_GEN_1, PWM_GEN_MODE_UP_DOWN |PWM_GEN_MODE_NO_SYNC); freq= (100*(SysCtlClockGet()/32)/5000); PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, freq); PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, freq); IntMasterEnable(); PWMIntEnable(PWM0_BASE, PWM_INT_GEN_0); PWMGenIntTrigEnable(PWM0_BASE, PWM_GEN_0, PWM_INT_CNT_ZERO); IntEnable(INT_PWM0_0); GPIOIntEnable(GPIO_PORTF_BASE,GPIO_PIN_4); } }