how to change duty cycle?

Started by mazeltob May 10, 2007
hi... i am still very new here.....

i have a question, which should be very basic to all of you.

what i ask is that how to change duty cycle in PWM. i know we need to
update the value of CCRx to match the counter value.

this is done in one PWM cycle. what if i wanna change this CCRx value
for next PWM cycle to have other Duty Cycle? is it done by software or
hardware?

what i guess is that the very last overflow of one pwm cycle generates
interrupt that is fed to execute software line to write a new value to
CCRx. is it correct?

and how can we know the exact value to a certain Duty Cycle to generate?
for example, i wanna to have duty cycle from 30% 50% 55% 60% 62%. the
values for each duty cycle are already defined somewhere (like a table
to refer) and software reads them to write?

Please help me out with this questions...

Thanks in advance.

sonny
Set the timer value to determine the period and the capture value to
determine the duty cycle.

Generally these two values are stored in RAM by the applications software. A
Timer
overflow reads the two values and sets the timer register to the period and
the capture
register to the duty cycle.

You could use a table but that is not very efficient. If you want 50% just
shift period value right once
and put it in the capture register.

Crane

mazeltob wrote:
>
> hi... i am still very new here.....
>
> i have a question, which should be very basic to all of you.
>
> what i ask is that how to change duty cycle in PWM. i know we need to
> update the value of CCRx to match the counter value.
>
> this is done in one PWM cycle. what if i wanna change this CCRx value
> for next PWM cycle to have other Duty Cycle? is it done by software or
> hardware?
>
> what i guess is that the very last overflow of one pwm cycle generates
> interrupt that is fed to execute software line to write a new value to
> CCRx. is it correct?
>
> and how can we know the exact value to a certain Duty Cycle to generate?
> for example, i wanna to have duty cycle from 30% 50% 55% 60% 62%. the
> values for each duty cycle are already defined somewhere (like a table
> to refer) and software reads them to write?
>
> Please help me out with this questions...
>
> Thanks in advance.
>
> sonny
>

--
Set the timer value to determine the period and the capture value to
determine the duty cycle.

Generally these two values are stored in RAM by the applications software. A
Timer
overflow reads the two values and sets the timer register to the period and
the capture
register to the duty cycle.

You could use a table but that is not very efficient. If you want 50% just
shift period value right once
and put it in the capture register.

Crane

mazeltob wrote:
>
> hi... i am still very new here.....
>
> i have a question, which should be very basic to all of you.
>
> what i ask is that how to change duty cycle in PWM. i know we need to
> update the value of CCRx to match the counter value.
>
> this is done in one PWM cycle. what if i wanna change this CCRx value
> for next PWM cycle to have other Duty Cycle? is it done by software or
> hardware?
>
> what i guess is that the very last overflow of one pwm cycle generates
> interrupt that is fed to execute software line to write a new value to
> CCRx. is it correct?
>
> and how can we know the exact value to a certain Duty Cycle to generate?
> for example, i wanna to have duty cycle from 30% 50% 55% 60% 62%. the
> values for each duty cycle are already defined somewhere (like a table
> to refer) and software reads them to write?
>
> Please help me out with this questions...
>
> Thanks in advance.
>
> sonny
>

--
hi... i am still very new here.....

i have a question, which should be very basic to all of you.

what i ask is that how to change duty cycle in PWM. i know we need to
update the value of CCRx to match the counter value.

this is done in one PWM cycle. what if i wanna change this CCRx value
for next PWM cycle to have other Duty Cycle? is it done by software or
hardware?

what i guess is that the very last overflow of one pwm cycle generates
interrupt that is fed to execute software line to write a new value to
CCRx. is it correct?

and how can we know the exact value to a certain Duty Cycle to generate?
for example, i wanna to have duty cycle from 30% 50% 55% 60% 62%. the
values for each duty cycle are already defined somewhere (like a table
to refer) and software reads them to write?

Please help me out with this questions...

Thanks in advance.

sonny