• The PWM timer consists of a 16-bit down counter, a 16-bit data register with a cycle set buffer, a 16-bit compare register with a duty set buffer, and a pin controller.
  • The cycle and duty data is stored in a buffered register and thus can be rewritten while the timer is in operation.
  • The counter clock of the 16-bit down counter can be selected from eight internal clocks (1, 4, 16, 128, 256,512, 1024, and 2048 frequency divisions of the machine clock) and three external events (detection of a rising edge, a falling edge or both).
  • The one-shot mode where the counting stops at an underflow or the continuous mode where the counting is repeated after reloading can be selected.
  • The start event of the 16-bit PWM timer can be selected from a software trigger and three external events (detection of a rising edge, a falling edge or both).

 

RSI_MCPWM_BaseTimerSelect:

Prototype
STATIC INLINE void RSI_MCPWM_BaseTimerSelect( RSI_MCPWM_T *pMCPWM, uint8_t baseTime 
Input Arguments

pMCPWM   :  Pointer to the MCPWM instance register area

baseTime   :  if 0 then one base timer for each channel

                     if 1 then only one base timer for all channels

Return Value

None

Description

This API is used to select number of base timers as four base timers for four channels or one base timer for all channels of MCPWM

Example Usage
RSI_MCPWM_BaseTimerSelect(MCPWM, ONE_TIMER_FOR_EACH_CHNL);

 

RSI_MCPWM_SetOutputPolarity:

Prototype

STATIC INLINE void  RSI_MCPWM_SetOutputPolarity( RSI_MCPWM_T *pMCPWM,

        boolean_t polL,

        boolean_t polH )

Input Arguments

pMCPWM  :  Pointer to the MCPWM instance register area

polL     :  Ouput polarity for low side (L3, L2, L1, L0)

polH    :  Ouput polarity for high side (H3, H2, H1, H0)

Return Value

None

Description

This API is used to set output polarity for MCPWM

Example Usage
RSI_MCPWM_SetOutputPolarity(MCPWM,1 ,1);

 

RSI_MCPWM_SetOutputMode:

Prototype

STATIC INLINE error_t RSI_MCPWM_SetOutputMode( RSI_MCPWM_T *pMCPWM,

        boolean_t mode,

        uint8_t chnlNum )

Input Arguments

pMCPWM    :  Pointer to the MCPWM instance register area

mode    :  If input is one then complementary output mode if zero then independent output mode.

chnlNum :  Channel number(0 to 3)

Return Value

ERROR_PWM_INVALID_CHNLNUM : If channel number is invalid

RSI_OK  : If process is done successfully

Description

This API is used to set output mode for the MCPWM

Example Usage
RSI_MCPWM_SetOutputMode(MCPWM, 1,0);

 

RSI_MCPWM_SetBaseTimerMode:

Prototype

STATIC INLINE error_t RSI_MCPWM_SetBaseTimerMode( RSI_MCPWM_T *pMCPWM,

        uint8_t mode,

        uint8_t chnlNum )

Input Arguments

pMCPWM  :  Pointer to the MCPWM instance register area

mode    :  Base timer operating mode

                           -  000 : free running mode

                           -  001 : single event mode

                           -  010 : down count mode

                           -  100 : up/down mode

                           -  101 : up/dowm mode with interrupts for double PWM updates

chnlNum : Channel number(0 to 3)

Return Value

ERROR_PWM_INVALID_CHNLNUM : If channel number is invalid

RSI_OK  : If process is done successfully

Description

This API is used to set the mode of base timer for required channel

Example Usage
RSI_MCPWM_SetBaseTimerMode(MCPWM, TMR_FREE_RUN_MODE, PWM_CHNL_0);

 

RSI_MCPWM_GetTimePeriod:

Prototype

STATIC INLINE uint16_t RSI_MCPWM_GetTimePeriod( RSI_MCPWM_T *pMCPWM,

        uint8_t chnlNum,

        uint16_t *timePeriod )

Input Arguments

pMCPWM    :  Pointer to the MCPWM instance register area

chnlNum     : channel number(0-3)

timePeriod  : pointer to read time period.

Return Value

ERROR_PWM_INVALID_CHNLNUM : If channel number is invalid

RSI_OK  : If process is done successfully

Description

Get time period for required channel.

Example Usage
RSI_MCPWM_GetTimePeriod(MCPWM,chnl_num,&time_period);

 

RSI_MCPWM_SetDutyCycle:

Prototype

STATIC INLINE error_t RSI_MCPWM_SetDutyCycle( RSI_MCPWM_T *pMCPWM,

                                              uint16_t dutyCycle,

                                              uint8_t chnlNum )

Input Arguments

pMCPWM    :  Pointer to the MCPWM instance register area

dutyCycle :  Duty cycle value

chnlNum   :  channel number(0 to 3)

Return Value

ERROR_PWM_INVALID_ARG : If channel number is invalid

RSI_OK  : If process is done successfully

Description

This API is used to set duty cycle for the required MCPWM channel

Example Usage

RSI_MCPWM_SetDutyCycle(MCPWM, 0 ,PWM_CHNL_0);

 

RSI_MCPWM_Start:

Prototype

STATIC INLINE error_t RSI_MCPWM_Start( RSI_MCPWM_T *pMCPWM,

        uint8_t chnlNum )

Input Arguments

pMCPWM    :  Pointer to the MCPWM instance register area

chnlNum   :  channel number(0 to 3)

Return Value

ERROR_PWM_INVALID_CHNLNUM : If channel number is invalid

RSI_OK  : If process is done successfully

Description

This API is used to start the MCPWM operation for required channel

Example Usage
RSI_MCPWM_Start( MCPWM , PWM_CHNL_0);

 

RSI_MCPWM_SetTimePeriod:

Prototype

STATIC INLINE error_t RSI_MCPWM_SetTimePeriod( RSI_MCPWM_T *pMCPWM,

        uint8_t chnlNum, uint16_t period,uint16_t initVal )

Input Arguments

pMCPWM    :  Pointer to the MCPWM instance register area

chnlNum   :  channel number(0 to 3)

period  :  Time period value

initVal :  Update the base time counter initial value

Return Value

ERROR_PWM_INVALID_CHNLNUM : If channel number is invalid

RSI_OK  : If process is done successfully

Description

This API is used to set time period and counter initial,value for the required MCPWM channel.

Example Usage
RSI_MCPWM_SetTimePeriod( MCPWM,PWM_CHNL_3 ,rate ,COUNTER_INIT_VAL);

 

RSI_MCPWM_InterruptEnable:

Prototype

STATIC INLINE void RSI_MCPWM_InterruptEnable( RSI_MCPWM_T *pMCPWM,

uint16_t flag )

Input Arguments

pMCPWM    :  Pointer to the MCPWM instance register area

flag   : flag value can be logical OR of the below parameters

           RISE_PWM_TIME_PERIOD_MATCH_CH0

           PWM_TIME_PRD_MATCH_INTR_CH0

           FLT_A_INTR

           FLT_B_INTR

           RISE_PWM_TIME_PERIOD_MATCH_CH1

           PWM_TIME_PRD_MATCH_INTR_CH1

           RISE_PWM_TIME_PERIOD_MATCH_CH2

           PWM_TIME_PRD_MATCH_INTR_CH2

           RISE_PWM_TIME_PERIOD_MATCH_CH3

           PWM_TIME_PRD_MATCH_INTR_CH3

Return Value None
Description

This API is used to enable the interrupts of MCPWM

Example Usage
RSI_MCPWM_InterruptEnable( MCPWM, RSI_MCPWM_EVENT_TIME_PERIOD_MATCH_CH0 );

 

RSI_MCPWM_OutputOverrideEnable:

Prototype

STATIC INLINE error_t RSI_MCPWM_OutputOverrideEnable( RSI_MCPWM_T *pMCPWM,

uint8_t pwmOutput )

Input Arguments

pMCPWM    :  Pointer to the MCPWM instance register area

pwmOutput :  Pwm output over ride,possible values are as below

                             - 0 : L0

                             - 1 : L1

                             - 2 : L2

                             - 3 : L3

                             - 4 : H0

                             - 5 : H1

                             - 6 : H2

                             - 7 : H3

Return Value

ERROR_PWM_INVALID_ARG : If pwmOutput value is invalid

RSI_OK  : If process is done successfully

Description

This API is used to enable the output override operation of MCPWM

Example Usage
RSI_MCPWM_OutputOverrideEnable( MCPWM, PWM_OUTPUT_L0););

 

