Volatile decoder variables (#902)

* triggerToothAngle is modified by interrupts

* triggerActualTeeth is never modified in interrupts
This commit is contained in:
DeionSi 2022-07-27 02:08:06 +02:00 committed by GitHub
parent e3b931b3d1
commit 9fdd217b02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 4 deletions

View File

@ -41,9 +41,10 @@ unsigned long angleToTime(int16_t angle, byte method)
{ {
noInterrupts(); noInterrupts();
unsigned long toothTime = (toothLastToothTime - toothLastMinusOneToothTime); unsigned long toothTime = (toothLastToothTime - toothLastMinusOneToothTime);
uint16_t tempTriggerToothAngle = triggerToothAngle; // triggerToothAngle is set by interrupts
interrupts(); interrupts();
returnTime = ( (toothTime * angle) / triggerToothAngle ); returnTime = ( (toothTime * angle) / tempTriggerToothAngle );
} }
else { returnTime = angleToTime(angle, CRANKMATH_METHOD_INTERVAL_REV); } //Safety check. This can occur if the last tooth seen was outside the normal pattern etc else { returnTime = angleToTime(angle, CRANKMATH_METHOD_INTERVAL_REV); } //Safety check. This can occur if the last tooth seen was outside the normal pattern etc
} }
@ -76,9 +77,10 @@ uint16_t timeToAngle(unsigned long time, byte method)
{ {
noInterrupts(); noInterrupts();
unsigned long toothTime = (toothLastToothTime - toothLastMinusOneToothTime); unsigned long toothTime = (toothLastToothTime - toothLastMinusOneToothTime);
uint16_t tempTriggerToothAngle = triggerToothAngle; // triggerToothAngle is set by interrupts
interrupts(); interrupts();
returnAngle = ( (unsigned long)(time * triggerToothAngle) / toothTime ); returnAngle = ( (unsigned long)(time * tempTriggerToothAngle) / toothTime );
} }
else { returnAngle = timeToAngle(time, CRANKMATH_METHOD_INTERVAL_REV); } //Safety check. This can occur if the last tooth seen was outside the normal pattern etc else { returnAngle = timeToAngle(time, CRANKMATH_METHOD_INTERVAL_REV); } //Safety check. This can occur if the last tooth seen was outside the normal pattern etc
} }

View File

@ -233,7 +233,7 @@ extern volatile unsigned int secondaryToothCount; //Used for identifying the cur
extern volatile unsigned long secondaryLastToothTime; //The time (micros()) that the last tooth was registered (Cam input) extern volatile unsigned long secondaryLastToothTime; //The time (micros()) that the last tooth was registered (Cam input)
extern volatile unsigned long secondaryLastToothTime1; //The time (micros()) that the last tooth was registered (Cam input) extern volatile unsigned long secondaryLastToothTime1; //The time (micros()) that the last tooth was registered (Cam input)
extern volatile uint16_t triggerActualTeeth; extern uint16_t triggerActualTeeth;
extern volatile unsigned long triggerFilterTime; // The shortest time (in uS) that pulses will be accepted (Used for debounce filtering) extern volatile unsigned long triggerFilterTime; // The shortest time (in uS) that pulses will be accepted (Used for debounce filtering)
extern volatile unsigned long triggerSecFilterTime; // The shortest time (in uS) that pulses will be accepted (Used for debounce filtering) for the secondary input extern volatile unsigned long triggerSecFilterTime; // The shortest time (in uS) that pulses will be accepted (Used for debounce filtering) for the secondary input
extern volatile bool validTrigger; //Is set true when the last trigger (Primary or secondary) was valid (ie passed filters) extern volatile bool validTrigger; //Is set true when the last trigger (Primary or secondary) was valid (ie passed filters)

View File

@ -76,7 +76,7 @@ volatile unsigned int secondaryToothCount; //Used for identifying the current se
volatile unsigned long secondaryLastToothTime = 0; //The time (micros()) that the last tooth was registered (Cam input) volatile unsigned long secondaryLastToothTime = 0; //The time (micros()) that the last tooth was registered (Cam input)
volatile unsigned long secondaryLastToothTime1 = 0; //The time (micros()) that the last tooth was registered (Cam input) volatile unsigned long secondaryLastToothTime1 = 0; //The time (micros()) that the last tooth was registered (Cam input)
volatile uint16_t triggerActualTeeth; uint16_t triggerActualTeeth;
volatile unsigned long triggerFilterTime; // The shortest time (in uS) that pulses will be accepted (Used for debounce filtering) volatile unsigned long triggerFilterTime; // The shortest time (in uS) that pulses will be accepted (Used for debounce filtering)
volatile unsigned long triggerSecFilterTime; // The shortest time (in uS) that pulses will be accepted (Used for debounce filtering) for the secondary input volatile unsigned long triggerSecFilterTime; // The shortest time (in uS) that pulses will be accepted (Used for debounce filtering) for the secondary input
volatile bool validTrigger; //Is set true when the last trigger (Primary or secondary) was valid (ie passed filters) volatile bool validTrigger; //Is set true when the last trigger (Primary or secondary) was valid (ie passed filters)