Hi Ti Team,
We are facing an issue in ePWm. we are using all 12 ePWM's with channel A & channel B both. These ePWM's are connected to control steeper motors. So in our sequence we are suppose to run multiple motors simultaneously according to the sequence. After 12 sequence all of a sudden ePWM stops working(If started then it is not stopping and vice versa).
Regards,
Ambarish BH
please follow below source code of pwm.c file for your reference.
#include "CAHeaderFiles.h"
extern volatile int nReactionTrayPitchsensorFlag;
extern volatile unsigned char ucCapacitanceSenseFlag;
/********************************************************************************/
/*!
* \struct EPWM_REGS
*/
/********************************************************************************/
volatile struct EPWM_REGS *ePWM[12] =
{ &EPwm1Regs, &EPwm2Regs, &EPwm3Regs, &EPwm4Regs, &EPwm5Regs, &EPwm6Regs,&EPwm7Regs, &EPwm8Regs,&EPwm9Regs,&EPwm10Regs,&EPwm11Regs,&EPwm12Regs };
/********************************************************************************/
/*!
* \fn : void Initialize_PWM(void)
* \brief : Initialize 12 pwm engines
* \brief Description: This function initialize the pwm isr and intervector table
* Configures pwm engine and period
* Configures all ePWM channels and sets up PWM
* \return : void
*/
/********************************************************************************/
void Initialize_PWM(void)
{
// InitEPwmGpio(); //epwms gpio pin configuration is different for
//epwm9 to epwm12, so this default function is commented
//and following functions are called for epwm configuration
InitEPwm1Gpio();
InitEPwm2Gpio();
InitEPwm3Gpio();
InitEPwm4Gpio();
InitEPwm5Gpio();
InitEPwm6Gpio();
InitEPwm7Gpio();
InitEPwm8Gpio();
InitEPwm9To12(); //change GPIO pin configuration as per requirement
//for epwm9 to epwm12 & initialize epwm 9 to epwm12
// Interrupts that are used in this example are re-mapped to
// ISR functions found within this file.
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.EPWM1_INT = &epwm1_isr;
PieVectTable.EPWM2_INT = &epwm2_isr;
PieVectTable.EPWM3_INT = &epwm3_isr;
PieVectTable.EPWM4_INT = &epwm4_isr;
PieVectTable.EPWM5_INT = &epwm5_isr;
PieVectTable.EPWM6_INT = &epwm6_isr;
PieVectTable.EPWM7_INT = &epwm7_isr;
PieVectTable.EPWM8_INT = &epwm8_isr;
PieVectTable.EPWM9_INT = &epwm9_isr;
PieVectTable.EPWM10_INT = &epwm10_isr;
PieVectTable.EPWM11_INT = &epwm11_isr;
PieVectTable.EPWM12_INT = &epwm12_isr;
EDIS; //This is needed to disable write to EALLOW protected registers
EALLOW;
CpuSysRegs.PCLKCR0.bit.TBCLKSYNC =0;
EDIS;
ConfigPWM(0, 1);
ConfigPWM(1, 1);
ConfigPWM(2, 1);
ConfigPWM(3, 1);
ConfigPWM(4, 1);
ConfigPWM(5, 1);
ConfigPWM(6, 1);
ConfigPWM(7, 1);
ConfigPWM(8, 1);
ConfigPWM(9, 1);
ConfigPWM(10, 1);
ConfigPWM(11, 1);
ConfigPWMB(0, 1);
ConfigPWMB(1, 1);
ConfigPWMB(2, 1);
ConfigPWMB(3, 1);
ConfigPWMB(4, 1);
ConfigPWMB(5, 1);
ConfigPWMB(6, 1);
ConfigPWMB(7, 1);
ConfigPWMB(8, 1);
ConfigPWMB(9, 1);
ConfigPWMB(10, 1);
ConfigPWMB(11, 1);
EALLOW;
CpuSysRegs.PCLKCR0.bit.TBCLKSYNC =1;
EDIS;
// Enable CPU INT3 which is connected to EPWM1-3 INT:
IER |= M_INT3;
// Enable EPWM INTn in the PIE: Group 3 interrupt 1-3
PieCtrlRegs.PIEIER3.bit.INTx1 = 1;
PieCtrlRegs.PIEIER3.bit.INTx2 = 1;
PieCtrlRegs.PIEIER3.bit.INTx3 = 1;
PieCtrlRegs.PIEIER3.bit.INTx4 = 1;
PieCtrlRegs.PIEIER3.bit.INTx5 = 1;
PieCtrlRegs.PIEIER3.bit.INTx6 = 1;
PieCtrlRegs.PIEIER3.bit.INTx7 = 1;
PieCtrlRegs.PIEIER3.bit.INTx8 = 1;
PieCtrlRegs.PIEIER3.bit.INTx9 = 1;
PieCtrlRegs.PIEIER3.bit.INTx10 = 1;
PieCtrlRegs.PIEIER3.bit.INTx11 = 1;
PieCtrlRegs.PIEIER3.bit.INTx12 = 1;
// Enable global Interrupts and higher priority real-time debug events:
// EINT; // Enable Global interrupt INTM
// ERTM; // Enable Global realtime interrupt DBGM
}
/*****************************************************************************/
/*!
* fn : void InitEPwm9To12()
* Description: This function initializes the pwm 9 to 12
* return : void
*/
/*****************************************************************************/
void InitEPwm9To12(void)
{
EALLOW;
//Enable epwm 9A & 9B
/* Disable internal pull-up for the selected output pins
for reduced power consumption */
GpioCtrlRegs.GPAPUD.bit.GPIO16 = 1; // Disable pull-up on GPIO16 (EPWM9A)
GpioCtrlRegs.GPAPUD.bit.GPIO17 = 1; // Disable pull-up on GPIO17 (EPWM9B)
/* Configure EPWM-9 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM9 functional pins
GpioCtrlRegs.GPAGMUX2.bit.GPIO16 = 1; // Configure GPIO16 as EPWM9A
GpioCtrlRegs.GPAGMUX2.bit.GPIO17 = 1; // Configure GPIO16 as EPWM9B
GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 1; // Configure GPIO16 as EPWM9A
GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 1; // Configure GPIO16 as EPWM9B
//Enable epwm 10A & 10B
/* Disable internal pull-up for the selected output pins
for reduced power consumption */
GpioCtrlRegs.GPAPUD.bit.GPIO18 = 1; // Disable pull-up on GPIO18 (EPWM10A)
GpioCtrlRegs.GPAPUD.bit.GPIO19 = 1; // Disable pull-up on GPIO19 (EPWM10B)
/* Configure EPWM-10 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM10 functional pins
GpioCtrlRegs.GPAGMUX2.bit.GPIO18 = 1; // Configure GPIO16 as EPWM10A
GpioCtrlRegs.GPAGMUX2.bit.GPIO19 = 1; // Configure GPIO16 as EPWM10B
GpioCtrlRegs.GPAMUX2.bit.GPIO18 = 1; // Configure GPIO18 as EPWM10A
GpioCtrlRegs.GPAMUX2.bit.GPIO19 = 1; // Configure GPIO19 as EPWM10B
//Enable epwm 11A & 11B
/* Disable internal pull-up for the selected output pins
for reduced power consumption */
GpioCtrlRegs.GPAPUD.bit.GPIO20 = 1; // Disable pull-up on GPIO20 (EPWM11A)
GpioCtrlRegs.GPAPUD.bit.GPIO21 = 1; // Disable pull-up on GPIO21 (EPWM11B)
/* Configure EPWM-11 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM11 functional pins
GpioCtrlRegs.GPAGMUX2.bit.GPIO20 = 1; // Configure GPIO16 as EPWM11A
GpioCtrlRegs.GPAGMUX2.bit.GPIO21 = 1; // Configure GPIO16 as EPWM11B
GpioCtrlRegs.GPAMUX2.bit.GPIO20 = 1; // Configure GPIO20 as EPWM11A
GpioCtrlRegs.GPAMUX2.bit.GPIO21 = 1; // Configure GPIO21 as EPWM11B
//Enable epwm 11A & 11B
/* Disable internal pull-up for the selected output pins
for reduced power consumption */
GpioCtrlRegs.GPAPUD.bit.GPIO22 = 1; // Disable pull-up on GPIO22 (EPWM12A)
GpioCtrlRegs.GPAPUD.bit.GPIO23 = 1; // Disable pull-up on GPIO23 (EPWM12B)
/* Configure EPWM-12 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM12 functional pins
GpioCtrlRegs.GPAGMUX2.bit.GPIO22 = 1; // Configure GPIO16 as EPWM12A
GpioCtrlRegs.GPAGMUX2.bit.GPIO23 = 1; // Configure GPIO16 as EPWM12B
GpioCtrlRegs.GPAMUX2.bit.GPIO22 = 1; // Configure GPIO22 as EPWM12A
GpioCtrlRegs.GPAMUX2.bit.GPIO23 = 1; // Configure GPIO23 as EPWM12B
EDIS;
}
/********************************************************************************/
/*!
* \fn : void ConfigPWM(Uint16 Channel, Uint16 period)
* \param : Channel - pwm channel to be configured
* \param : period - specifies the pwm period
*
* \brief : Initialize individual pwm channels
* \brief Description: This function initialize the pwm channel registers
* Configures pwm engine and period
* Configures all ePWM channels and sets up PWM
* \return : void
*/
/********************************************************************************/
void ConfigPWM(Uint16 Channel, Uint16 period)
{
// (*ePWM[Channel]).TBCTL.bit.PRDLD = TB_SHADOW; // set Immediate load
(*ePWM[Channel]).TBCTL.bit.PRDLD = TB_IMMEDIATE; // set Immediate load TB_IMMEDIATE //modified TBD
(*ePWM[Channel]).TBPRD = period-1; // PWM frequency = 1 / period
// (*ePWM[Channel]).CMPA.bit.CMPA = period / 2; // set duty 0% initially
(*ePWM[Channel]).CMPA.bit.CMPA = 25 ; //DUTY_PERCENT_0; // set duty 0% initially
(*ePWM[Channel]).TBPHS.all = 0;
(*ePWM[Channel]).TBCTR = 0;
(*ePWM[Channel]).TBCTL.bit.CTRMODE = TB_COUNT_UP; //TB_COUNT_UP;
(*ePWM[Channel]).TBCTL.bit.PHSEN = TB_DISABLE;
(*ePWM[Channel]).TBCTL.bit.SYNCOSEL = TB_SYNC_DISABLE;
(*ePWM[Channel]).TBCTL.bit.HSPCLKDIV = 7; //PWM_TB_DIV10;
(*ePWM[Channel]).TBCTL.bit.CLKDIV = 7; // PWM_TB_DIV8;
//modified to be deleted- TBCLK value changed to 520.83kHz
// (*ePWM[Channel]).TBCTL.bit.HSPCLKDIV = 6; //PWM_TB_DIV10; //TBCLK == 55803kHZ
// (*ePWM[Channel]).TBCTL.bit.CLKDIV = 4; // PWM_TB_DIV8;
//modification ends
(*ePWM[Channel]).TBCTL.bit.FREE_SOFT = 11;
(*ePWM[Channel]).CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
(*ePWM[Channel]).CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
// (*ePWM[Channel]).CMPCTL.bit.SHDWAMODE = CC_SHADOW;
// (*ePWM[Channel]).CMPCTL.bit.SHDWBMODE = CC_SHADOW;
(*ePWM[Channel]).CMPCTL.bit.SHDWAMODE = CC_IMMEDIATE; //modified TBD
(*ePWM[Channel]).CMPCTL.bit.SHDWBMODE = CC_IMMEDIATE; //modified TBD
// (*ePWM[Channel]).AQCTLA.bit.ZRO = AQ_SET; // PWM toggle high/low
(*ePWM[Channel]).AQCTLA.bit.ZRO = AQ_CLEAR; // PWM toggle high/low //modified TBD
(*ePWM[Channel]).AQCTLA.bit.CAU = AQ_CLEAR;
// Interrupt where we will change the Compare Values
(*ePWM[Channel]).ETSEL.bit.INTSEL = ET_CTR_ZERO; // Select INT on Zero event
(*ePWM[Channel]).ETSEL.bit.INTEN = 1; // Enable INT
(*ePWM[Channel]).ETPS.bit.INTPRD = ET_1ST; //ET_3RD; 0->fist event, 1-> second event, 2-> third event // Generate INT on 3rd event
}
/********************************************************************************/
/*!
* \fn : void ConfigPWMB(Uint16 Channel, Uint16 period)
* \param : Channel - pwm channel to be configured
* \param : period - specifies the pwm period
*
* \brief : Initialize individual pwm channels
* \brief Description: This function initialize the pwm channel registers
* Configures pwm engine and period
* Configures all ePWM channels and sets up PWM
* \return : void
*/
/********************************************************************************/
void ConfigPWMB(Uint16 Channel, Uint16 period)
{
// (*ePWM[Channel]).TBCTL.bit.PRDLD = TB_SHADOW; // set Immediate load TB_IMMEDIATE
(*ePWM[Channel]).TBCTL.bit.PRDLD = TB_IMMEDIATE; // set Immediate load TB_IMMEDIATE //modified TBD
(*ePWM[Channel]).TBPRD = period-1; // PWM frequency = 1 / period
(*ePWM[Channel]).CMPB.bit.CMPB = 0 ; // set duty 0% initially
(*ePWM[Channel]).TBPHS.all = 0;
(*ePWM[Channel]).TBCTR = 0;
(*ePWM[Channel]).TBCTL.bit.CTRMODE = TB_COUNT_UP; //TB_COUNT_UP;
(*ePWM[Channel]).TBCTL.bit.PHSEN = TB_DISABLE;
(*ePWM[Channel]).TBCTL.bit.SYNCOSEL = TB_SYNC_DISABLE;
(*ePWM[Channel]).TBCTL.bit.HSPCLKDIV = 7; //PWM_TB_DIV10; //TBCLK == 55803kHZ
(*ePWM[Channel]).TBCTL.bit.CLKDIV = 7; // PWM_TB_DIV8;
//modified to be deleted- TBCLK value changed to 520.83kHz
// (*ePWM[Channel]).TBCTL.bit.HSPCLKDIV = 6; //PWM_TB_DIV10; //TBCLK == 55803kHZ
// (*ePWM[Channel]).TBCTL.bit.CLKDIV = 4; // PWM_TB_DIV8;
//modification ends
(*ePWM[Channel]).TBCTL.bit.FREE_SOFT = 11;
(*ePWM[Channel]).CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
(*ePWM[Channel]).CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
// (*ePWM[Channel]).CMPCTL.bit.SHDWAMODE = CC_SHADOW;
// (*ePWM[Channel]).CMPCTL.bit.SHDWBMODE = CC_SHADOW;
(*ePWM[Channel]).CMPCTL.bit.SHDWAMODE = CC_IMMEDIATE; //modified TBD
(*ePWM[Channel]).CMPCTL.bit.SHDWBMODE = CC_IMMEDIATE; //modified TBD
// (*ePWM[Channel]).AQCTLB.bit.ZRO = AQ_SET; // PWM toggle high/low
(*ePWM[Channel]).AQCTLB.bit.ZRO = AQ_CLEAR; // PWM toggle high/low //modified TBD
(*ePWM[Channel]).AQCTLB.bit.CBU = AQ_CLEAR; //TBD?????????
// Interrupt where we will change the Compare Values
(*ePWM[Channel]).ETSEL.bit.INTSEL = ET_CTR_ZERO; // Select INT on Zero event
(*ePWM[Channel]).ETSEL.bit.INTEN = 1; // Enable INT
(*ePWM[Channel]).ETPS.bit.INTPRD = ET_1ST; //ET_3RD; 0->fist event, 1-> second event, 2-> third event // Generate INT on 3rd event
}
/********************************************************************************/
/*!
* \fn : void PWMControl(Uint16 Channel, Uint16 State, Uint16 period)
* \param : Channel - pwm channel to be configured
* \param : State - pwm state whether RUN or STOP
* \param : period - pwm period to be provided
* :
* \brief : Controls individual pwm channels
* \brief Description: This function control the pwm channel
* Configures pwm period & duty cycle
*
* \return : void
*/
/********************************************************************************/
void PWMControl(Uint16 Channel, Uint16 State, Uint16 period)
{
if(State == START)
{
(*ePWM[Channel]).TBPRD = period-1;
(*ePWM[Channel]).CMPA.bit.CMPA = (Uint16)(period*0.7); // set duty 50%
(*ePWM[Channel]).AQCTLA.bit.ZRO = AQ_SET; // PWM toggle high/low
(*ePWM[Channel]).AQCTLA.bit.CAU = AQ_CLEAR;
(*ePWM[Channel]).ETSEL.bit.INTEN = 1; // Enable INT
}
else
{
(*ePWM[Channel]).ETSEL.bit.INTEN = 0; // Disable INT
(*ePWM[Channel]).CMPA.bit.CMPA = 0; //DUTY_PERCENT_0; // set duty 0%
(*ePWM[Channel]).AQCTLA.bit.ZRO = AQ_CLEAR; // PWM toggle high/low
(*ePWM[Channel]).AQCTLA.bit.CAU = AQ_CLEAR;
}
}
/********************************************************************************/
/*!
* \fn : void PWMControlB(Uint16 Channel, Uint16 State, Uint16 period)
* \param : Channel - pwm channel to be configured
* \param : State - pwm state whether RUN or STOP
* \param : period - pwm period to be provided
* :
* \brief : Controls individual pwm channels
* \brief Description: This function control the pwm channel
* Configures pwm period & duty cycle
*
* \return : void
*/
/********************************************************************************/
void PWMControlB(Uint16 Channel, Uint16 State, Uint16 period)
{
DELAY_US(100);
if(State == START)
{
(*ePWM[Channel]).TBPRD = period-1;
(*ePWM[Channel]).CMPB.bit.CMPB = (Uint16)(period*0.7); // set duty 50%
(*ePWM[Channel]).AQCTLB.bit.ZRO = AQ_SET; // PWM toggle high/low
// (*ePWM[Channel]).AQCTLB.bit.CAU = AQ_CLEAR; //original
// (*ePWM[Channel]).AQCTLB.bit.CAU = 0;
(*ePWM[Channel]).AQCTLB.bit.CBU = AQ_CLEAR; //TBD????????
(*ePWM[Channel]).ETSEL.bit.INTEN = 1; // Enable INT
}
else
{
(*ePWM[Channel]).ETSEL.bit.INTEN = 0; // Disable INT
(*ePWM[Channel]).CMPB.bit.CMPB = 0; //DUTY_PERCENT_0; // set duty 0%
(*ePWM[Channel]).AQCTLB.bit.ZRO = AQ_CLEAR; // PWM toggle high/low
(*ePWM[Channel]).AQCTLB.bit.CBU = AQ_CLEAR;
}
}
/********************************************************************************/
/*!
* \fn : void PWMControlDutyCycle(Uint16 Channel, Uint16 State,
* Uint16 period, Uint16 nDutyCycle)
* \param : Channel - pwm channel to be configured
* \param : State - pwm state whether RUN or STOP
* \param : period - pwm period to be provided
* \param : nDutyCycle- pwm duty cyle :
* \brief : Controls individual pwm channels
* \brief Description: This function control the pwm channel
* Configures pwm period & duty cycle
*
* \return : void
*/
/********************************************************************************/
void PWMControlDutyCycle(Uint16 Channel, Uint16 State, Uint16 period, Uint16 nDutyCycle)
{
if(State == START)
{
(*ePWM[Channel]).TBPRD = period-1;
(*ePWM[Channel]).CMPA.bit.CMPA = (Uint16)(period * 0.01 * nDutyCycle); // set duty cycle % //e.g 0.5=50%
(*ePWM[Channel]).AQCTLA.bit.ZRO = AQ_SET; // PWM toggle high/low
(*ePWM[Channel]).AQCTLA.bit.CAU = AQ_CLEAR;
(*ePWM[Channel]).ETSEL.bit.INTEN = 1; // Enable INT
}
else
{
(*ePWM[Channel]).ETSEL.bit.INTEN = 0; // Disable INT
(*ePWM[Channel]).CMPA.bit.CMPA = 0; //DUTY_PERCENT_0; // set duty 0%
(*ePWM[Channel]).AQCTLA.bit.ZRO = AQ_CLEAR; // PWM toggle high/low
(*ePWM[Channel]).AQCTLA.bit.CAU = AQ_CLEAR;
}
}
/********************************************************************************/
/*!
* \fn : void Pwm1FreqControl(Uint16 period)
* \param : period pwm period to be provided
* \brief : Controls individual pwm frequency
* \brief Description: This function control the pwm channel Configures pwm
* period & duty cycle
* \return : void
*/
/********************************************************************************/
void Pwm1FreqControl(Uint16 period)
{
(*ePWM[0]).TBPRD = period-1;
(*ePWM[0]).CMPA.bit.CMPA = (Uint16)(period*0.7); // set duty 70%
}
/********************************************************************************/
/*!
* \fn : void Pwm1FreqControlB(Uint16 period)
* \param : period pwm period to be provided
* \brief : Controls individual pwm frequency
* \brief Description: This function control the pwm channel Configures pwm
* period & duty cycle
* \return : void
*/
/********************************************************************************/
void Pwm1FreqControlB(Uint16 period)
{
(*ePWM[0]).TBPRD = period-1;
(*ePWM[0]).CMPB.bit.CMPB = (Uint16)(period*0.7); // set duty 70%
}
/********************************************************************************/
/*!
* \fn : void Pwm2FreqControl(Uint16 period)
* \param : period pwm period to be provided
* \brief : Controls individual pwm frequency
* \brief Description: This function control the pwm channel Configures pwm
* period & duty cycle
* \return : void
*/
/********************************************************************************/
void Pwm2FreqControl(Uint16 period)
{
(*ePWM[1]).TBPRD = period-1;
(*ePWM[1]).CMPA.bit.CMPA = (Uint16)(period*0.7); // set duty 70%
}
/********************************************************************************/
/*!
* \fn : void Pwm2FreqControlB(Uint16 period)
* \param : period pwm period to be provided
* \brief : Controls individual pwm frequency
* \brief Description: This function control the pwm channel Configures pwm
* period & duty cycle
* \return : void
*/
/********************************************************************************/
void Pwm2FreqControlB(Uint16 period)
{
(*ePWM[1]).TBPRD = period-1;
(*ePWM[1]).CMPB.bit.CMPB = (Uint16)(period*0.7); // set duty 70%
}
/********************************************************************************/
/*!
* \fn : void Pwm3FreqControl(Uint16 period)
* \param : period pwm period to be provided
* \brief : Controls individual pwm frequency
* \brief Description: This function control the pwm channel Configures pwm
* period & duty cycle
* \return : void
*/
/********************************************************************************/
void Pwm3FreqControl(Uint16 period)
{
(*ePWM[2]).TBPRD = period-1;
(*ePWM[2]).CMPA.bit.CMPA = (Uint16)(period*0.7); // set duty 70%
}
/********************************************************************************/
/*!
* \fn : void Pwm3FreqControlB(Uint16 period)
* \param : period pwm period to be provided
* \brief : Controls individual pwm frequency
* \brief Description: This function control the pwm channel Configures pwm
* period & duty cycle
* \return : void
*/
/********************************************************************************/
void Pwm3FreqControlB(Uint16 period)
{
(*ePWM[2]).TBPRD = period-1;
(*ePWM[2]).CMPB.bit.CMPB = (Uint16)(period*0.7); // set duty 70%
}
/********************************************************************************/
/*!
* \fn : void Pwm4FreqControl(Uint16 period)
* \param : period pwm period to be provided
* \brief : Controls individual pwm frequency
* \brief Description: This function control the pwm channel Configures pwm
* period & duty cycle
* \return : void
*/
/********************************************************************************/
void Pwm4FreqControl(Uint16 period)
{
(*ePWM[3]).TBPRD = period-1;
(*ePWM[3]).CMPA.bit.CMPA = (Uint16)(period*0.7); // set duty 70%
}
/********************************************************************************/
/*!
* \fn : void Pwm4FreqControlB(Uint16 period)
* \param : period pwm period to be provided
* \brief : Controls individual pwm frequency
* \brief Description: This function control the pwm channel Configures pwm
* period & duty cycle
* \return : void
*/
/********************************************************************************/
void Pwm4FreqControlB(Uint16 period)
{
(*ePWM[3]).TBPRD = period-1;
(*ePWM[3]).CMPB.bit.CMPB = (Uint16)(period*0.7); // set duty 70%
}
/********************************************************************************/
/*!
* \fn : void Pwm5FreqControl(Uint16 period)
* \param : period pwm period to be provided
* \brief : Controls individual pwm frequency
* \brief Description: This function control the pwm channel Configures pwm
* period & duty cycle
* \return : void
*/
/********************************************************************************/
void Pwm5FreqControl(Uint16 period)
{
(*ePWM[4]).TBPRD = period-1;
(*ePWM[4]).CMPA.bit.CMPA = (Uint16)(period*0.5); // set duty 50%
}
/********************************************************************************/
/*!
* \fn : void Pwm5FreqControlB(Uint16 period)
* \param : period pwm period to be provided
* \brief : Controls individual pwm frequency
* \brief Description: This function control the pwm channel Configures pwm
* period & duty cycle
* \return : void
*/
/********************************************************************************/
void Pwm5FreqControlB(Uint16 period)
{
(*ePWM[4]).TBPRD = period-1;
(*ePWM[4]).CMPB.bit.CMPB = (Uint16)(period*0.7); // set duty 70%
}
/********************************************************************************/
/*!
* \fn : void Pwm6FreqControl(Uint16 period)
* \param : period pwm period to be provided
* \brief : Controls individual pwm frequency
* \brief Description: This function control the pwm channel Configures pwm
* period & duty cycle
* \return : void
*/
/********************************************************************************/
void Pwm6FreqControl(Uint16 period)
{
(*ePWM[5]).TBPRD = period-1;
(*ePWM[5]).CMPA.bit.CMPA = (Uint16)(period*0.7); // set duty 70%
}
/********************************************************************************/
/*!
* \fn : void Pwm6FreqControlB(Uint16 period)
* \param : period pwm period to be provided
* \brief : Controls individual pwm frequency
* \brief Description: This function control the pwm channel Configures pwm
* period & duty cycle
* \return : void
*/
/********************************************************************************/
void Pwm6FreqControlB(Uint16 period)
{
(*ePWM[5]).TBPRD = period-1;
(*ePWM[5]).CMPB.bit.CMPB = (Uint16)(period*0.7); // set duty 70%
}
/********************************************************************************/
/*!
* \fn : void Pwm7FreqControl(Uint16 period)
* \param : period pwm period to be provided
* \brief : Controls individual pwm frequency
* \brief Description: This function control the pwm channel Configures pwm
* period & duty cycle
* \return : void
*/
/********************************************************************************/
void Pwm7FreqControl(Uint16 period)
{
(*ePWM[6]).TBPRD = period-1;
(*ePWM[6]).CMPA.bit.CMPA = (Uint16)(period*0.7); // set duty 70%
}
/********************************************************************************/
/*!
* \fn : void Pwm7FreqControlB(Uint16 period)
* \param : period pwm period to be provided
* \brief : Controls individual pwm frequency
* \brief Description: This function control the pwm channel Configures pwm
* period & duty cycle
* \return : void
*/
/********************************************************************************/
void Pwm7FreqControlB(Uint16 period)
{
(*ePWM[6]).TBPRD = period-1;
(*ePWM[6]).CMPB.bit.CMPB = (Uint16)(period*0.7); // set duty 70%
}
/********************************************************************************/
/*!
* \fn : void Pwm8FreqControl(Uint16 period)
* \param : period pwm period to be provided
* \brief : Controls individual pwm frequency
* \brief Description: This function control the pwm channel Configures pwm
* period & duty cycle
* \return : void
*/
/********************************************************************************/
void Pwm8FreqControl(Uint16 period)
{
(*ePWM[7]).TBPRD = period-1;
(*ePWM[7]).CMPA.bit.CMPA = (Uint16)(period*0.7); // set duty 70%
}
/********************************************************************************/
/*!
* \fn : void Pwm8FreqControlB(Uint16 period)
* \param : period pwm period to be provided
* \brief : Controls individual pwm frequency
* \brief Description: This function control the pwm channel Configures pwm
* period & duty cycle
* \return : void
*/
/********************************************************************************/
void Pwm8FreqControlB(Uint16 period)
{
(*ePWM[7]).TBPRD = period-1;
(*ePWM[7]).CMPB.bit.CMPB = (Uint16)(period*0.7); // set duty 70%
}
/********************************************************************************/
/*!
* \fn : void Pwm9FreqControl(Uint16 period)
* \param : period pwm period to be provided
* \brief : Controls individual pwm frequency
* \brief Description: This function control the pwm channel Configures pwm
* period & duty cycle
* \return : void
*/
/********************************************************************************/
void Pwm9FreqControl(Uint16 period)
{
(*ePWM[8]).TBPRD = period-1;
(*ePWM[8]).CMPA.bit.CMPA = (Uint16)(period*0.7); // set duty 70%
}
/********************************************************************************/
/*!
* \fn : void Pwm9FreqControlB(Uint16 period)
* \param : period pwm period to be provided
* \brief : Controls individual pwm frequency
* \brief Description: This function control the pwm channel Configures pwm
* period & duty cycle
* \return : void
*/
/********************************************************************************/
void Pwm9FreqControlB(Uint16 period)
{
(*ePWM[8]).TBPRD = period-1;
(*ePWM[8]).CMPB.bit.CMPB = (Uint16)(period*0.7); // set duty 70%
}
/********************************************************************************/
/*!
* \fn : void Pwm10FreqControl(Uint16 period)
* \param : period pwm period to be provided
* \brief : Controls individual pwm frequency
* \brief Description: This function control the pwm channel Configures pwm
* period & duty cycle
* \return : void
*/
/********************************************************************************/
void Pwm10FreqControl(Uint16 period)
{
(*ePWM[9]).TBPRD = period-1;
(*ePWM[9]).CMPA.bit.CMPA = (Uint16)(period*0.7); // set duty 70%
}
/********************************************************************************/
/*!
* \fn : void Pwm10FreqControlB(Uint16 period)
* \param : period pwm period to be provided
* \brief : Controls individual pwm frequency
* \brief Description: This function control the pwm channel Configures pwm
* period & duty cycle
* \return : void
*/
/********************************************************************************/
void Pwm10FreqControlB(Uint16 period)
{
(*ePWM[9]).TBPRD = period-1;
(*ePWM[9]).CMPB.bit.CMPB = (Uint16)(period*0.7); // set duty 70%
}
/********************************************************************************/
/*!
* \fn : void Pwm11FreqControl(Uint16 period)
* \param : period pwm period to be provided
* \brief : Controls individual pwm frequency
* \brief Description: This function control the pwm channel Configures pwm
* period & duty cycle
* \return : void
*/
/********************************************************************************/
void Pwm11FreqControl(Uint16 period)
{
(*ePWM[10]).TBPRD = period-1;
(*ePWM[10]).CMPA.bit.CMPA = (Uint16)(period*0.7); // set duty 70%
}
/********************************************************************************/
/*!
* \fn : void Pwm11FreqControlB(Uint16 period)
* \param : period pwm period to be provided
* \brief : Controls individual pwm frequency
* \brief Description: This function control the pwm channel Configures pwm
* period & duty cycle
* \return : void
*/
/********************************************************************************/
void Pwm11FreqControlB(Uint16 period)
{
(*ePWM[10]).TBPRD = period-1;
(*ePWM[10]).CMPB.bit.CMPB = (Uint16)(period*0.7); // set duty 70%
}
/********************************************************************************/
/*!
* \fn : void Pwm12FreqControl(Uint16 period)
* \param : period pwm period to be provided
* \brief : Controls individual pwm frequency
* \brief Description: This function control the pwm channel Configures pwm
* period & duty cycle
* \return : void
*/
/********************************************************************************/
void Pwm12FreqControl(Uint16 period)
{
(*ePWM[11]).TBPRD = period-1;
(*ePWM[11]).CMPA.bit.CMPA = (Uint16)(period*0.7); // set duty 70%
}
/********************************************************************************/
/*!
* \fn : void Pwm12FreqControlB(Uint16 period)
* \param : period pwm period to be provided
* \brief : Controls individual pwm frequency
* \brief Description: This function control the pwm channel Configures pwm
* period & duty cycle
* \return : void
*/
/********************************************************************************/
void Pwm12FreqControlB(Uint16 period)
{
(*ePWM[11]).TBPRD = period-1;
(*ePWM[11]).CMPB.bit.CMPB = (Uint16)(period*0.7); // set duty 70%
}
/********************************************************************************/
/*!
* \fn : __interrupt void epwm1_isr(void)
* \brief : PWM isr routine to count number of steps
* \brief Description: PWM interrupt handler call on every frequency steps
* s-curve and pwm cotrol shall be done here
* \return : void
*/
/********************************************************************************/
__interrupt void epwm1_isr(void)
{
//check for homesensor flag, move Reagent arm till home sensor is detected
if(nReagentArmUpHomeFlag || nReagentArmRotationHomeFlag)
{
//reagent arm up home
if(nReagentArmUpHomeFlag )
{
nReagentArmUpHomesensor = GPIO_ReadPin(REAGENTARMLINEAR_HOMESENSOR);
if(nReagentArmUpHomesensor == 1)
{
nReagentArmUpHomeFlag = 0;
//PWMControlB(PWMCHANNEL_REAGENTARMLINEAR,STOP,PWMPERIOD_REAGENTARMLINEAR * 20);
StopMotor(REAGENT_ARM_LIN);
stReagentArmLinear.CurrentPosition = stReagentArmLinear.NextPosition;
nReagentArmLinearMotionDoneFlag = 1;
nReagentArmLinearStartFlag = 0;
ucCapacitanceSenseFlag = 0; //for temporary flag for capacitor sensor test
GPIO_WritePin(164,0);
}
}
//reagent Arm Roation Home
else if(nReagentArmRotationHomeFlag)
{
nReagentArmRotationHomesensor = GPIO_ReadPin(REAGENTARMROTATION_HOMESENSOR);
if(nReagentArmRotationHomesensor == 0)
{
nReagentArmRotationHomeFlag = 0;
//PWMControl(PWMCHENNEL_REAGENTARMROTATION,STOP,PWMPERIOD_REAGENTARMROTATION * 20);
StopMotor(REAGENT_ARM_ROT);
}
}
}
else if(nReagentArmLinearStartFlag == 1) //Move either reagent arm linear or rotation
{
HandleReagentArmLinearMotion();
}
else
{
HandleReagentArmRotationalMotion();
}
// Clear INT flag for this timer
EPwm1Regs.ETCLR.bit.INT = 1;
// Acknowledge this interrupt to receive more interrupts from group 3
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
}
/********************************************************************************/
/*!
* \fn : __interrupt void epwm2_isr(void)
* \brief : PWM isr routine to count number of steps
* \brief Description: PWM interrupt handler call on every frequency steps
* s-curve and pwm cotrol shall be done here
* \return : void
*/
/********************************************************************************/
__interrupt void epwm2_isr(void)
{
//check for homesensor flag, move Mixer arm till home sensor is detected
if( nMixerArmUpHomeFlag || nMixerArmRotationHomeFlag )
{
//Mixer Arm Linear Home
if(nMixerArmUpHomeFlag )
{
nMixerArmUpHomesensor = GPIO_ReadPin(MIXERARMLINEAR_HOMESENSOR);
if(nMixerArmUpHomesensor == 1 )
{
nMixerArmUpHomeFlag = 0;
//PWMControlB(PWMCHANNEL_MIXERARMLINEAR,STOP,PWMPERIOD_MIXERARMLINEAR * 20 );
StopMotor(MIXER_ARM_LIN);
stMixerArmLinear.CurrentPosition = stMixerArmLinear.NextPosition;
nMixerArmLinearmotionDoneFlag = 1;
}
}
//Mixer Arm Roation Home
else if(nMixerArmRotationHomeFlag )
{
nMixerArmRotationHomesensor = GPIO_ReadPin(MIXERARMROTATION_HOMESENSOR);
if(nMixerArmRotationHomesensor == 1 )
{
nMixerArmRotationHomeFlag = 0;
//PWMControl(PWMCHANNEL_MIXERARMROTATION,STOP, PWMPERIOD_MIXERARMROTATION * 20);
StopMotor(MIXER_ARM_ROT);
}
}
}
else if(nMixerArmLinearStartFlag == 1) //Move either Mixer arm linear or rotation
{
HandleMixerArmLinearMotion();
}
else
{
HandleMixerArmRotationalMotion();
}
// Clear INT flag for this timer
EPwm2Regs.ETCLR.bit.INT = 1;
// Acknowledge this interrupt to receive more interrupts from group 3
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
}
/********************************************************************************/
/*!
* \fn : __interrupt void epwm3_isr(void)
* \brief : PWM isr routine to count number of steps
* \brief Description: PWM interrupt handler call on every frequency steps
* s-curve and pwm cotrol shall be done here
* \return : void
*/
/********************************************************************************/
__interrupt void epwm3_isr(void)
{
//check for homesensor flag, move Sample arm till home sensor is detected
if(nSampleArmUpHomeFlag || nSampleArmRotationHomeFlag )
{
//Sample Arm Linear Home
if(nSampleArmUpHomeFlag )
{
nSampleArmUpHomesensor = GPIO_ReadPin(SAMPLEARMLINEAR_HOMESENSOR);
if(nSampleArmUpHomesensor == 1 )
{
nSampleArmUpHomeFlag = 0;
//PWMControlB(PWMCHANNEL_SAMPLEARMLINEAR,STOP,PWMPERIOD_SAMPLEARMLINEAR * 20);
StopMotor(SAMPLE_ARM_LIN);
stSampleArmLinear.CurrentPosition = stSampleArmLinear.NextPosition;
nSampleArmLinearMotionDoneFlag = 1;
}
}
//Sample Arm Roation Home
else if(nSampleArmRotationHomeFlag )
{
nSampleArmRotationHomesensor = GPIO_ReadPin(SAMPLEARMROTATION_HOMESENSOR);
if(nSampleArmRotationHomesensor == 0)
{
nSampleArmRotationHomeFlag = 0;
//PWMControl(PWMCHANNEL_SAMPLEARMROTATION,STOP,PWMPERIOD_SAMPLEARMROTATION * 20);
StopMotor(SAMPLE_ARM_ROT);
}
}
}
else if(nSampleArmLinearStartFlag == 1) //Move either Sample arm linear or rotation
{
HandleSampleArmLinearMotion();
}
else
{
HandleSampleArmRotationalMotion();
}
// Clear INT flag for this timer
EPwm3Regs.ETCLR.bit.INT = 1;
// Acknowledge this interrupt to receive more interrupts from group 3
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
}
/********************************************************************************/
/*!
* \fn : __interrupt void epwm4_isr(void)
* \brief : PWM isr routine to count number of steps
* \brief Description: PWM interrupt handler call on every frequency steps
* s-curve and pwm cotrol shall be done here
* \return : void
*/
/********************************************************************************/
__interrupt void epwm4_isr(void)
{
nReactionTrayPitchsensor = GPIO_ReadPin(REACTIONCAROUSEL_STEPSENSOR);
if(0 == nReactionTrayPitchsensor)
{
nReactionTrayPitchCounter++;
if(nReactionTrayPitchsensorFlag)
{
//PWMControl(PWMCHENNEL_REACTIONCROUSAL,STOP,PWMPERIOD_REACTIONCROUSAL * 5); // stop PWM generation for reaction tray
StopMotor(REACTION_CAROUSAL);
stReactionCorousal.CurrentPosition = 1;
stReactionCorousal.NextPosition = 1;
nReactionTrayPitchCounter = 0;
nReactionTrayPitchsensorFlag = 0;
}
}
//check for homesensor flag, move Reaction Carousel till home sensor is detected
if(nReactionTrayHomeFlag)
{
nReactionTrayHomesensor = GPIO_ReadPin(REACTIONCAROUSEL_HOMESENSOR);
if(nReactionTrayHomesensor == 1 )
{
nReactionTrayHomeFlag = 0;
//PWMControl(PWMCHENNEL_REACTIONCROUSAL,STOP,PWMPERIOD_REACTIONCROUSAL * 5); // stop PWM generation for reaction tray
StopMotor(REACTION_CAROUSAL);
stReactionCorousal.CurrentPosition = 1;
stReactionCorousal.NextPosition = 1;
nReactionTrayPitchCounter = 0;
}
}
else
{
MoveReactionCarousel();
}
// Clear INT flag for this timer
EPwm4Regs.ETCLR.bit.INT = 1;
// Acknowledge this interrupt to receive more interrupts from group 3
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
// MoveReactionTray();
}
/********************************************************************************/
/*!
* \fn : __interrupt void epwm5_isr(void)
* \brief : PWM isr routine to count number of steps
* \brief Description: PWM interrupt handler call on every frequency steps
* s-curve and pwm cotrol shall be done here
* \return : void
*/
/********************************************************************************/
__interrupt void epwm5_isr(void)
{
nReagentTrayPitchSensor = GPIO_ReadPin(REAGENTCAROUSEL_STEPSENSOR);
if(0 == nReagentTrayPitchSensor)
{
nReagentTrayPitchCounter++;
if(nReagentTrayPitchsensorFlag)
{
//PWMControl(PWMCHENNEL_REAGENTCROUSEL,STOP,PWMPERIOD_REAGENTCROUSEL * 9); // stop PWM generation for reaction tray
StopMotor(REAGENT_CAROUSAL);
stReagentCorousal.CurrentPosition = 1;
stReagentCorousal.NextPosition = 1;
nReagentTrayPitchCounter = 0;
nReagentTrayPitchsensorFlag = 0;
}
}
//check for homesensor flag, move Reagent Carousel till home sensor is detected
if(nReagentTrayHomeFlag)
{
nReagentTrayHomesensor = GPIO_ReadPin(REAGENTCAROUSEL_HOMESENSOR);
if(nReagentTrayHomesensor == 1 )
{
nReagentTrayHomeFlag = 0;
//PWMControl(PWMCHENNEL_REAGENTCROUSEL,STOP,PWMPERIOD_REAGENTCROUSEL * 9); // stop PWM generation for reagent tray
StopMotor(REAGENT_CAROUSAL);
stReagentCorousal.CurrentPosition = 1;
stReagentCorousal.NextPosition = 1;
}
}
else
{
MoveReagentTray();
}
//to be deleted, temp function to tes RCT
// TemporaryMoveRCT(); //to be deleted , for testing RCT with arkmotion driver only
// Clear INT flag for this timer
EPwm5Regs.ETCLR.bit.INT = 1;
// Acknowledge this interrupt to receive more interrupts from group 3
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
}
/********************************************************************************/
/*!
* \fn : __interrupt void epwm6_isr(void)
* \brief : PWM isr routine to count number of steps
* \brief Description: PWM interrupt handler call on every frequency steps
* s-curve and pwm cotrol shall be done here
* \return : void
*/
/********************************************************************************/
__interrupt void epwm6_isr(void)
{
// Clear INT flag for this timer
EPwm6Regs.ETCLR.bit.INT = 1;
// Acknowledge this interrupt to receive more interrupts from group 3
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
}
/********************************************************************************/
/*!
* \fn : __interrupt void epwm7_isr(void)
* \brief : PWM isr routine to count number of steps
* \brief Description: PWM interrupt handler call on every frequency steps
* s-curve and pwm cotrol shall be done here
* \return : void
*/
/********************************************************************************/
__interrupt void epwm7_isr(void)
{
//check for homesensor flag, move Wash station linear till home sensor is detected
if(nWashArmUpHomeFlag )
{
nWashArmUpHomeHomesensor = GPIO_ReadPin(WASHSTATIONLINEAR_HOMESENSOR);
if(nWashArmUpHomeHomesensor == 1 )
{
nWashArmUpHomeFlag = 0;
//PWMControl(PWMCHANNEL_WASHARMLINEAR,STOP,PWMPERIOD_WASHARMLINEAR * 25 );
StopMotor(WASH_STATION);
stWashStation.CurrentPosition = stWashStation.NextPosition;
nWashArmMovementDoneFlag = 1;
}
}
else
{
MoveWashStationLinear();
}
// Clear INT flag for this timer
EPwm7Regs.ETCLR.bit.INT = 1;
// Acknowledge this interrupt to receive more interrupts from group 3
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
}
/********************************************************************************/
/*!
* \fn : __interrupt void epwm8_isr(void)
* \brief : PWM isr routine to count number of steps
* \brief Description: PWM interrupt handler call on every frequency steps
* s-curve and pwm cotrol shall be done here
* \return : void
*/
/********************************************************************************/
__interrupt void epwm8_isr(void)
{
ReagentSyringePumpOperationControl();
// Clear INT flag for this timer
EPwm8Regs.ETCLR.bit.INT = 1;
// Acknowledge this interrupt to receive more interrupts from group 3
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
}
/********************************************************************************/
/*!
* \fn : __interrupt void epwm9_isr(void)
* \brief : PWM isr routine to count number of steps
* \brief Description: PWM interrupt handler call on every frequency steps
* s-curve and pwm cotrol shall be done here
* \return : void
*/
/********************************************************************************/
__interrupt void epwm9_isr(void)
{
//check for homesensor flag, move sample tray Y till home sensor is detected
/*if(nSampleTrayHomeFlag )
{
nSampleTrayHomesensor = GPIO_ReadPin(SAMPLETRAY_HOMESENSOR);
if(nSampleTrayHomesensor == 1 )
{
nSampleTrayHomeFlag = 0;
PWMControlB(PWMCHANNEL_SAMPLETRAY, STOP, PWMPERIOD_SAMPLETRAY * 20);
}
}
else
{
MoveSampleTrayY();
}*/
SampleSyringePumpOperationControl();
// Clear INT flag for this timer
EPwm9Regs.ETCLR.bit.INT = 1;
// Acknowledge this interrupt to receive more interrupts from group 3
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
}
/********************************************************************************/
/*!
* \fn : __interrupt void epwm10_isr(void)
* \brief : PWM isr routine to count number of steps
* \brief Description: PWM interrupt handler call on every frequency steps
* s-curve and pwm cotrol shall be done here
* \return : void
*/
/********************************************************************************/
__interrupt void epwm10_isr(void)
{
// Clear INT flag for this timer
EPwm10Regs.ETCLR.bit.INT = 1;
// Acknowledge this interrupt to receive more interrupts from group 3
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
}
/********************************************************************************/
/*!
* \fn : __interrupt void epwm11_isr(void)
* \brief : PWM isr routine to count number of steps
* \brief Description: PWM interrupt handler call on every frequency steps
* s-curve and pwm cotrol shall be done here
* \return : void
*/
/********************************************************************************/
__interrupt void epwm11_isr(void)
{
// Clear INT flag for this timer
EPwm11Regs.ETCLR.bit.INT = 1;
// Acknowledge this interrupt to receive more interrupts from group 3
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
}
/********************************************************************************/
/*!
* \fn : __interrupt void epwm12_isr(void)
* \brief : PWM isr routine to count number of steps
* \brief Description: PWM interrupt handler call on every frequency steps
* s-curve and pwm cotrol shall be done here
* \return : void
*/
/********************************************************************************/
__interrupt void epwm12_isr(void)
{
// Clear INT flag for this timer
EPwm12Regs.ETCLR.bit.INT = 1;
// Acknowledge this interrupt to receive more interrupts from group 3
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
}
//motor pump code
/********************************************************************************/
/*!
* \fn : void PWMControlDutyCycleB(Uint16 Channel, Uint16 State,
* Uint16 period, Uint16 nDutyCycle)
* \param : Channel - pwm channel to be configured
* \param : State - pwm state whether RUN or STOP
* \param : period - pwm period to be provided
* \param : nDutyCycle- pwm duty cyle :
* \brief : Controls individual pwm channels
* \brief Description: This function control the pwm channel
* Configures pwm period & duty cycle
*
* \return : void
*/
/********************************************************************************/
void PWMControlDutyCycleB(Uint16 Channel, Uint16 State, Uint16 period, Uint16 nDutyCycle)
{
if(State == START)
{
(*ePWM[Channel]).TBPRD = period-1;
(*ePWM[Channel]).CMPB.bit.CMPB = (Uint16)(period * 0.01 * nDutyCycle); // set duty cycle % //e.g 0.5=50%
(*ePWM[Channel]).AQCTLB.bit.ZRO = AQ_SET; // PWM toggle high/low
(*ePWM[Channel]).AQCTLB.bit.CBU = AQ_CLEAR;
(*ePWM[Channel]).ETSEL.bit.INTEN = 1; // Enable INT
}
else
{
(*ePWM[Channel]).ETSEL.bit.INTEN = 0; // Disable INT
(*ePWM[Channel]).CMPB.bit.CMPB = 0; //DUTY_PERCENT_0; // set duty 0%
(*ePWM[Channel]).AQCTLB.bit.ZRO = AQ_CLEAR; // PWM toggle high/low
(*ePWM[Channel]).AQCTLB.bit.CBU = AQ_CLEAR;
}
}
//*****************************************************************************
// Close the Doxygen group.
//! @}
//*****************************************************************************