[En-Nut-Discussion] RE: Control function to drive a RC servo
azummo-enutdisc at towertech.it
Wed Jun 11 01:22:27 CEST 2003
On Wed, 11 Jun 2003 00:39:41 +1000
"ptlinux" <ptlinux at optushome.com.au> wrote:
> 1. Timer0 is 8-bit with PWM but according to Harald it is been use by
> the OS. Timer1/Timer3 are 16-bit timer... So it will give me higher
> resolution or accuracy I should say?!
> 2. I don't really understand what how to use the attributes TOP, OCR3A
> and ICR3 mean.. I know they are registers but I don't see how it can be
> used in the context of creating PWM...
> It seems like I need to be comparing against an input value... And TOP
> is the point which I trigger an interrupt?! Sorry.. It is very vague to
> me... Can you please explain more. I couldn't find an example in the
> datasheet which refers to theses values to create a PWM.
> The period of my PWM is 20ms, my required wave form is as follows.. How
> does TOP, OCR3A and ICR3 comes into play?!
> * between 1ms-2ms
> |--| |--|
> ------| |--------| |.........
> | 20 ms |
The timer counts from BOTTOM (0) to TOP (the value you put in ICR3)
and rolls over.
To calculate the value for ICR3 you need to use the formula in the datasheet, which
takes into account the system frequency and the prescaler setting.
See the description on page 121-123 of the datasheet.
This gives you the frequency,
now you need to set the PWM duty cycle. For a 50% duty cycle, you can set
OCR3A = ICR3 / 2.
Adjust accordingly to your needs.
> 3. I don't think I will using an OVERFLOW (ISR).. Because the dutycycle
> (1ms-2ms) will be controlled by user... I am planning to allow user to
> input + or - to ethernut... And + and - will increment/decrement the
> dutycycle accordingly. Therefore think I need to write a custom ISR say
> and register it as say INT0 (interrupt vector) and in the ISR modify the
The you can keep ICR constant and only adjust OCR3A in your main cycle,
you don't even have to use interrupts. If you want to be very clean,
you can change OCR3A on the OVERFLOW interrupt.
Tower Technologies - Turin, Italy
More information about the En-Nut-Discussion