# Calculating interrupt frequencies and speed?

Created Sat, 10 Nov 2012 22:27:09 +0000 by rasmadrak

Sat, 10 Nov 2012 22:27:09 +0000

Hi there!

Thought I'd check up on using interrupts for performing various tasks, such as periodic updates etc.

How does one calculate what values to use for a specific refreshrate? Is it possible to have a timer at 70 hz?

Sat, 10 Nov 2012 22:42:19 +0000

I found this example by someone called Ryan - 80000000MHz / (256 * 6250) = 50 Hz (trigger for the interrupt)

So far it seems correct when used with: OpenTimer1(T1_ON | T1_PS_1_256 | T1_SOURCE_INT, 6249); ConfigIntTimer1(T1_INT_ON | T1_INT_PRIOR_1);

:)

### EmbeddedMan

Sun, 11 Nov 2012 17:41:56 +0000

You can have timer interrupts fire at any speed from super, super slow (once per year or more) all the way to about 300KHz. You can go a bit faster, but your ISR has to be VERY short and very clean, and you won't have a whole lot of CPU time for many other things. (Which is just fine for some applications.) Your 70Hz is easily achievable and very easy to do.

The example that rasmadrak showed is a very good way to do it (set up Timer1 to fire at your rate, and then create a Timer1 ISR function).

Another way to do it is to use the Core Timer functions built into MPIDE that allow you to execute a function at a periodic rate. See [url]http://www.chipkit.org/wiki/index.php?title=Core_Timer_Service_Overview[/url]

*Brian

Sun, 11 Nov 2012 21:01:56 +0000

Awesome! I didn't know about that one! :)

### doc_norway

Wed, 28 Nov 2012 19:22:10 +0000

You can have timer interrupts fire at any speed from super, super slow (once per year or more) all the way to about 300KHz. You can go a bit faster, but your ISR has to be VERY short and very clean, and you won't have a whole lot of CPU time for many other things. (Which is just fine for some applications.) Your 70Hz is easily achievable and very easy to do.

I have actually managed to get the (32bit) interrupts triggering at a consistent rate of 1MHz :) The ISR isvery short (output data to PortA, pulse one pin high/low, increase a variable, set variable to 0 if it has reached its max), and the main loop is only checking to see if someone has touched the touch screen.

But it is possible :)

/Henning

### EmbeddedMan

Thu, 29 Nov 2012 03:06:37 +0000

Holy fast batman. I've never tried a 1MHz ISR. That's amazing. Go PIC32!!! You only have 80 instructions between ISR invocations.

*Brian

### doc_norway

Thu, 29 Nov 2012 21:33:13 +0000

The biggest problem at these speeds are the inaccuracy of the main PIC32 crystal. When driving at 1MHz outputting a 50% duty cycle square wave I measure the output frequency to be 495.something KHz on one chipKit and 498.something KHz on another.

BTW: The output is done through a 10bit DAC :)

/Henning