believe it all. comparing the ice tube to an arduino is like comparing a granny smith to a jonathan. they're both apples, but different, you know?
pwm frequency is dependent on how the avr timer registers are set up. along with the clock speed of the microcontroller there are a couple of other relevant parameters. each timer has a prescaler by which the mcu clock is divided and a top value which determines how many prescaled clock cycles occur in each pwm cycle. timers can also be configured for single or dual slope mode. a dual slope pwm wave form will have a frequency a little higher than half that of a single slope wave form.
for a single slope pwm mode the pwm frwquency is f_cpu / prescaler / top. where f_cpu is the clock frequency at which the mcu is running, (16MHz for most arduini and 8MHz for the ice tube and some arduini).
on the ice tube the prescaler is set to 1, (this is what is meant by clock divider turned off), the top value is 256 and a single slope mode has been selected so,
joe426 wrote:The PWM output speed of the microcontroller is F_CPU / 256 = 8 MHz / 256 = 31.25KHz (period of 32 useconds)
as i said.
mtbf0 wrote:if you choose to pursue this project, the
avr datasheet will turn out to be your best friend.
on the arduino a prescaler of 64 is selected for each of the timers. timer0 is configured for single slope operation and timer1 and timer2 are confirgured for dual slope operation. the top value for all timers is 256.
this gives a pwm frequency on timer0, (which controls the pwm on pins 5 and 6), of 16MHz / 64 / 256 = 976.5625Hz, which is what the arduino uses for its timing functions.
timer1 and timer2 use dual slope operation since it is preferred for motors. for dual slope operation the pwm frequency will be f_cpu / prescaler / ((top - 1) * 2), so for pwm on pins 3, 9, 10 and 11 will be 16000000 / 64 / 510 or 490.196078431Hz.
did i mention the
data sheet?
amongst the stuff in your arduino installation is a file called wiring.cpp. if you can figure out where arduino is installed on your system, it'll be at arduino-0021/hardware/arduino/cores/arduino/wiring.cpp. that's where i started learning about pwm. then i read the
data sheet. then i read it again and again and again, but i'm a little slow.
i suggest you also peruse the source code for the ice tube.
it's early. although i have reread this post there are likely typos in it. gotta go to work, now.
"i want to lead a dissipate existence, play scratchy records and enjoy my decline" - iggy pop, i need more