PWM library

The General-Purpose Timer module is available with a number of ARM MCUs. mikroC PRO for ARM provides a library which simplifies using of the PWM mode of General-Purpose Timer Module.

  Important :

Library Routines for Stellaris Cortex M3

Library Routines for Stellaris Cortex M4

Library Routines for ST

Library Routines for CEC1x02

Library Routines for Kinetis

Library Routines for MSP432

PWM_CCPx_Init

Prototype // for Stellaris MCUs with dedicated PORT functions :

unsigned int PWM_CCPx_Init(unsigned long freq_hz);

// for Stellaris MCUs with alternative PORT functions on GPIO pins :

unsigned int PWM_CCPx_Init(unsigned long freq_hz, const Module_Struct *module);

Description

Initializes the PWM module for Stellaris Cortex M3 MCUs.

Parameters
  • freq_hz: PWM frequency in Hz (refer to device datasheet for correct values in respect with Fosc).
  • module: appropriate module pinout. Use Code Assistant to list available module pinouts by typing _GPIO_MODULE_CCP and pressing Ctrl + Space.
Returns

This function returns calculated timer period.

Requires
  • MCU must have the HW PWM Module.
  • Prior to PWM module initialization user must set appropriate pins as output. Please, see GPIO_Config routine.
  • PWM library routines require you to specify the module you want to use. To select the desired PWM module, simply change the letter x in the routine prototype for a number from 0 to 7.
Example
// for Stellaris MCUs with dedicated PORT functions :
GPIO_Config(&GPIO_PORTD_DATA_BITS, _GPIO_PINMASK_4, _GPIO_DIR_NO_CHANGE, _GPIO_CFG_ADV_CCP);
ratio = PWM_CCP0_Init(25000);                          
PWM_CCP0_Set_Duty(ratio/4,_PWM_INVERTED_ENABLE);
PWM_CCP0_Start();

// for Stellaris MCUs with alternative PORT functions on GPIO pins :
ratio = PWM_CCP0_Init(25000, &_GPIO_MODULE_CCP0_B5);                       
PWM_CCP0_Set_Duty(ratio/4,_PWM_INVERTED_ENABLE);
PWM_CCP0_Start();
Notes

Number of available PWM channels depends on MCU. Refer to MCU datasheet for details.

PWM_TnCCPx_Init

Prototype

unsigned int PWM_TnCCPx_Init(unsigned long freq_hz, const Module_Struct *module);

Description

Initializes the PWM module for Stellaris Cortex M4 MCUs.

Parameters
  • freq_hz: PWM frequency in Hz (refer to device datasheet for correct values in respect with Fosc).
  • module: appropriate module pinout. Use Code Assistant to list available module pinouts by typing _GPIO_MODULE_T and pressing Ctrl + Space.
Returns

This function returns calculated timer period.

Requires
  • MCU must have the HW PWM Module.
  • Prior to PWM module initialization user must set appropriate pins as output. Please, see GPIO_Config routine.
  • PWM library routines require you to specify the module you want to use. To select the desired PWM module, simply change the letter x in the routine prototype for a number 0 or 1 to select desired PWM module and letter n from 0 to 5 depending on the used timer module.
