Hello everyone,
I´m working on my MODM7AE70, I have a problem in the use of the
interrupt, I explain, I have configured an external interrupt with
polarity 0 (either), to test this I have a square wave generator
with a frequency of 200 microseconds and to test if the interruption
enters every 200us, I used the stopwatch function to obtain the
SysTick GetNow(), and with this to be able to calculate the
difference between interruptions, so far so good, but the problem is
with the results (when I finish the interruption, I save everything
inside a SD memory, I will add some examples), the program works but
always in each sample I get a couple of values that do not match
Input value: 1 Time diff: 0.000203753 sec Number Tick: 61126 //good
Input value: 0 Time diff: 0.000202147 sec Number Tick: 60644//good
Input value: 1 Time diff: 0.000203787 sec Number Tick: 61136//good
Input value: 0 Time diff: 0.000202267 sec Number Tick: 60680//good
Input value: 1 Time diff: 0.000203727 sec Number Tick: 61118//good
Input value: 0 Time diff: 0.000202213 sec Number Tick: 60664//good
Input value: 1 Time diff: 0.000203673 sec Number Tick: 61102//good
Input value: 0 Time diff: 0.000202227 sec Number Tick: 60668//good
Input value: 1 Time diff: 6.14891e+10 sec Number Tick: 18446744073694612752 //wrong
Input value: 0 Time diff: 0.050203 sec Number Tick: 15060907 //wrong
Input value: 1 Time diff: 0.000202973 sec Number Tick: 60892//good
Input value: 0 Time diff: 0.000202207 sec Number Tick: 60662//good
Input value: 1 Time diff: 0.000203787 sec Number Tick: 61136//good
Input value: 0 Time diff: 0.000202267 sec Number Tick: 60680//good
Input value: 1 Time diff: 0.000203787 sec Number Tick: 61136//Good
Note: Number ticks are the system ticks
This is repeated about 8 times in 100k samples (100k is the maximum
I keep).
18446744073694612752 ticks = 1949 years
I will add my code:
extern volatile uint32_t TimeTick;
extern volatile uint32_t CPU_CLOCK;
/**********************************<TIMER
TICK>********************************/
static unsigned long long GetNow()
{
uint32_t iv = SysTick->VAL;
uint32_t tt = TimeTick;
uint32_t ev = SysTick->VAL;
if ((iv < ev) && (tt = TimeTick)) //TimTick incremented between
iv and lv
{
tt--;
}
uint32_t lv = SysTick->LOAD;
unsigned long long cv = tt;
cv *= lv;
cv += (lv - iv);
return cv;
}
/********************************** Convert
********************************/
double Convert(unsigned long long uv)
{
double dv = uv;
return dv / CPU_CLOCK;
}
/*****************DEFINITIONS*****************/
#define IRQ_POLARITY_EITHER 0 //for 0 and 1
volatile bool interruptionState = false;
PinIO pioPort = P2[6];
volatile int inputNum = 0;
volatile bool firstInt = false;
volatile unsigned long long beforeTickTime = 0;
volatile bool beforeState;
const unsigned int filtermin = 59882;
const unsigned int filtermax = 62306;
typedef struct{
bool state;
unsigned long long difftick;
}wrongInputs;
wrongInputs volatile inputs[100000];
/*****************INTERRUPTION FUNCCTION*****************/
void extInt(int port, int portPin)
{
unsigned long long actualTickTime = GetNow();
if(interruptionState){
bool state = pioPort.readBack();
if(firstInt){
if(inputNum < 100000)
{
unsigned long long tickDiff = actualTickTime - beforeTickTime;
inputs[inputNum].state = state;
inputs[inputNum].difftick = tickDiff;
inputNum++;
}
}else{
firstInt = true;
}
beforeTickTime = actualTickTime;
beforeState = state;
}
}
/*****************SAVE SD MEMORY CARD*****************/
void getInputDiff(){
if(interruptionState){
DisableIrq(pioPort);//disable the interruption
interruptionState = false;
}
f_enterFS();
InitExtFlash(); // Initialize the CFC or SD/MMC
external flash drive
DeleteFile(pFileName);
double time;
#define WRITE_BUFSIZE 80
for (int x = 0; x < inputNum; x++) {
time = Convert(inputs[x].difftick);
char write_buf[WRITE_BUFSIZE];
sniprintf(write_buf, WRITE_BUFSIZE,
"Input value: %d Time diff: %g sec Number Tick: %llu\n",
inputs[x].state, time, inputs[x].difftick);
AppendFile((unsigned char
*)write_buf, pFileName, strlen(write_buf));
}
UnmountExtFlash();
f_releaseFS();
}
/*****************STARTS (ENABLEIRQ) AND CLEAN
ARRAY*****************/
void startInterruption(){
if(!interruptionState){
memset((void *)inputs, 0,
sizeof(inputs));
inputNum = 0;
EnableIrq(pioPort);
interruptionState = true;
firstInt = false;
}
}
/*****************CONFIG*****************/
void configureIO(){
SetPinIrq( pioPort, IRQ_POLARITY_EITHER, extInt);
DisableIrq(pioPort);
interruptionState = false;
}
I WILL APPRECIATE ANY HELP
Kind Regards
Fredy Gutierrez
Wrong Interruption Time
Re: Wrong Interruption Time
GetNow has an error...
Should be:
f ((iv < ev) && (tt == TimeTick)) //TimTick incremented between iv and tt
Should be:
f ((iv < ev) && (tt == TimeTick)) //TimTick incremented between iv and tt