PWM or I/O setting

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hello,

i try actually pwm_tones from SDK v2.0.1. I know already how to set the PWM frequency. But i still don't understand, how can i set the pin.

On the image we can see, that the pin for 5s always on (High) and 4s always off (low). The time is defined by a random generator.

How/Where can i change it?

scope_20.png

0 Likes
1 Solution
asridharan
Employee
Employee
10 comments on KBA 5 comments on KBA First comment on KBA

This is probably because sleep is enabled by default in SDK 2.x and PWM with PMU_CLK as the reference clock will not function when sleeping.

Change the pwm_tones app to use LHL_CLK instead (for example: pwm_start(PWM0, LHL_CLK, toggle_value, init_value); ), which has a fixed reference of ~128KHz instead of the aclk generated reference (so you may have to change the init and toggle values to generate the same PWM frequency). When reference clock is LHL_CLK, the PWM will continue to function in sleep.

View solution in original post

5 Replies
asridharan
Employee
Employee
10 comments on KBA 5 comments on KBA First comment on KBA

This is probably because sleep is enabled by default in SDK 2.x and PWM with PMU_CLK as the reference clock will not function when sleeping.

Change the pwm_tones app to use LHL_CLK instead (for example: pwm_start(PWM0, LHL_CLK, toggle_value, init_value); ), which has a fixed reference of ~128KHz instead of the aclk generated reference (so you may have to change the init and toggle values to generate the same PWM frequency). When reference clock is LHL_CLK, the PWM will continue to function in sleep.

Anonymous
Not applicable

thanks for your reply. now it's work find.

Can you tell me, how can i calculate the PWM freq (init & toggle value)? and how can i change the duty cycle?

0 Likes
Anonymous
Not applicable

aclk_configure() and pwm_start() are used for PWM configuration.

The base frequency can be defined by 1st argument of aclk_configure().

Each clock (from the base frequency) increments internal counter.

Ex.) below code defines base frequency as 2kHz.

     aclk_configure(2000, ACLK1, ACLK_FREQ_24_MHZ);

PWM frequency is generated by the base frequency and 4th argument of pwm_start() as InitCount.

The internal counter starts from InitCount to 0x03ff. When it reaches 0x03ff, it will back to InitCount.

Ex.) below code generates PWM frequency as 2Hz.

     pwm_start(PWM0, PMU_CLK, 0x03eb, 0x0018);     // 1000 * 2kHz = 2Hz(500ms)

Ex.) below code generates PWM frequency as 100Hz.

     pwm_start(PWM1, PMU_CLK, 0x03ec, 0x03ec);     // 20 * 2kHz = 100Hz(10ms)

Duty cycle can be changed by 3rd argument of pwm_start() as toggleCount.

Ex.) 2Hz example shows 490ms and 10ms cycle     // (0x03ff-0x03eb=)20 * 2kHz = 10ms)

Anonymous
Not applicable

Thanks. Now i can set the pwm as i want

0 Likes
Anonymous
Not applicable

Hi zefry and dmiya

I am Also Working On PWM. I am able to generate the PWM At particular Frequency and duty cycle. But I am not able to Generate Frequently.

I.E.
Say I waned to Send a data stream (e.g. 1001010 ) through PWM. But I was Not able to send those stream.
Will You please help me Out with Your guidance.

Thanking You.,
Hinesh

0 Likes