mikroSDK Reference Manual
|
PWM Driver API Reference. More...
Functions list | |
void | pwm_configure_default (pwm_config_t *config) |
Configure PWM config structure. More... | |
err_t | pwm_open (pwm_t *obj, pwm_config_t *config) |
Open the PWM driver object on selected pin. More... | |
err_t | pwm_set_freq (pwm_t *obj, uint32_t freq_hz) |
Set PWM frequency in Hertz. More... | |
err_t | pwm_start (pwm_t *obj) |
Enable counter and start PWM module. More... | |
err_t | pwm_set_duty (pwm_t *obj, float duty_ratio) |
Set PWM duty cycle in percentages. More... | |
err_t | pwm_stop (pwm_t *obj) |
Stop PWM module. More... | |
err_t | pwm_close (pwm_t *obj) |
Close PWM driver context object. More... | |
The PWM driver provides standard PMM functionality including setting the duty cycle and frequency.
void pwm_configure_default | ( | pwm_config_t * | config | ) |
Configures structure to default initialization values. Take into consideration that this is just structure variable initial values setting. Values need to be redefined by user.
[in,out] | config | PWM driver configuration settings. See pwm_config_t structure definition for detailed explanation. |
Default values:
Function | Default value |
---|---|
PWM pin | 0xFFFFFFFF (invalid pin) |
Frequency in Hz | 0 (Frequency set to 0) |
Example
err_t pwm_open | ( | pwm_t * | obj, |
pwm_config_t * | config | ||
) |
Opens the PWM driver object on selected pins. Allocates memory and pin for specified object.
[in,out] | obj | PWM driver object. See pwm_t structure definition for detailed explanation. |
[in] | config | PWM driver configuration settings. See pwm_config_t structure definition for detailed explanation. |
pwm_config_t
structure has been adequately filled out. See pwm_configure_default definition for detailed explanation. Example
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] | obj | PWM driver context object. See pwm_t structure definition for detailed explanation. |
[in] | freq_hz | PWM frequency in HZ. |
Example
Initializes PWM module on hardware level, if not already initialized and starts PWM module.
[in] | obj | PWM driver object. See pwm_t structure definition for detailed explanation. |
Example
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] | obj | PWM driver object. See pwm_t structure definition for detailed explanation. |
[in] | duty_ratio | PWM duty_ratio. |
Example
Disable output for specific PWM module.
[in] | obj | PWM driver object. See pwm_t structure definition for detailed explanation. |
Example
De-allocates hardware resources for specific driver object and de-initializes the module on a hardware level.
[in,out] | obj | PWM driver object. See pwm_t structure definition for detailed explanation. |
Example