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

Alessandro Zummo azummo-enutdisc at towertech.it
Mon Jun 9 02:32:11 CEST 2003


On Mon, 9 Jun 2003 09:52:16 +1000
"ptlinux" <ptlinux at optushome.com.au> wrote:


> I've read the Post on
> http://www.egnite.de/pipermail/en-nut-discussion/2003-April/000690.html.
> Am I safe to assume that if I don't set Port E Pin 5 as out. .then I
> should be able to pick say Pin 1 as my PWM digital out?!
> 
> I have been reading the timer example. So what I need to do to generate
> the PWM is to create a TimerThread say for 2ms and sleep it for 20ms?
> 
> Do you have some example on how to achieve it? Do I still uses outp()
> for driving output pin high / low?!

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



More information about the En-Nut-Discussion mailing list