Author Topic: webbotlib and PWM  (Read 2329 times)

0 Members and 1 Guest are viewing this topic.

Offline richiereynoldsTopic starter

  • Full Member
  • ***
  • Posts: 112
  • Helpful? 3
webbotlib and PWM
« on: February 11, 2010, 06:46:11 PM »
Hi there, just started using webbotlib, really like it, as a C++ programmer I feel right at home at this higher level.
Got a question about the PWM functionality. I'm using an ATMEGA328P and I have 4 servos, two modified for differential wheels and two unmodified for scanners.

I've only got one 16 bit timer though which outs through 2 pins so I can only control 2 of my servos (the scanning ones) using the built in PWM, I used the hardware method for this.

Was just wondering why the PWM functionality is limited to 16 bit timers? I understand the resolution won't be great on the 8 bit ones but it would probably do for modified wheels, and I've got two 8 bit timers doing nothing, which I imagine is fairly common looking at the specs of most of the cheap chips.

Cheers, Richard.

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: webbotlib and PWM
« Reply #1 on: February 11, 2010, 08:19:43 PM »
Hi Richard,
Thanks for your support and kind comments.

I think you are talking about PWM regarding servo, not DC motors, and why they need a 16 bit timer. Correct me if I'm wrong.
But on that assumption:-

A generic servo needs a pulse between 1ms and 2ms and you probably need 100 position settings between those.(Most servos can cope without about 90 different slots so 100 is a fair example.

The servo needs a pulse every 20ms.

So if 1ms (the difference between 2ms and 1ms) requires 100 slots. Then 20ms requires 2000 slots - even though only 10% of them are used.

An 8 bit timer can only measure 2^8 = 256 slots
Whereas a 16 bit timer can measure 2^16 =v 65,536 slots

So if a servo requires 2000 slots then an 8 bit timer just doesn't cut it with only 256. It would mean a servo would only have (2000 div 256 = 7) 7 distinct positions which is rubbish.

So the granularity for 8 bit timer is not good,

But, as you say, this is in the eye of the beholder. For a true servo then 7 positions is not good. For a continuous servo then you may not be able to tell the difference.

So: that is 'why' - but your point is valid, given some constraints.

So I will look into it.

-- edit --
But by the time you introduce a zero point then it may mean '3 reverse' and '3 forward' speeds


« Last Edit: February 11, 2010, 08:23:03 PM by Webbot »
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline richiereynoldsTopic starter

  • Full Member
  • ***
  • Posts: 112
  • Helpful? 3
Re: webbotlib and PWM
« Reply #2 on: February 12, 2010, 10:21:48 AM »
Oh yes, I totally understand your reasoning and in the vast majority of cases it's spot on.
Just that in this particular case, and I'd guess the same for a lot of beginners starting with the $50 robot or similar, 3 forward and 3 reverse speeds would be fine for diff drive.
Plus the way you've made it so easy to set up and kick off your PWM makes it very handy for prototyping and experimentation with other things without getting bogged down in any of those details. Which is why I think having those other timers available for easy (albeit low res) PWM operation would be a nice addition.

Mind you, I've ordered a nice AXON 2 now anyway, so looking forward to playing with that with much fewer constraints!

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: webbotlib and PWM
« Reply #3 on: February 13, 2010, 07:08:45 AM »
Quote
I'd guess the same for a lot of beginners starting with the $50 robot or similar, 3 forward and 3 reverse speeds would be fine for diff drive.
For a beginner, yea . . . but you can't do any form of smooth control, fuzzy logic, or PID with such a limitation :P

Offline KurtEck

  • Robot Overlord
  • ****
  • Posts: 217
  • Helpful? 12
Re: webbotlib and PWM
« Reply #4 on: February 14, 2010, 04:30:37 PM »
Another place that maybe an 8 bit timer for a PWM servo would be for something like the picoswitch (http://www.dimensionengineering.com/PicoSwitch.htm) or battleswitch.  For the most part they need the center position to not do anything and a Plus value to turn on the switch and a negative value to turn it off.

I may attach one of these on my bot soon...

Kurt

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: webbotlib and PWM
« Reply #5 on: February 15, 2010, 02:23:04 AM »
You could use the generic pwm stuff in pwm.h as that can use any timer.
You set up a 50Hz frequency (ie every 20ms)
Setting the duty cycle to 5(%) would give a 1ms pulse and values either side will give on or off.

You have to be slightly careful as the frequency is fixed for one timer ie you couldn't produce a 50Hz and a 75Hz frequency one 2 pwm channels for the same timer.
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

 


Get Your Ad Here

data_list