chipKIT® Development Platform

Inspired by Arduino™

how add routine in millisecondCoreTimerService ?

Created Wed, 11 Jul 2012 13:22:46 +0000 by philippel13


philippel13

Wed, 11 Jul 2012 13:22:46 +0000

hi,

i need to generate an interrupt every 1ms.

I've seen this interrupt already exist in wiring.c with the running of the millisecondCoreTimerService routine each millis.

So how could i add the call of a personnal cpp routine in millisecondCoreTimerService ?

wiring.c is in C and i don't know how to call in a method of an class. When i add "include delais.h" in wiring, i've the following error :
"error: expected '=', ',', ';', 'asm' or 'attribute' before 'delais'"

Any idea ?

thanks


majenko

Wed, 11 Jul 2012 13:46:42 +0000

I would shy away from modifying the core wiring code if I were you.

You would be much better off setting up your own timer (there are quite a few to pick from) to call your routine at the right times.

You should read the chip's datasheet and the pic32 timers manual for more detail on them.

Incidentally, "include delais.h" is not a C or a C preprocessor directive. I think you mean something more like

#include "delais.h"

KeithV

Wed, 11 Jul 2012 15:29:33 +0000

You could write your own serivce and register it....

you could create a service like the following"

uint32_t myMillisecondCoreTimerService(uint32_t curTime) { static nextInt = 0; uint32_t relWait = 0; uint32_t relTime = curTime - nextInt;

// catch-up up to current time; we may have fallen behind due to interrupts being diabled. while(relWait <= relTime) { relWait += CORE_TICK_RATE; // add a ms to our next ISR time }

// set when we want to be called again
nextInt += relWait;                     // calculate the absolute interrupt time we want.

// put your code here:

return(nextInt);

}

And then register the service from within your sketch by calling:

attachCoreTimerService(myMillisecondCoreTimerService);

Just be careful to keep whatever you are doing quick, under a few 10s of uSec, certainly under 100 uSec as you are running as an ISR. You do not need to change any code in wiring.c, and the serivce would only apply to your sketch.


jRobert

Wed, 11 Jul 2012 15:36:43 +0000

The Wiki gives a pretty good explaination of the CoreTimerService http://chipkit.org/wiki/index.php?title=Core_Timer_Service_Overview

jRobert


philippel13

Wed, 11 Jul 2012 17:47:50 +0000

I've used the example in the wiki and it's works fine !

In the wiki i've also find the task manager. I could also do that with it. http://chipkit.org/wiki/index.php?title=Task_Manager_Overview

Big thanks you for your help.