Long arithmetic in interrupt handler

Tony Hague
2012-10-11
2013-03-12
  • Tony Hague

    Tony Hague - 2012-10-11

    I have a piece of code on a Silicon labs C8051F584,  which controls a DC motor.  An  interrupt handler, triggered by the PCA reload. calculates a new PWM value using 3 'long' multiplies (_mullong) and a long divide (_divslong).

    Now, I have read in the manual advice to avoid function calls in the IRQ handler, and I know that this arithmetic is implemented by library functions.  I've also read the advice about compiling the libraries to be reentrant, which I have not done.

    BUT - these functions are not called in a way that should need them to be re-entrant; they are only used in the interrupt and nowhere else.  The only other library function used is memcpy.  I'm using large model, so there should (?) be no overlaying causing issues.

    Anyway; the code works as I expected when compiled with SDCC 2.9; the motor runs smoothly.  But the same code,  compiled under 3.1 and 3.2, causes the motor to sit chattering around violently.  Replacing the arithmetic library calls with my own explicitly called multiply and divide routines restores normal operation.

    Is there some obvious change between 2.9 and 3.1 which might explain this ?  I'll stick with my own multiply and divide routines as a aolution, but I'd like to understand what is going on.  Any suggestions gratefully received.

     
  • Maarten Brock

    Maarten Brock - 2012-10-12

    Allthough in large model your own variables are not overlayed, the compiler can still overlay its internal temporaries. You can try to disable overlaying in your code.

     
  • Tony Hague

    Tony Hague - 2012-10-15

    Right.  I thought there must be a gap in my understanding somewhere - that is very likely the explanation. 

    Thank you for the quick and helpful response.

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks