Adafruit is open, safely ... and shipping all orders at this time! Read more!
0

PWM higher resolution?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

PWM higher resolution?

by Fp on Tue Jul 15, 2008 5:26 pm

Hello, new to the forum and uCs, having a blast w arduino (boarduino) on a macbook.

I am working on a control voltage program that interfaces with analog circuitry and I'm having resolution problems with 8bit pwm, any improvement over that should solve it.

The issue comes down to having more than 255 steps for the analog voltage control, 1024 would be a lot better in my application, I guess the higher the better.

Ideal situation would be the equivalent of 'analogwrite(1024)' so to speak. That would drop right in my code, but that's just wishful thinking, any help in what direction to look for the answer would be appreciated.

Fp
Fp
 
Posts: 2
Joined: Tue Jul 15, 2008 1:01 pm

by mtbf0 on Tue Jul 15, 2008 8:48 pm

timer1, which controls two of the pwm channels on the arduino is based on a 16 bit counter. taking control of it is not a big deal, so if you only need two channels that might be the way to go.
"i want to lead a dissipate existence, play scratchy records and enjoy my decline" - iggy pop, i need more
User avatar
mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am
Location: oakland ca

by Fp on Wed Jul 16, 2008 9:52 am

Yes, that would definitely work. Where can I look for on how to take control of that 16bit counter? I've been searching but I'm sure I'm missing it.

Thank you.
Fp
 
Posts: 2
Joined: Tue Jul 15, 2008 1:01 pm

by mtbf0 on Wed Jul 16, 2008 5:22 pm

you'll want to have a look at the atmega168 datasheet. a wonderful, if daunting document. it reveals all the details that the arduino environment strives to hide from you.

i have a couple of projects that use timer1, though not in the way you intend to.

see these posts

and these.

the timer code is in the setup routine and in the isrs. to do pwm you don't need an interrupt handler. just stick values in the appropriate registers when you want to change the duty cycle.

another interesting thing to study is the wiring code for pwm on the arduino itself. this can be found in arduino-010/hardware/cores/arduino/. the timer initialization is in the file wiring.c and the code to set the pwm duty cycle is in the file wiring_analog.c.

any more questions, just ask. for some reason i love this stuff.[/url]
"i want to lead a dissipate existence, play scratchy records and enjoy my decline" - iggy pop, i need more
User avatar
mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am
Location: oakland ca

Please be positive and constructive with your questions and comments.