|
|
|
|
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
November 20, 2009, 08:22:34 PM
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Search:
Advanced search
Sept 30th - New Price -
Axon
is now $94
Robot Forum
72,665
Posts in
9,267
Topics by
5,289
Members
Latest Member:
rac34125
Robot Forum
>
Software
>
Software
>
New Tutorial : PWM on ATmega168
0 Members and 1 Guest are viewing this topic.
Pages:
[
1
]
Author
Topic: New Tutorial : PWM on ATmega168 (Read 4221 times)
airman00
Contest Winner
Supreme Robot
Helpful? 17
Offline
Posts: 3,607
narobo.com
New Tutorial : PWM on ATmega168
«
on:
November 30, 2008, 07:50:18 AM »
New Tutorial -
http://www.societyofrobots.com/member_tutorials/node/226
Can be used to give PWM capabilities to the 50 dollar robot board or any ATmega168.
feedback appreciated.
Logged
Check out the Roboduino, Arduino-compatible board!
Link:
http://curiousinventor.com/kits/roboduino
www.Narobo.com
mbateman
Full Member
Helpful? 0
Offline
Posts: 82
Re: New Tutorial : PWM on ATmega168
«
Reply #1 on:
November 30, 2008, 11:16:23 AM »
Good info, but you should make it clear in the tutorial that this is useful for PWM that does not care too much about the base freqency and can use the whole range of 0-100% duty cycles. It is not suitable for servo control since it is not the correct base freqency and with the 8 bit timers, does not have sufficient granularity for the 5-10% range that servos require. For things like your LED dimmer and direct H-bridge motor control, it is very useful, though.
Logged
airman00
Contest Winner
Supreme Robot
Helpful? 17
Offline
Posts: 3,607
narobo.com
Re: New Tutorial : PWM on ATmega168
«
Reply #2 on:
November 30, 2008, 11:20:08 AM »
Quote from: mbateman on November 30, 2008, 11:16:23 AM
Good info, but you should make it clear in the tutorial that this is useful for PWM that does not care too much about the base freqency and can use the whole range of 0-100% duty cycles. It is not suitable for servo control since it is not the correct base freqency and with the 8 bit timers, does not have sufficient granularity for the 5-10% range that servos require. For things like your LED dimmer and direct H-bridge motor control, it is very useful, though.
I'll copy and paste that into the tutorial right now
Logged
Check out the Roboduino, Arduino-compatible board!
Link:
http://curiousinventor.com/kits/roboduino
www.Narobo.com
Ro-Bot-X
Contest Winner
Supreme Robot
Helpful? 10
Offline
Posts: 1,117
Current project: MiniEric robot.
Re: New Tutorial : PWM on ATmega168
«
Reply #3 on:
November 30, 2008, 12:07:28 PM »
Too much cut and paste
For both Timer0 and Timer 2:
// 00 A off,
toggle on compare
should be:
// 00 A Off, pin works as general I/O
same for B...
// 11 Low part of WGM: PWM,
phase correct
should be:
// 11 Low part of WGM: PWM, Fast PWM
Then, when you set the pin On, you comment:
// 10 A on,
toggle on compare
should be:
// 10 - A On, set at Bottom, clear at compare match
//
5
B on,
toggle on compare
here instead of pin number 5, there should be the way you are setting the 2 bits for the channel B:
// 10 - B On, set at Bottom, clear at Compare match
There is no "Toggle on Compare", they should all be "Set at Bottom, Clear at Compare match" for all timers in the setup you are using.
Other than that, the functionality is good, just the comments are wrong. We don't want people to get confused, right?
Logged
Check out my new blog!
SeriousRobotics
Webbot
Expert Roboticist
Supreme Robot
Helpful? 26
Offline
Posts: 928
Re: New Tutorial : PWM on ATmega168
«
Reply #4 on:
November 30, 2008, 12:21:16 PM »
@airman00
Hey, I've started doing a tutorial on PWM as well. Didn't mean to step on your toes but my idea was to cover the subject generically - not just Mega168, Roboduino etc. Just that there seem to be loads of questions/misunderstandings about it.
Its up there but unfinished and is still work in progress.
Will eventually also cover doing PWM via software rather than hardware
Logged
My robot library:
http://sourceforge.net/projects/webbotavrclib
What I do:
http://www.inbrand.co.uk
airman00
Contest Winner
Supreme Robot
Helpful? 17
Offline
Posts: 3,607
narobo.com
Re: New Tutorial : PWM on ATmega168
«
Reply #5 on:
November 30, 2008, 12:22:38 PM »
yea you caught me RobotX , I'll edit the comments sometime today .
@Webbot
OK cool Looking forward to it
Logged
Check out the Roboduino, Arduino-compatible board!
Link:
http://curiousinventor.com/kits/roboduino
www.Narobo.com
Ro-Bot-X
Contest Winner
Supreme Robot
Helpful? 10
Offline
Posts: 1,117
Current project: MiniEric robot.
Re: New Tutorial : PWM on ATmega168
«
Reply #6 on:
November 30, 2008, 12:31:02 PM »
Can you also add a formula to convert the 0-255 value to 0-100 percentage? That way it doesnt matter if the timer is 8 or 16 bit...
So instead of writing:
pwmSet5(255); //pin6 which is 8 bit PWM
to write:
pwmSet5(100); //pin6 which is 8 bit PWM
I know this reduces the granularity, but sometimes is more usefull. Maybe a pwmPercentSet5(value) command?
«
Last Edit: November 30, 2008, 12:33:23 PM by Ro-Bot-X
»
Logged
Check out my new blog!
SeriousRobotics
Webbot
Expert Roboticist
Supreme Robot
Helpful? 26
Offline
Posts: 928
Re: New Tutorial : PWM on ATmega168
«
Reply #7 on:
November 30, 2008, 01:50:47 PM »
I recommend a general linear interpolation routine such as:
Code:
/*
*
Interpolate between two numbers
*
value - the current value to be used
* minVal - the minimum that 'value' can be
* maxVal - the maximum that 'value' can be
* minRtn - the return value if 'value = minVal'
* maxRtn - the return value if 'value = maxVal'
* return a value in the range minRtn to maxRtn
*/
int interpolate(int value, int minVal, int maxVal, int minRtn, int maxRtn){
long int lRtnRange = maxRtn - minRtn;
long int lValRange = maxVal - minVal;
long int lRelVal = value - minVal;
lRtnRange = minRtn + ( lRtnRange * lRelVal / lValRange );
return (int)lRtnRange;
}
Logged
My robot library:
http://sourceforge.net/projects/webbotavrclib
What I do:
http://www.inbrand.co.uk
Admin
Administrator
Supreme Robot
Helpful? 62
Offline
Posts: 8,610
Re: New Tutorial : PWM on ATmega168
«
Reply #8 on:
December 01, 2008, 11:58:27 PM »
I just added it to the $50 Robot tutorial.
Logged
subscribe to SoR's YouTube account
Pages:
[
1
]
Jump to:
Please select a destination:
-----------------------------
General Misc
-----------------------------
=> Misc
=> Robot Videos
-----------------------------
Software
-----------------------------
=> Software
-----------------------------
Electronics
-----------------------------
=> Electronics
-----------------------------
Mechanics and Construction
-----------------------------
=> Mechanics and Construction
Related Topics
Subject
Started by
Replies
Views
Last post
Atmega168 Timer1 PWM
Software
SomeSaba
5
1917
December 19, 2007, 07:15:49 PM
by
SomeSaba
need help with pwm in atmega168
Software
rox2007
8
2371
January 20, 2008, 07:46:40 AM
by
rox2007
Ponyprog and atmega168
Electronics
gamefreak
12
1601
January 29, 2008, 09:09:47 AM
by
JonHylands
ATMega168
Electronics
walkercreations
13
204
October 16, 2009, 04:29:51 AM
by
SmAsH
Advertise on this Forum
Loading...