Part Number: TMS320F28379D
Hello experts,
I am facing a wierd issue , If I execute the below function inside a PWM ISR(50 us time), testCounterSpeedMA is incremented multiple times and it increments randomly!
Sometimes it increments by 2, 11, 7 etc..
The same function if i run it in a slower task, example inside a 10 ms timer , it correctly increments by 1 when ever there is a speed change.
Why does this happen?
I would like to execute this function from the PWM isr and have the counter increment only once, when ever there is a speed change.
void checkForSpeedChange(MOTOR_Vars_t *pMotor)
{
volatile static int16_t prevSpeedMA = 0;
volatile static uint16_t testCounterSpeedLoopResetMA = 0;
if(prevSpeedMA != pMotor->speedRefRPM)
{
testCounterSpeedMA++;
//Log speed change
pMotor->speedChange = true;
//Store the previous value
prevSpeedMA = pMotor->speedRefRPM;
}
}