sub_pwm_set

Top  Previous  Next
Got to SUB-20 page

Synopsis

int sub_pwm_set( sub_handle hndl, int pwm_n, int duty )

 

Configure specific PWM output.

Parameters

pwm_n - number of PWM output to configure. Can be 0..7.

duty - Duty cycle in range 0..255

Duty cycle

If duty cycle is 0, PWM output will be constantly low

If duty cycle is grater or equal to the limit set by sub_pwm_config, PWM output will be constantly high

 

Effective duty cycle in percent can be calculated as

 

DUTY% = duty/limit * 100%

 

Duty cycle resolution in bits depends on limit. It can be in range of 1 bit for limit=2 up to 8 bit for limit=255

Return value

On success function returns 0. Otherwise error code.

Example

 

/* Set PWM resolution=10ms, limit=100, frequency=1Hz */

sub_pwm_config( hndl, 10000, 100 );

 

/* Set PWM_0 pin (GPIO24) to output state */

sub_gpio_config( hndl, 0x01000000, &config, 0x01000000 );

 

/* Output 50% duty cycle on PWM_0 pin */

sub_pwm_set( hndl, 0, 50 );

See also

sub_pwm_config

Error Codes

Compatibility

FW version

0.1.8 or grater

Library version

0.1.12.10 or grater