![]() |
mikroSDK Reference Manual
|
PWM Hardware Abstraction Layer API Reference. More...
Functions list | |
| void | hal_pwm_configure_default (hal_pwm_config_t *config) |
| Configure PWM configuration structure. More... | |
| err_t | hal_pwm_open (handle_t *handle, bool hal_obj_open_state) |
| Open the PWM HAL object on selected pin. More... | |
| err_t | hal_pwm_set_freq (handle_t *handle, hal_pwm_config_t *config) |
| Set PWM frequency in Hertz. More... | |
| err_t | hal_pwm_start (handle_t *handle) |
| Start PWM HAL context object. More... | |
| err_t | hal_pwm_set_duty (handle_t *handle, float duty_ratio) |
| Set PWM duty cycle in percentages. More... | |
| err_t | hal_pwm_stop (handle_t *handle) |
| Stop PWM module. More... | |
| err_t | hal_pwm_close (handle_t *handle) |
| Close PWM HAL object. More... | |
API for configuring and manipulating PWM HAL module.
| void hal_pwm_configure_default | ( | hal_pwm_config_t * | config | ) |
Configures structure to default init values. Take into consideration that this is just structure variable initial values setting. Values need to be redefined by user.
| [in,out] | config | PWM HAL configuration settings. See hal_pwm_config_t structure definition for detailed explanation. |
Default values:
| Function | Default value |
|---|---|
| PWM pin | HAL_PIN_NC (invalid pin) |
| Frequency in Hz | 0 (Frequency set to 0) |
Example
| err_t hal_pwm_open | ( | handle_t * | handle, |
| bool | hal_obj_open_state | ||
| ) |
Opens the PWM HAL object on selected pin. Allocates memory and pin for specified object.
| [in,out] | handle | PWM handle. See hal_pwm_t structure definition for detailed explanation. |
| [in] | hal_obj_open_state | PWM state, is it open or not. |
Example
| err_t hal_pwm_set_freq | ( | handle_t * | handle, |
| hal_pwm_config_t * | config | ||
| ) |
This function is used to set the PWM frequency, it stops PWM module and sets duty cycle on 0. Take into consideration that the module will be re-initialized on the hardware level.
| [in] | handle | PWM handle. See hal_pwm_t structure definition for detailed explanation. |
| [in] | config | PWM configuration structure. See hal_pwm_config_t structure definition for detailed explanation. |
Example
| err_t hal_pwm_start | ( | handle_t * | handle | ) |
Initializes PWM module on hardware level, if not already initialized and starts PWM module.
| [in] | handle | PWM handle. |
Example
| err_t hal_pwm_set_duty | ( | handle_t * | handle, |
| float | duty_ratio | ||
| ) |
Set PWM duty cycle in percentages. The user should enter the duty_ratio in percentages. The duty_ratio value should be between 0 and 1, (where 0 represents 0% and 1 represents 100%). If the user sets value for duty_ratio to be less than 0, duty_ratio is automatically set to 0(0%), and If the user sets value for duty_ratio to be greater than 1, duty_ratio is automatically set to 1(100%).
| [in] | handle | PWM handle. |
| [in] | duty_ratio | PWM duty_ratio. |
Example
| err_t hal_pwm_stop | ( | handle_t * | handle | ) |
Disable output for specific PWM module.
| [in] | handle | PWM handle. |
Example
| err_t hal_pwm_close | ( | handle_t * | handle | ) |
De-allocates hardware resources for specific HAL object and de-initializes the module on a hardware level.
| [in,out] | handle | PWM handle. |
Example