An AVR PWM subtlety


LilyTiny SparkFun

The original idea was not to use Arduino with the Arduino programming language, which resilts in rather slow PWM outputs, but to use Arduino hardware and assembler-code the PWM bit which can yield waveforms at hundreds of kHz.

Anyway, it transpires that setting an AVR counter to ‘fast PWM’ mode can result in an output frequency a fraction off from the one expected.

Luckily, has a clear explanation why (scroll down).

It transpires that the reference clock is divided by one more than the number you put in the appropriate register.

Do have a look, many AVRs have excellent flexible fast PWMs.

The picture is SparkFun’s LilyTiny, which can source one complementary pair of PWM waveforms and a single PWM waveform (portB bit4 is not bought out, so no complement).


Source link

Leave a Reply