Main Site Documentation

OutputCompare Example on Wiki.TinyClr Question



I’m trying to get through the wiki entry on OutputCompare.

The second example “Include PWM signal” has this paragraph about timing.

“Example, we will use frequency at 1KHz (1000Hz), it means the period time to execute Outputcompare in one time is 1000000000 / (1000 *1000) = 1000 microsecond = 1 milisecond.”

How do we get to the 1000000000 ? What does it represent?



it represents a large number ! :smiley:

If you look a bit at the code:

3.            //to make sure period time is microsecond
4.            uint period = ((uint)(1000000000 / frequency))/1000; 

It says microseconds. there are one million microsecs in a second, so that number means it is using one thousandth of a microsec, and i suspect that whoever authored that code is using that number so there’s less rounding error on the period calculation, as the number is divided by 1000 later, but after the division of the frequency.

So it’s ultimately saying:

[quote]period = ((microsecs_in_1sec * roundingfactor) / frequency) / roundingfactor

hope that helps