I’m starting programming a dspic33 from Microchip and i’m having problems when I try to return an extern variable. My code is divided in 3 files, and is something like this:
main.c
#include <stdio.h> /*printf definition ... */
#include "clock.h"
volatile unsigned long count = 0;
int16_t main(void)
{
clock_init();
while(1)
{
if(flag)
{
printf("MAIN:count = %lu clock_time %lu",count, clock_time());
flag = 0;
}
}
return 0;
}
clock.h
...
extern volatile unsigned long count;
...
clock.c
#include "clock.h"
void __attribute__((__interrupt__, no_auto_psv)) _T1Interrupt(void)
{
count++;
flag=1;
IFS0bits.T1IF = 0;
}
unsigned long clock_time(void)
{
return count;
}
The output is something like:
MAIN:count = 1 clock_time : 590106798
MAIN:count = 2 clock_time : 590106798
MAIN:count = 3 clock_time : 590106798
and so on…
I’m wondering why the clock_time() is not returning the correct value of count. Does anyone know what I’m doing wrong?
Have you try with a wait between:
Maybe the clock is very fast and the units of your variable are too small to represent it. Or probaly the conversion in the printf of the variable type.