Example
ratio = PWM_T0CCP0_Init(25000, &_GPIO_MODULE_T0CCP0_F0_AHB);                       
PWM_T0CCP0_Set_Duty(ratio/4,_PWM_INVERTED_ENABLE);
PWM_T0CCP0_Start();
Notes
  • Number of PWM and Timer modules differs from chip to chip. Please, read the appropriate datasheet before utilizing this library.
  • PWM_TIMn_Init

    Prototype

    unsigned int PWM_TIMn_Init(unsigned long freq_hz);

    Description

    Initializes the Timer module in PWM mode for ST MCUs.

    Parameters
    • freq_hz: PWM frequency in Hz (refer to device datasheet for correct values in respect with Fosc).
    Returns

    This function returns calculated timer period.

    Requires
    • MCU must support the Timer module in PWM mode.
    • PWM library routines require you to specify the Timer module you want to use. To select the desired Timer module, simply change the letter n in the routine prototype for a number from 0 to 17.
    Example
    ratio = PWM_TIM0_Init(25000);                       
    PWM_TIM0_Set_Duty(ratio/4,_PWM_INVERTED_ENABLE);
    PWM_TIM0_Start();
    
    Notes
    • Number of Timer modules differs from chip to chip. Please, read the appropriate datasheet before utilizing this library.

    PWM_CCPx_Set_Duty

    Prototype

    void PWM_CCPx_Set_Duty(unsigned int duty, char inverted);

    Description

    The function changes PWM duty ratio for Stellaris Cortex M3 MCUs.

    Parameters
    • duty: PWM duty ratio. Valid values: 0 to timer period returned by the PWM_CCPx_Init function.
    • inverted: inverted and non inverted PWM signals. Valid values :

      Inverted parameter
      Description Predefined library const
      Inverted PWM signal _PWM_INVERTED_ENABLE
      Non-inverted PWM signal _PWM_INVERTED_DISABLE
    Returns

    Nothing.

    Requires
    • MCU must have the HW PWM Module.
    • PWM module must be properly initialized. See PWM_CCPx_Init routine.
    • PWM library routines require you to specify the module you want to use. To select the desired PWM module, simply change the letter x in the routine prototype for a number from 0 to 7.
    Example
    // Set channel 1 duty ratio to 50%:
    unsigned int pwm_period1;
    ...
    PWM_CCP0_Set_Duty(pwm_period1/2, 1);
    
    Notes

    Number of available PWM channels depends on MCU. Refer to MCU datasheet for details.

    PWM_TnCCPx_Set_Duty

    Prototype

    void PWM_TnCCPx_Set_Duty(unsigned int, unsigned char inverted);

    Description

    The function changes PWM duty ratio for Stellaris Cortex M4 MCUs.

    Parameters
    • duty: PWM duty ratio. Valid values: 0 to timer period returned by the PWM_CCPx_Init function.
    • inverted: inverted and non inverted PWM signals. Valid values :

      Inverted parameter
      Description Predefined library const
      Inverted PWM signal _PWM_INVERTED_ENABLE
      Non-inverted PWM signal _PWM_INVERTED_DISABLE
    Returns

    Nothing.

    Requires
    • MCU must have the HW PWM Module.
    • Prior to PWM module initialization user must set appropriate pins as output. Please, see GPIO_Config routine.
    • PWM module must be properly initialized. See PWM_TnCCPx_Init routine.
    • PWM library routines require you to specify the module you want to use. To select the desired PWM module, simply change the letter x in the routine prototype for a number 0 or 1 to select desired PWM module and letter n from 0 to 5 depending on the used timer module.
    Example
    // Set channel 1 duty ratio to 50%:
    unsigned int pwm_period1;
    ...
    PWM_T0CCP0_Set_Duty(pwm_period1/2, 1);
    
    Notes
  • Number of PWM and Timer modules differs from chip to chip. Please, read the appropriate datasheet before utilizing this library.
  • PWM_TIMn_Set_Duty

    Prototype

    void PWM_TIMn_Set_Duty(unsigned int duty, char inverted, char channel);

    Description

    The function changes duty ratio for Timer module in PWM mode for ST MCUs.

    Parameters
    • duty: PWM duty ratio. Valid values: 0 to timer period returned by the PWM_TIMn_Init function.
    • inverted: inverted and non inverted PWM signals. Valid values :
      Inverted parameter
      Description Predefined library const
      Inverted PWM signal _PWM_INVERTED
      Non-inverted PWM signal _PWM_NON_INVERTED
    • channel: desired PWM channel :
      Channel parameter
      Description Predefined library const
      Channel 1 _PWM_CHANNEL1
      Channel 2 _PWM_CHANNEL2
      Channel 3 _PWM_CHANNEL3
      Channel 4 _PWM_CHANNEL4
    Returns

    Nothing.

    Requires
    • MCU must support the Timer module in PWM mode.
    • PWM mode must be properly initialized. See PWM_TIMn_Init routine.
    • PWM library routines require you to specify the Timer module you want to use. To select the desired Timer module, simply change the letter n in the routine prototype for a number from 0 to 17.
    Example
    // Set channel 1 duty ratio to 50%:
    unsigned int pwm_period1;
    ...
    PWM_TIM0_Set_Duty(pwm_period1/2, _PWM_NON_INVERTED, _PWM_CHANNEL1);
    
    Notes

    Number of available Timer modules and PWM channels depends on MCU. Refer to MCU datasheet for details.

    PWM_CCPx_Start

    Prototype

    void PWM_CCPx_Start();

    Description

    Starts appropriate PWM module for Stellaris Cortex M3 MCUs.

    Parameters

    None.

    Returns

    Nothing.

    Requires
    • MCU must have the HW PWM Module.
    • PWM channel must be properly initialized. See PWM_CCPx_Init routine.
    • PWM library routines require you to specify the module you want to use. To select the desired PWM module, simply change the letter x in the routine prototype for a number from 0 to 7.
    Example
    // Start PWM module
    PWM_CCP0_Start();
    Notes

    Number of available PWM channels depends on MCU. Refer to MCU datasheet for details.

    PWM_TnCCPx_Start

    Prototype

    void PWM_TnCCPx_Start();

    Description

    Starts appropriate PWM module for Stellaris Cortex M4 MCUs.

    Parameters

    None.

    Returns

    Nothing.

    Requires
    • MCU must have the HW PWM Module.
    • Prior to PWM module initialization user must set appropriate pins as output. Please, see GPIO_Config routine.
    • PWM channel must be properly initialized. See PWM_TnCCPx_Init routine.
    • PWM library routines require you to specify the module you want to use. To select the desired PWM module, simply change the letter x in the routine prototype for a number 0 or 1 to select desired PWM module and letter n from 0 to 5 depending on the used timer module.
    Example
    // Start PWM module
    PWM_T0CCP0_Start();
    Notes
    • Number of PWM and Timer modules differs from chip to chip. Please, read the appropriate datasheet before utilizing this library.

    PWM_TIMn_Start

    Prototype

    void PWM_TIMn_Start(char channel, const module_Struct *module);

    Description

    Starts appropriate Timer module in PWM mode for ST MCUs.

    Parameters
    • channel: desired PWM channel :
      Channel parameter
      Description Predefined library const
      Channel 1 _PWM_CHANNEL1
      Channel 2 _PWM_CHANNEL2
      Channel 3 _PWM_CHANNEL3
      Channel 4 _PWM_CHANNEL4
    • module: appropriate module pinout. Use Code Assistant to list available module pinouts by typing _GPIO_MODULE_TIM and pressing Ctrl + Space.
    Returns

    Nothing.

    Requires
    • MCU must support the Timer module in PWM mode.
    • PWM mode must be properly initialized. See PWM_TIMn_Init routine.
    • PWM library routines require you to specify the Timer module you want to use. To select the desired Timer module, simply change the letter n in the routine prototype for a number from 0 to 17.
    Example
    // Start PWM module
    PWM_TIM0_Start(_PWM_CHANNEL1, &_GPIO_MODULE_TIM1_CH1_PA8);
    Notes

    Number of available Timer modules and PWM channels depends on MCU. Refer to MCU datasheet for details.

    PWM_CCPx_Stop

    Prototype

    void PWM_CCPx_Stop();

    Description

    Stops appropriate PWM module for Stellaris Cortex M3 MCUs.

    Parameters

    None.

    Returns

    Nothing.

    Requires
    • MCU must have the HW PWM Module.
    • PWM channel must be properly initialized. See PWM_CCPx_Init routine.
    • PWM library routines require you to specify the module you want to use. To select the desired PWM module, simply change the letter x in the routine prototype for a number from 0 to 7.
    Example
    // Stop PWM module
    PWM_CCP0_Stop();
    Notes
    • Number of PWM modules differs from chip to chip. Please, read the appropriate datasheet before utilizing this library.

    PWM_TnCCPx_Stop

    Prototype

    void PWM_TnCCPx_Stop();

    Description

    Stops appropriate PWM module for Stellaris Cortex M4 MCUs.

    Parameters

    None.

    Returns

    Nothing.

    Requires
    • MCU must have the HW PWM Module.
    • Prior to PWM module initialization user must set appropriate pins as output. Please, see GPIO_Config routine.
    • PWM channel must be properly initialized. See PWM_TnCCPx_Init routine.
    • PWM library routines require you to specify the module you want to use. To select the desired PWM module, simply change the letter x in the routine prototype for a number 0 or 1 to select desired PWM module and letter n from 0 to 5 depending on the used timer module.
    Example
    // Stop PWM module
    PWM_T0CCP0_Stop();
    Notes
    • Number of PWM and Timer modules differs from chip to chip. Please, read the appropriate datasheet before utilizing this library.

    PWM_TIMn_Stop

    Prototype

    void PWM_TIMn_Stop(char channel);

    Description

    Stops appropriate Timer module in PWM mode for ST MCUs.

    Parameters
    • channel: desired PWM channel :
      Channel parameter
      Description Predefined library const
      Channel 1 _PWM_CHANNEL1
      Channel 2 _PWM_CHANNEL2
      Channel 3 _PWM_CHANNEL3
      Channel 4 _PWM_CHANNEL4
    Returns

    Nothing.

    Requires
    • MCU must support the Timer module in PWM mode.
    • PWM mode must be properly initialized. See PWM_TIMn_Init routine.
    • PWM library routines require you to specify the Timer module you want to use. To select the desired Timer module, simply change the letter n in the routine prototype for a number from 0 to 17.
    Example
    // Start PWM module
    PWM_TIM0_Stop(_PWM_CHANNEL1);
    Notes

    Number of available Timer modules and PWM channels depends on MCU. Refer to MCU datasheet for details.

    PWMx_Init

    Prototype

    unsigned int PWMx_Init(unsigned long freq_hz);

    Description

    Initializes the CEC1x02 PWM module. Duty ration is set to 50% by default.
    PWM modules are initialized on the following pins :

    CEC1302

    • PWM0 on pin P133.
    • PWM1 on pin P136.
    • PWM2 on pin P034.
    • PWM3 on pin P141.

    CEC1702

    • PWM0 on pin P053.
    • PWM1 on pin P054.
    • PWM2 on pin P055.
    • PWM3 on pin P056.
    • PWM4 on pin P001.
    • PWM5 on pin P002.
    • PWM10 on pin P134.
    Parameters
    • freq_hz: PWM frequency in Hz, can be in range of 10-100Hz (when 100KHz is used as the clock source) or in the range of 15kHz-30kHz (when 48MHz is used as the clock source), as stated in the datasheet.
    Returns

    This function returns calculated timer period.

    Requires
    • PWM library routines require you to specify the module you want to use. Simply change the letter x in the routine prototype for a number from 0 to 10.
    Example
    ratio = PWM0_Init(25000);                       
    PWM0_Set_Duty(ratio/4,_PWM_INVERTED_ENABLE);
    PWM0_Start();
    
    Notes

    None.

    PWMx_Set_Duty

    Prototype

    void PWMx_Set_Duty(unsigned int duty, char active_low);

    Description

    The function changes the CEC1x02 PWM module duty ratio.

    Parameters
    • duty: PWM duty ratio. Valid values: 0 to timer period returned by the PWMx_Init function.
    • inverted: inverted and non inverted PWM signals. Valid values :
      Inverted parameter
      Description Predefined library const
      Inverted PWM signal _PWM_INVERTED
      Non-inverted PWM signal _PWM_NON_INVERTED
    Returns

    Nothing.

    Requires
    • PWM mode must be properly initialized. See PWMx_Init routine.
    • PWM library routines require you to specify the module you want to use. To select the desired module, simply change the letter x in the routine prototype for a number from 0 to 10.
    Example
    // Set channel 1 duty ratio to 50%:
    unsigned int pwm_period1;
    ...
    PWM0_Set_Duty(pwm_period1/2, _PWM_NON_INVERTED);
    
    Notes

    None.

    PWMx_Start

    Prototype

    void PWMx_Start();

    Description

    Starts CEC1x02 PWM module.

    Parameters

    None.

    Returns

    Nothing.

    Requires
    • PWM mode must be properly initialized. See PWMx_Init routine.
    • PWM library routines require you to specify the module you want to use. To select the desired module, simply change the letter x in the routine prototype for a number from 0 to 10.
    Example
    // Start PWM1 module
    PWM1_Start();
    
    Notes

    None.

    PWMx_Stop

    Prototype

    void PWMx_Stop();

    Description

    This routine stops CEC1x02 PWM module.

    Parameters

    None.

    Returns

    Nothing.

    Requires
    • PWM mode must be properly initialized. See PWMx_Init routine.
    • PWM library routines require you to specify the module you want to use. To select the desired module, simply change the letter x in the routine prototype for a number from 0 to 10.
    Example
    // Stop PWM1 module
    PWM1_Stop();
    
    Notes

    None.

    PWM_FTMx_Init

    Prototype

    unsigned int PWM_FTMx_Init(unsigned int freq_hz, unsigned int config, unsigned int channel, Module_Struct* module);

    Description

    Initializes the Kinetis PWM module.

    Parameters
    • freq_hz: desired PWM frequency in Hz.
    • config: configuration of the PWM module.
      Description Predefined library const
      Input compare _PWM_INPUT_COMPARE
      Output compare _PWM_OUTPUT_COMPARE
      Egde-aligned PWM _PWM_EDGE_ALIGNED_PWM
      Center-aligned PWM _PWM_CENTER_ALIGNED_PWM
      Combined PWM _PWM_COMBINED_PWM
      Dual edge capture _PWM_DUAL_EDGE_CAPTURE
    • channel: desired PWM channel :
      Description Predefined library const
      Channel 0 _PWM_CHANNEL0
      Channel 1 _PWM_CHANNEL1
      Channel 2 _PWM_CHANNEL2
      Channel 3 _PWM_CHANNEL3
      Channel 4 _PWM_CHANNEL4
      Channel 5 _PWM_CHANNEL5
      Channel 6 _PWM_CHANNEL6
      Channel 7 _PWM_CHANNEL7
    • Module_Struct: appropriate module pinout. Use Code Assistant to list available module pinouts by typing _GPIO_Module_PWM and pressing Ctrl + Space.
    Returns

    This function returns calculated timer period.

    Requires
    • PWM library routines require you to specify the module you want to use. Simply change the letter x in the routine prototype for a number from 0 to 3.
    Example
    PWM_FTM0_Init(800,_PWM_EDGE_ALIGNED_PWM, _PWM_CHANNEL_1, &_GPIO_Module_PWM0_PTA4);
    
    Notes

    None.

    PWM_FTMx_Set_Duty

    Prototype

    unsigned int PWMx_Set_Duty(unsigned int duty_ratio, unsigned int inverted, unsigned int channel);

    Description

    The function changes the Kinetis PWM module duty ratio.

    Parameters
    • duty: PWM duty ratio. Valid values: 0 to timer period returned by the PWM_FTMx_Init function.
    • inverted: inverted and non inverted PWM signals. Valid values :
      Inverted parameter
      Description Predefined library const
      Inverted PWM signal _PWM_INVERTED
      Non-inverted PWM signal _PWM_NON_INVERTED
    • channel: desired PWM channel :
      Description Predefined library const
      Channel 0 _PWM_CHANNEL0
      Channel 1 _PWM_CHANNEL1
      Channel 2 _PWM_CHANNEL2
      Channel 3 _PWM_CHANNEL3
      Channel 4 _PWM_CHANNEL4
      Channel 5 _PWM_CHANNEL5
      Channel 6 _PWM_CHANNEL6
      Channel 7 _PWM_CHANNEL7
    Returns

    Nothing.

    Requires
    • PWM mode must be properly initialized. See PWM_FTMx_Init routine.
    • PWM library routines require you to specify the module you want to use. To select the desired module, simply change the letter x in the routine prototype for a number from 0 to 3.
    Example
    PWM_FTM0_Set_Duty(90,_PWM_INVERTED,_PWM_CHANNEL_1);
    
    Notes

    None.

    PWM_FTMx_Start

    Prototype

    void PWM_FTMx_Start(unsigned int channel);

    Description

    Starts Kinetis PWM module for a desired channel.

    Parameters
    • channel: desired PWM channel :
      Description Predefined library const
      Channel 0 _PWM_CHANNEL0
      Channel 1 _PWM_CHANNEL1
      Channel 2 _PWM_CHANNEL2
      Channel 3 _PWM_CHANNEL3
      Channel 4 _PWM_CHANNEL4
      Channel 5 _PWM_CHANNEL5
      Channel 6 _PWM_CHANNEL6
      Channel 7 _PWM_CHANNEL7
    Returns

    Nothing.

    Requires
    • PWM mode must be properly initialized. See PWMx_Init routine.
    • PWM library routines require you to specify the module you want to use. To select the desired module, simply change the letter x in the routine prototype for a number from 0 to 3.
    Example
    sa// Start PWM1 module on channel 1
    PWM_FTM1_Start(_PWM_CHANNEL1);
    
    Notes

    None.

    PWM_FTMx_Stop

    Prototype

    void PWM_FTMx_Stop(unsigned int channel);

    Description

    This routine stops Kinetis PWM module.

    Parameters
    • channel: desired PWM channel :
      Description Predefined library const
      Channel 0 _PWM_CHANNEL0
      Channel 1 _PWM_CHANNEL1
      Channel 2 _PWM_CHANNEL2
      Channel 3 _PWM_CHANNEL3
      Channel 4 _PWM_CHANNEL4
      Channel 5 _PWM_CHANNEL5
      Channel 6 _PWM_CHANNEL6
      Channel 7 _PWM_CHANNEL7
    Returns

    Nothing.

    Requires
    • PWM mode must be properly initialized. See PWM_FTMx_Init routine.
    • PWM library routines require you to specify the module you want to use. To select the desired module, simply change the letter x in the routine prototype for a number from 0 to 3.
    Example
    // Stop PWM1 module on channel 1
    PWM_FTM1_Stop(_PWM_CHANNEL1);
    
    Notes

    None.

    PWM_SetExternalClockFreq

    Prototype

    void PWM_SetExternalClockFreq(unsigned char pwmModuleNum, unsigned long clockSource, unsigned long freq);

    Description

    The function sets the MSP432 PWM module clock.

    Parameters
    • pwmModuleNum: number of pwm/timer module. Values values 0..3.
    • clockSource: clock source seledction. Valid values :
      Clock source
      Description Predefined library const
      TimerX clockk _PWM_CFG_CLOCK_SRC_TAXCLK
      Internal clock _PWM_CFG_CLOCK_SRC_INCLK
    • freq: clock frequency of external source.
    Returns

    Nothing.

    Requires

    Nothing.

    Example
    
    
    Notes

    Call this function before Init if you want to use external clock as PWM clock source.

    PWMx_Init

    Prototype

    unsigned int PWMx_Init(unsigned long freq, unsigned long config, const Module_Struct *module);

    Description

    Initializes the MSP432 PWM module. Duty ration is set to 50% by default.

    Parameters
    • freq_hz: PWM frequency in Hz.
    • config: PWM configuration. Use OR operator to combine one value from each table :
      Clock source
      Description Predefined library const
      TimerX clockk _PWM_CFG_CLOCK_SRC_TAXCLK
      Auxiliary clock _PWM_CFG_CLOCK_SRC_ACLK
      Low-speed subsystem master clock _PWM_CFG_CLOCK_SRC_SMCLK
      Internal clock _PWM_CFG_CLOCK_SRC_INCLK
      Output Mode
      Description Predefined library const
      Outbit mode _PWM_CFG_OUTPUTMODE_OUTBITVALUE
      Set mode _PWM_CFG_OUTPUTMODE_SET
      Reset mode _PWM_CFG_OUTPUTMODE_TOGGLE_RESET
      Set/Reset mode _PWM_CFG_OUTPUTMODE_SET_RESET
      Toggle mode _PWM_CFG_OUTPUTMODE_TOGGLE
      Reset mode _PWM_CFG_OUTPUTMODE_RESET
      Toggle/set mode _PWM_CFG_OUTPUTMODE_TOGGLE_SET
      Reset/Set mode _PWM_CFG_OUTPUTMODE_RESET_SET
      Channel
      Description Predefined library const
      Channel 1 _PWM_CFG_CHANNEL_1
      Channel 2 _PWM_CFG_CHANNEL_2
      Channel 3 _PWM_CFG_CHANNEL_3
      Channel 4 _PWM_CFG_CHANNEL_4
      Channel 5 _PWM_CFG_CHANNEL_5
    • module: appropriate module pinout. Use Code Assistant to list available module pinouts by typing _GPIO_MODULE_PWM and pressing Ctrl + Space.
    Returns

    This function returns calculated Timer CCR value.

    Requires
    • PWM library routines require you to specify the module you want to use. Simply change the letter x in the routine prototype for a number from 0 to 3.
    Example
    ratio = PWM0_Init(25000, _PWM_CFG_CLOCK_SRC_SMCLK | _PWM_CFG_OUTPUTMODE_SET | _PWM_CFG_CHANNEL_1, &_GPIO_MODULE_PWM_TA0_1_A12);                       
    
    Notes

    Timer CCR value is max value for duty.

    PWMx_Set_Duty

    Prototype

    void PWMx_Set_Duty(unsigned int duty, unsigned long channel);

    Description

    The function changes the MSP432 PWM module duty ratio.

    Parameters
    • duty: PWM duty ratio. Valid values: 0 to timer period returned by the PWMx_Init function.
    • channel: PWM channel. Valid values :
      Channel
      Description Predefined library const
      Channel 1 _PWM_CFG_CHANNEL_1
      Channel 2 _PWM_CFG_CHANNEL_2
      Channel 3 _PWM_CFG_CHANNEL_3
      Channel 4 _PWM_CFG_CHANNEL_4
      Channel 5 _PWM_CFG_CHANNEL_5
    Returns

    Nothing.

    Requires
    • PWM mode must be properly initialized. See PWMx_Init routine.
    • PWM library routines require you to specify the module you want to use. To select the desired module, simply change the letter x in the routine prototype for a number from 0 to 3.
    Example
    // Set channel 1 duty ratio to 50%:
    unsigned int pwm_period1;
    ...
    PWM0_Set_Duty(pwm_period1/2, _PWM_CFG_CHANNEL_1);
    
    Notes

    None.

    PWMx_Start

    Prototype

    void PWMx_Start();

    Description

    Starts MSP432 PWM module.

    Parameters

    None.

    Returns

    Nothing.

    Requires
    • PWM mode must be properly initialized. See PWMx_Init routine.
    • PWM library routines require you to specify the module you want to use. To select the desired module, simply change the letter x in the routine prototype for a number from 0 to 3.
    Example
    // Start PWM1 module
    PWM1_Start();
    
    Notes

    None.

    PWMx_Stop

    Prototype

    void PWMx_Stop();

    Description

    This routine stops MSP432 PWM module.

    Parameters

    None.

    Returns

    Nothing.

    Requires
    • PWM mode must be properly initialized. See PWMx_Init routine.
    • PWM library routines require you to specify the module you want to use. To select the desired module, simply change the letter x in the routine prototype for a number from 0 to 3.
    Example
    // Stop PWM1 module
    PWM1_Stop();
    
    Notes

    None.

    Copyright (c) 2002-2019 mikroElektronika. All rights reserved.
    What do you think about this topic ? Send us feedback!
    Want more examples and libraries? 
    Find them on LibStock - A place for the code