This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AC Drive with TIVA

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);

	}
}

  •  Hi, at first glance it cannot work,

    first initialization code must be out of while(1) loop

    some form of wait is necessary on last instruction of superloop

    is interrupt sync on gpio4 correctly served? I fear NO due to this main loop and other wrong assumption.

     Best practice is to capture to a free running counter pulse of main zero crossing then adjust the phase of thyristor firing to correct phase.

     IMHO your code is free running @ processor speed / loop clock    and never can get in sync with zero cross...

  • Thank you Mr roberto,

    You mean to say i should not use PWM and instead of that i should use GPIO for the gate pulse generation and TIMER for the duty cycle generation. If i am not wrong.

    And what are you saying about gpio4 interrupt sync? I am not able to catch it. Please explain me where I am going wrong. 

    Thank you for your kind support.

  •  No, I saw your code is wrong, please remove from while(1) all code initializing pheripheral and move it before to execute just one time.

     Check with debugger if GPIO routine get served.

    never execute initiatio ìn mìin a loop