Continue to Site

Welcome to

Welcome to our site! is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Float variables inside interrupts

Not open for further replies.


Newbie level 5
Aug 27, 2008
Reaction score
Trophy points
Activity points
I am using linux on a MPC5200 board.

There is a serial interrupt in the code. On accessing a global floating point variable from inside the interrupts I am corrupting variables elsewhere. Is accessing float variables inside not recommended and why ?

also note that the frequency of this interrupts is fairly high.

There is no such limitation to avoid accessing floating point variables in the interrupt section. The problem is just manifestation of something completely different:
1. stack overflow
2. sharing problems
3. timing problem

You can try to pinpoint the problem by insulating the problems - try to:
1. change the stack size
2. put some protection tehniques when accessing this variable - it's common mistake to access such variables without protection. You'll get definetly problems if during the access of the variables from the main level the interrupt changes this variable.
3. reduce the speed of interupts (slow down the serial events)
for ultra timing critical applications, there can be minor slacks if u access floating point variables inside interrupts. especially if the FPU is implimented in software. However, corruption cannot occur as a result of this as luben111 suggested
It cross my mind two reasons:
- wrong set of adress in moving data memset() memcpy()
- wrong set of adress in DMA access

the MPC5200 has a floating point unit. A couple of thoughts
1. does the hardware automatically save the FPU registers on interrupt?
2. are you calling none-reentrant functions from within the interrupt service routine?
3. have you declared global variables used within the interrupt routine as volatile?

1.In the interrupt no registers are save by hardware, depending on compiler there are implicit implementation on interrupt header of routine and post.
If you need special register to be save you have to rewrite the interrupt mechanism from scratch .
2. You can call what function you need in the interrupt but there are bad thinks coming after if
- functions are to big and can lock the resources
- if same interrupt come in this time, lost of interrupts (phantom interrupts) can appear and old 16 bit micro have hardware support for this situation.
3. Global variables used in interrupt can be changed any time and in a way you have to be careful take this into account. Usage of volatile I find it useful
- when you what to avoid optimization
- when the address points out to a mapped register.

Not open for further replies.

Part and Inventory Search

Welcome to