chipKIT® Development Platform

Inspired by Arduino™

Timer Interrupts for Chipkit Max32?

Created Mon, 19 Nov 2012 17:22:19 +0000 by RoboNegro


RoboNegro

Mon, 19 Nov 2012 17:22:19 +0000

Greetings all,

Does the Chipkit Max32 have internal timer compare match interrupts? If so, does anyone have example code for this?

I have code for an ArduinoMega that looks like:

void setup()
{
    Serial.begin(115200);
 
    // initialize Timer5
    cli();          // disable global interrupts
    TCCR5A = 0;     // set entire TCCR1A register to 0
    TCCR5B = 0;     // same for TCCR1B
 
    // set compare match register to desired timer count:
    //313 = 50 Hz
    //156 = 100 Hz
    //80 = 200 Hz
    OCR5A = 78;
    // turn on CTC mode:
    TCCR5B |= (1 << WGM52);
    // Set CS50, CS51, CS52 bits for prescaler value: 1024
    TCCR5B |= (1 << CS50);
    TCCR5B |= (0 << CS51);
    TCCR5B |= (1 << CS52);
    // enable timer compare interrupt:
    TIMSK5 |= (1 << OCIE5A);
    sei(); // enable global interrupts

}

I would like to adapt this code to the ChipKit.

Thanks


mkirby

Mon, 17 Dec 2012 21:27:24 +0000

You're going to want to check out the PIC32MX795F512L datasheet on Microchip's website. Look for the Output compare chapter. There is a little bit of sample code in there, they also should have example programs using this sort of idea. Unfortunately I myself do not have any example code for this at this time though.

-MKirby