NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » Maximum PWM frequency?

May 08, 2010
by Frozenlock
Frozenlock's Avatar

I've recently browsed the Squirter tutorial and its C code.

It seems the output's state is triggered by a while loop in the Main part of the program.

while(1) {
pwm_set(pos);
// Print the current servo position to the LCD.
lcd_line_two();
fprintf_P(&lcd_stream, PSTR(" servo position: %d "), pos);

I can understand how it works for (relatively) low speed of 20ms, but what is the maximum attainable speed with this technique? I guess below half the clock's frequency. In addition, writing to the LCD must uses some available clock pulse...

Is there a way to know when this threshold is reached?

By the way, NO, I don't intend to drive motors at this speed! :-P Let's say it's a little brain teaser.

Thanks in advance!

Frozenlock

May 10, 2010
by hevans
(NerdKits Staff)

hevans's Avatar

Hi Frozenlock,

The servo squirter tutorial has a particular pulse frequency because the servo expects the pulses to be at least 20ms apart. Remember you are just commanding a position for a servo, not a speed.

If you want to consider strictly how fast you can make a PWM wave, the limiting factors are going to be your clock, and the resolution you want for your PWM duty cycle. With no prescaler on the timer, the timer will increase by 1 every tick of the 14.7456Mhz clock. On the 8 bit timers (on fast PWM mode, with top at 0xFF) the period of your PWM wave will be 2^8 clock cycles, and you have 256 bits of resolution inside that to vary your PWM. If you want to go faster you can set the TOP value to be something lower, but you will be losing possible resolution for your duty cycle.

Hope that answers your question.

Humberto

May 11, 2010
by Frozenlock
Frozenlock's Avatar

Thank you very much!

If I try to reduce the TOP value, is there a point where the output pin will be unable to comply?

May 11, 2010
by hevans
(NerdKits Staff)

hevans's Avatar

Hi Frozenlock,

That depends on what you are driving. Unloaded the pin will have no problem switching every other clock cycle. Once you are trying to drive something the characteristics of everything connected to the node will affect how fast you can switch it.

Humberto

Post a Reply

Please log in to post a reply.

Did you know that you can use printf and scanf functions to talk to your computer from your USB NerdKit? Learn more...