[En-Nut-Discussion] RE: Control function to drive a RC servo

ptlinux ptlinux at optushome.com.au
Tue Jun 10 16:39:41 CEST 2003


>>Hello,

>> i suggest you to use Timer3. If i remember correct, it has 16bit PWM
with output on PE3.

>>  You have to configure PE3 as an output using bit 3 of the DDRE
register and fill ICR3 with the TOP 
>> value you need and use OCR3A  for PWM duty cycle.

>>  The ICR3 value is related to the frequency of your output, 
>> you will find the right formula in the atmega datasheet.

>>  You can then use an interrupt routine (OVERFLOW3 int)
>> to change the values and/or the time period.

>>  You can easily disable the output without disabling the timer  bu
temporarly turning PE3 to an input.

>>  There are a few chapter about the atmega timers on the datasheet.
They  may look difficult at a first >>sight but it's very important you
understand them.

 Feel free to ask if you need more help. 


-- 

 Best regards,

 Alessandro Zummo,
  Tower Technologies - Turin, Italy

  http://www.towertech.it


Alessandro,

Thanks for your detail... I have been reading the datasheet on the
timers... I am a bit confused about a few things... Hope you can help me
with it.

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  |
 

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
dutycycle. 

Thanks for your help...

PT 





More information about the En-Nut-Discussion mailing list