Created Wed, 29 Feb 2012 23:52:44 +0000 by Mark597
Wed, 29 Feb 2012 23:52:44 +0000
On other projects I have used a Timer overflow interrupt to preform other tasks. I can see several posts that talk about setting up Timers and writting ISR's for various tasks. It there an include file I'm missing for functions like: OpenTimer2(T2_ON | T2_PS_1_1, 256); ConfigIntTimer2(); etc....
I have download code for projects that appear to work but I can't compile them in MPIDE. The compiler returns a NOT DECLARED IN THIS SCOPE error.
It's probably something I'm missing...
Thu, 01 Mar 2012 01:27:27 +0000
Hello,
#include <plib.h>
That library allows you to access all of Microchip's peripheral libraries. Although I find it easier just to modify the registers directly, saves me time looking for all the api calls and #defines that Microchip has.
http://ww1.microchip.com/downloads/en/DeviceDoc/PIC32MX_Datasheet_v2_61143B.pdf
Best Regards, Ryan K
Thu, 01 Mar 2012 12:30:20 +0000
Hello, #include <plib.h> That library allows you to access all of Microchip's peripheral libraries. Although I find it easier just to modify the registers directly, saves me time looking for all the api calls and #defines that Microchip has. http://ww1.microchip.com/downloads/en/DeviceDoc/PIC32MX_Datasheet_v2_61143B.pdf Best Regards, Ryan K
Thanks, for the PIC32MX datasheet. The register descriptions are detailed. The datasheet I have only gives a block diagram of the Timers. I didn't include plib.h so I'll give that a try.
Thanks for your reply.
Sat, 03 Mar 2012 04:47:08 +0000
I had the same problem. The plib.h include gave me problems so I modified the registers. setup code:
// Fpb = SYS_FREQ = 80Mhz (From configuration in bootloader code)
// Timer Prescale = 256
// PR2 = 0xF423 = 62,499
// interrupts every 200 ms
// 200 ms = (PR2 + 1) * TMR Prescale / Fpb = (62499 + 1) * 256 / 80000000
T2CON =0x0; // stop timer and clear control register
T2CONSET = 0x0070; //set prescaler to 256
TMR2 = 0x0; // clear timer register
PR2 = 0xF423; // load period register
IPC2SET = 0x0000000D; // set priority level to 3 and subpriority level to 1
IFS0CLR = 0x00000100; // clear timer interupt status flag
IEC0SET = 0x00000100; // enable timer interrupts
T2CONSET = 0x8000; // start timer
interrupt code:
#ifdef __cplusplus
extern "C" {
#endif
void __ISR(_TIMER_2_VECTOR,IPL3AUTO) comms_handler(void)
{
//mT2ClearIntFlag(); // Clear interrupt flag
IFS0CLR = 0x00000100;
digitalWrite(Led4, HIGH);
oneSecond++;
}
#ifdef __cplusplus
}
#endif
Hope this helps
Fri, 09 Mar 2012 00:29:09 +0000
Thanks for the replies.
Not including the <plib.h> was most of the problem and a couple of other things.
I did get the Timer overflow working.
Mark