chipKIT® Development Platform

Inspired by Arduino™

Interrupts and Timers

Created Fri, 05 Aug 2011 02:15:14 +0000 by ksoth


Fri, 05 Aug 2011 02:15:14 +0000


I am working on a project that I had intended to use an Arduino Mega for. However, in my tinkering I discovered that the Arduino, although having plenty of I/O ports, is just not fast enough to do what I need. So, when I saw the 80 MHz clock of this board with the advertisement of Arduino compatibility, I scooped it up in no time.

I have read the forums and have learned that compatibility is limited. For the most part, it shouldn't be a problem. All I really need are interrupts and basic I/O. However, I need to run some timing tests on I/O operations to actually make sure this board has what it takes.

My previous timing test was quite simple. When the interrupt occured, just set TCNT1 to zero, perform a few operations, then serial out the value of TCNT1 after the operations complete so I can read the value in the serial monitor.

I would like to do this for the chipKIT board, but when I try to use the same libraries as with the Arduino, avr/interrupt.h and avr/io.h, the upload fails due to them missing.

I have looked a bit through the forums but didn't find any resolution.

Anyone know how to get interrupts working? Also, what are the name(s) of the counters?

Thanks in advance, Mike


Fri, 05 Aug 2011 02:56:02 +0000

For interrupts you could use the Arduino function attachInterrupt(), but this is not implemented yet (thread).

For timers have a look at the changes I made for my attempt at SoftPWM, and the Servo thread. You need the "PIC32 Peripheral Libraries for MPLAB C32 Compiler" manual and the "PIC32 Family Reference Manual", which should be linked from the boards' product pages.


Fri, 05 Aug 2011 03:11:30 +0000


Thanks. I seem to have found it in another post, too, where someone posted a servo sketch.

Seems to be working OK! And I think the board will be plenty fast enough. Only about 60 clock cycles per DigitalWrite, .75 us at 80 MHz, compared to the Arduino's 75 cycles, 4.7 us. So about 6 times faster. Woo!

Thanks, Mike