 # OutputCompare Example on Wiki.TinyClr Question

#1

Hey

I’m trying to get through the wiki entry on OutputCompare.
(http://wiki.tinyclr.com/index.php?title=Output_Compare)

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?

Thanks!

#2

it represents a large number ! 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
[/quote]

hope that helps