Monday, February 10, 2014

Microcontroller Timer Frequency Calculator

Recently I needed to compute an appropriate frequency for a timer to proper modulate 38kHz with an ATTiny 13 . Made the computation and discover that the exact frequency cannot be reached with just the microcontroller without tampering with the OSCCAL and CLKPCE .
I needed to find the closest frequency to the target 38kHz (planned to use CTC on 2*38kHz = 76kHz, where CTC means: Clear Timer on Compare) that can be reached by using the timer (in hardware mode). Also I wanted to learn the basics for AngularJS . Below in this page is the resulted tool:

Usage Note: After you enter the base microcontroller clock source and the desired frequencies press the Compute Posibilities button. Look in the tables below for the resulted timer period, counter threshold and suggested prescalers configuration.

Note: Any feedback would be GREATLY appreciated. If you have suggestions how to improve this tool let me know. If you want to use this work in your site, please post a visible link to this blog page on your site page. Thank you!



UC Prescalers Timer

16 bit Timer

  • {{'1/'+Math.pow(2, sc.Scale)}}
  • {{'1/'+Math.pow(2, sc.Scale)}}
UC Base Frequency: Hz
Desired Frequencies:
  • Hz
Use this if not 0: ms
Least Common Multiple: Hz
Greatest Common Divisor: Hz

Sorting predicate = {{ResultsSort}}
Frequency (Hz) Timer Interval Timer Count UC Prescaler Timer Prescaler
{{result.FrequencyInHz}} {{result.TimerInterval}} {{result.TimerCount}} {{'1/'+Math.pow(2, result.UCPrescaler)}} {{'1/'+Math.pow(2, result.TimerPrescaler)}}
Frequency (Hz) Closest Frequency Error Timer Interval Timer Count UC Prescaler Timer Prescaler
{{result.FrequencyInHz}} {{result.FrequencyInHz + result.Error}} {{result.Error}} {{result.TimerInterval}} {{result.TimerCount}} {{'1/'+Math.pow(2, result.UCPrescaler)}} {{'1/'+Math.pow(2, result.TimerPrescaler)}}