Society of Robots - Robot Forum

Software => Software => Topic started by: airman00 on January 22, 2009, 07:25:43 AM

Title: 8 bit Timer - Hardware Servo Control
Post by: airman00 on January 22, 2009, 07:25:43 AM
I know you have to use 16bit timers to control a servo , but I could have sworn that it is possible to use a 8 bit timer to control a servo as well through Hardware PWM.
Can someone please tell me how to control it through 8 bit PWM and what kind of resolution I could expect for an 8 bit hardware PWM ?
Title: Re: 8 bit Timer - Hardware Servo Control
Post by: want2learn on January 22, 2009, 04:00:24 PM
I have very little experience here but I'm going to throw in my tuppence anyway.

Does it really matter if the timer is 8 or 16 bit? I thought 16 bit was only really necessary for software pwm.

I thought the clock speed and timer speed (set with a prescaler right?) were what was important here. After all controlling the servos means generating a 1-2ms pulse at 50Hz.

I know I must be missing something
Title: Re: 8 bit Timer - Hardware Servo Control
Post by: TrickyNekro on January 22, 2009, 04:34:11 PM
Set the prescaler so you have a near 50Hz signal and do some math!!! :P

Suppose you have 20ms at 255 (overflow)
When it's 1ms you have.... well x =~ 13 and
When it's 2ms you have.... mm x =~ 26.....
So.... 13 steps.... quit poor... really....
Consider you have a 255 for 2ms and 128 for 1ms your have a 128 steps... well that's better....
But you have to generate the pause with software... sorry again...

Why don't you use a 16bit timer for many servo control via software and generic I/O :-X
Title: Re: 8 bit Timer - Hardware Servo Control
Post by: airman00 on January 22, 2009, 06:08:31 PM
But you have to generate the pause with software... sorry again...
is there anyway to have the pause to make a 20ms from hardware?
Title: Re: 8 bit Timer - Hardware Servo Control
Post by: airman00 on January 22, 2009, 06:32:26 PM
Looky what I found :
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1214327529/7#7
Title: Re: 8 bit Timer - Hardware Servo Control
Post by: Webbot on January 22, 2009, 08:57:38 PM
As TrickyNero says - it is possible to use the 8 bit timers for hardware PWM but the total travel of your servo will be split down into about 13 steps. Most servos have a resolution of about 90 steps. If you dont require fine position control then 8 bit timers are ok.
Title: Re: 8 bit Timer - Hardware Servo Control
Post by: want2learn on January 22, 2009, 11:46:46 PM
I'm not trying to hijack this thread but I thought that with hardware pwm you set the timer to give as near as dammit 50Hz signal, so the timer will count up then down and each up/down cycle will take 20ms (50Hz), then all you have to do in software is generate the 1-2ms pulse to the servo everytime the counter comes back to 0.

The idea of hardware pwm is so you're not generating pauses in software which in a hard working mcu can be a bit off.
How does this affect resolution ??

I have read up on this and thats my grasp, dunno if it's the wrong end of the stick again but I'm a bit confused now ???

Anyone suggest more reading material?

EDIT:- I answered my own questions with a bit of digging on SoR.
          Still, any suggested reading material would be appreciated. Thanks
Title: Re: 8 bit Timer - Hardware Servo Control
Post by: Webbot on January 25, 2009, 01:09:11 PM
Yeah, hardware PWM means no pauses, you just set up the PWM frequency and from then on you just write one register to change the servo pulse length. Other reading: http://www.societyofrobots.com/member_tutorials/node/228 (http://www.societyofrobots.com/member_tutorials/node/228)

Quote
The idea of hardware pwm is so you're not generating pauses in software which in a hard working mcu can be a bit off.
How does this affect resolution ??
The problem is that if you've got a 20ms (50Hz frequency) set up then, with an 8 bit timer, then 0 would be mean no pulse and 255 would be a pulse of 20ms. For a servo: the active range (roughly) is a pulse between 1ms and 2ms ie a range of 1ms out of 20ms. So 1/20th of the total. 255/20 = 12.5 which means that there are only 12,or 13 thirteen, different speed/position settings you can use.
Title: Re: 8 bit Timer - Hardware Servo Control
Post by: want2learn on January 25, 2009, 03:08:05 PM
Thanks Webbot, was wearing my confused hat over in the corner for a while.