PWM Functions - PalouseRobosub/SUBLIBinal GitHub Wiki

PWM Functions

This page describes the functions available within the PWM peripheral library of SUBLIBinal. Please select a function from the list below to read the appropriate documentation about it.

Functions


initialize_PWM

Definition

Error initialize_PWM(PWM_Config config);

Description
The initialize PWM function is used for the initialization of a PWM on a pin. The function will configure the specified pin and set it as an output. Please note, if an invalid pin is entered, a valid pin will be defaulted to. This can cause unexpected results if an invalid pin is entered.

Parameters

  • PWM_Config config: the config parameter should be a completely filled in configuration structure for the PWM module.

Return

This function will return the following error codes based upon success status:

  • ERR_INVALID_ENUM: This error code will be returned if the configuration does not specify timer_2 or timer_3. Only these two timers may be used for configuration.
  • ERR_INVALID_PIN: This error will be returned if an invalid pin for the pwm channel specified is selected.

top


enable_PWM

Definition

void enable_PWM(PWM_Channel channel);

Description
The enable PWM function will simply enable a PWM waveform on the specified PWM channel. No other configuration occurs within this function.

Parameters

  • PWM_Channel channel: this function accepts a single configuration parameter. The only value that must be present within the structure is a PWM_Channel so that the proper channel is enabled.

top


disable_PWM

Definition

void disable_PWM(PWM_Channel channel);

Description
This function will disable a PWM waveform on the specified PWM channel. No other configuration occurs within this function.

Parameters

  • PWM_Channel channel: This function accepts a single parameter. The channel specified will be used in determining which channel to disable.

top


update_PWM

Definition

Error update_PWM(PWM_Channel channel, Timer_Type timer, float dutyCycle);

Description
This function will change the duty cycle of the specified PWM channel in the configuration structure. This function does not interrupt PWM operation and will update the PWM duty cycle on the next available cycle.

Parameters

  • PWM_Channel channel: This parameter specifies which channel should be updated.
  • Timer_Type timer: This parameter specifies which timer the PWM should be sourced from.
  • float dutyCycle: This parameter should be the new duty cycle desired on the associated PWM channel.

Return

This function will return the following error codes based upon success status:

  • ERR_INVALID_ENUM: This error code will be returned if the configuration does not specify timer_2 or timer_3. Only these two timers may be used for configuration.
  • ERR_INVALID_PIN: This error will be returned if an invalid pin for the pwm channel specified is selected.

top