RSI_MCPWM_OverrideValueSet:

Prototype

 STATIC INLINE error_t RSI_MCPWM_OverrideValueSet( RSI_MCPWM_T *pMCPWM,

uint8_t pwmOutput, uint8_t value )

Input Arguments

pMCPWM    :  Pointer to the MCPWM instance register area

pwmOutput :  PWM outputs are as below

                             -  0 : L0

                             -  1 : L1

                             -  2 : L2

                             -  3 : L3

                             -  4 : H0

                             -  5 : H1

                             -  6 : H2

                             -  7 : H3

value     :  override value can be 0 or 1
Return Value

ERROR_PWM_INVALID_CHNLNUM : If channel number is invalid

RSI_OK  : If process is done successfully

Description

This API is used to set override value for the required output of MCPWM.

Example Usage

RSI_MCPWM_OverrideValueSet(MCPWM, PWM_OUTPUT_L0, 1);

 

RSI_MCPWM_OutputOverrideDisable:

Prototype

STATIC INLINE error_t RSI_MCPWM_OutputOverrideDisable( RSI_MCPWM_T *pMCPWM,

uint8_t pwmOutput )

Input Arguments

pMCPWM    :  Pointer to the MCPWM instance register area

pwmOutput :  Pwm output over ride enable,possible values are as below

                             - 0 : L0

                             - 1 : L1

                             - 2 : L2

                             - 3 : L3

                             - 4 : H0

                             - 5 : H1

                             - 6 : H2

                             - 7 : H3

Return Value

ERROR_PWM_INVALID_CHNLNUM : If channel number is invalid

RSI_OK  : If process is done successfully

Description

This API is used to disable the output override operation of MCPWM

Example Usage
RSI_MCPWM_OutputOverrideDisable(MCPWM, PWM_OUTPUT_L0);

 

RSI_MCPWM_ChannelReset:

Prototype error_t mcpwm_channel_reset(RSI_MCPWM_T *pMCPWM,uint8_t chnlNum)
Input Arguments

pMCPWM    :  Pointer to the MCPWM instance register area

chnlNum   :  channel number(0 to 3)

Return Value

ERROR_PWM_INVALID_CHNLNUM : If channel number is invalid

RSI_OK  : If process is done successfully

Description

This API is used to reset the required channel of MCPWM

Example Usage
RSI_MCPWM_ChannelReset(MCPWM,0);