cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 4 MCU

Anonymous
Not applicable

Hi,

I want to change the duty cycle of an PWM  frequenctly  as per my requirement.

Can you tell me how to do it and also  tell me the how to calculate the duty cycle based on input clk frequency

Thanks in advance

0 Likes
Reply
1 Solution
JoMe_264151
Expert II

The PWM duty cycle is independent of the input frequency.

Duty Cycle in % = 100 * Period / Compare value

Both values can be changed by APIs, see the PWM datasheet.

Bob

View solution in original post

9 Replies
JoMe_264151
Expert II

The PWM duty cycle is independent of the input frequency.

Duty Cycle in % = 100 * Period / Compare value

Both values can be changed by APIs, see the PWM datasheet.

Bob

View solution in original post

Anonymous
Not applicable

Thanks Bob for reply

0 Likes
Reply
Anonymous
Not applicable

hI,

i want to generate a pwm dutycycle 20% to 90%  but these below apis

   PWM_WritePeriod(3);

PWM_WriteCompare(10); 

given the same waveform output  that is it's not working.

according to your formula  Duty Cycle in % = 100 * Period / Compare value 

but it's not working.

Please help me to resolve the issue.

Thnbaks in advance.

0 Likes
Reply
Anonymous
Not applicable

hI ,

i want to generate pwm for 10% duty cycle to 90% dutycycle .For every 10 seconds i am changing the period and compare value.

But no pwm output is coming i mean pwm getting stopped

please help me to generate duty cycle.

Thanks in adavance

0 Likes
Reply
Anonymous
Not applicable

in my code i removed the while(1);   it's not working

0 Likes
Reply
JoMe_264151
Expert II

Sorry, reziprok error:

Duty Cycle in % = 100 / Period * Compare value

or

Compare Value = Period * Duty cycle  in % / 100

See attached project

Bob

0 Likes
Reply
Anonymous
Not applicable

Thanks sir

0 Likes
Reply
Anonymous
Not applicable

Hi bob,

I attached  an snapshot of the pwm dutycycle.

According to your formula  ,the duty_cycle should  be 50% but  it shows the waveform in the configuration as a 70% dutycycle waveform.

compare value=1,period=2ms  ,ip frequency is 1000HZ .

please help me to resolve the issue.

Thanks in advance.

0 Likes
Reply
EmHo_296241
Contributor II

Hi

It is better to use the PWM block with higher counts(high period value) for higher accuracy. Other wise one clock cycle for toggle state can introduce this much error.

0 Likes
Reply