Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix temp-interrupt with LIN_ADVANCE #74

Closed
wants to merge 1 commit into from
Closed

Conversation

AnHardt
Copy link
Owner

@AnHardt AnHardt commented Feb 6, 2017

Error mechanism:
Let's suppose we are in 'Temperature::isr()'.

  CBI(TIMSK0, OCIE0B); //Disable Temperature ISR
  sei();

The temperature-interrupt is disabled, but all others are enabled.

Now the temp-isr is interrupted by the Stepper::advance_isr_scheduler()

    // Disable Timer0 ISRs and enable global ISR again to capture UART events (incoming chars)
    CBI(TIMSK0, OCIE0B); // Temperature ISR
    DISABLE_STEPPER_DRIVER_INTERRUPT();
    sei();

temp-isr and stepper-isr are disabled.
When we leave the Stepper::advance_isr_scheduler() we execute

    // Restore original ISR settings
    cli();
    SBI(TIMSK0, OCIE0B);
    ENABLE_STEPPER_DRIVER_INTERRUPT();

Enable temp-isr and stepper-isr. In case we interrupted the temp-isr this does not restore the ISR settings, but enables the temp-isr falsely.
If its time for a fresh temp-isr now, this is entered before the still on the stack temp-isr ended - the temp-isr bites its tail.

Problems:
Is temp-isr is entered multiple times the stack may overflow.
temp-isr is not made for reentering.

Symptoms:
Sampling OVERSAMPLENR+1 (or more) instead of OVERSAMPLENR samples.

  • if the temperature is low (high raw values) this may result in min-temp-error.
  • if the temperature is high it looks like a sudden, and only one time, drop of temperature by about 1/17 the expected one.

Even worse and unpredictable things when the stack overfolowes

@AnHardt AnHardt changed the title fix-linadv Fix temp-interrupt with LIN_ADVANCE Feb 6, 2017
Make multiple instances of Temperature::isr() impossible.


Error mechanism:
Let's suppose we are in 'Temperature::isr()'.

  CBI(TIMSK0, OCIE0B); //Disable Temperature ISR
  sei();
The temperature-interrupt is disabled, but all others are enabled.

Now the temp-isr is interrupted by the Stepper::advance_isr_scheduler()

    // Disable Timer0 ISRs and enable global ISR again to capture UART events (incoming chars)
    CBI(TIMSK0, OCIE0B); // Temperature ISR
    DISABLE_STEPPER_DRIVER_INTERRUPT();
    sei();
temp-isr and stepper-isr are disabled.
When we leave the Stepper::advance_isr_scheduler() we execute

    // Restore original ISR settings
    cli();
    SBI(TIMSK0, OCIE0B);
    ENABLE_STEPPER_DRIVER_INTERRUPT();
Enable temp-isr and stepper-isr. In case we interrupted the temp-isr this does not restore the ISR settings, but enables the temp-isr falsely.
If its time for a fresh temp-isr now, this is entered before the still on the stack temp-isr ended - the temp-isr bites its tail.

Problems:
Is temp-isr is entered multiple times the stack may overflow.
temp-isr is not made for reentering.

Symptoms:
Sampling OVERSAMPLENR+1 (or more) instead of OVERSAMPLENR samples.

if the temperature is low (high raw values) this may result in min-temp-error.
if the temperature is high it looks like a sudden, and only one time, drop of temperature by about 1/17 the expected one.
Even worse and unpredictable things when the stack
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant