What i am doing wrong if i have functions and macro defined as below:
//in main.c
void vConfigureTimerForRunTimeStats( void )
{
PR4=0; // set period (doesnt matter cause i am using prescaller to get TMR4 as counter
TMR4=0; //clear timer register
T4CONSET=BIT_6|BIT_5|BIT_4;//timer prescaler 256, 10000000/256=39kHz
T4CONSET =BIT_15;//enable Timer
}
I would guess, and it is a guess, that somehow two consecutive time readings show the time going backwards rather than forwards. Is it possible that a time reading occurs before the run time counter has been initialised? Can you put a break point in the function that calculated/returns the run time counter value to see what values are being returned the first few times it is called?
It might be easier even to buffer the first few returned values. You could create a temporary array of say 50 places, then the first 50 times the function that calculates/returns the time value is called have it also write the value into the next array slot. Then pause the program and view what was written to the array.
time readings are made by FreeRTOS, initialization is made by FreeRTOS, I dont know if timer is read before initialization:)
But i think i have the answer: TMR4 is 16 bit long… i must check what FreeRTOS expect it to be… and if it expect to be 32 bit long, there is an option to set it to 16 bit?
One technique with 16 bit timers is to configure the timer to generate an interrupt at a high frequency (10K Hz?), then have the ISR just increment a 32 bit variable. The 32 bit variable is then your run time stats base.
This is not a particularly efficient method because of the high interrupt overhead. If you really know the PIC32, you could use the fast interrupt shadow registers to minimise the effect (don’t ask me about that though! I’ve never used them myself).
Thanx, now with prescaler i have 39kHz timer with 1kHz task rate. I think that 16 bit timer at 39kHz is good enough to do its job. There is no problem to make interupt and increment timer by 1 every tick…. by what for??? if i could force FreeRTOS to use stats with 16 bit long counters…. but how??? If such change is not worth the time then i will write interrupt but if you could tell me if it is possible i would be honoured thanx
one notice to freertos examples about stats:
you cannot declare ‘extern’ in FreeRTOSconfig.h because that header is included in assembler file (ISR_Support.h) in PIC32 port