Problem of doing float operation in interrupt function or interrupt called function

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem of doing float operation in interrupt function or interrupt called function

2,980 Views
dingding
Contributor II
#pragma interrupt called
void sci_cmd()
{
   ……
    Kp=(float)(sci_rec_buffer[1]*256+sci_rec_buffer[2])*0.0001;
  ……
   }
for example, runing aboved function in sci interrupt function, but Kp(define as float type) isn't changed. I do these in codewarrior 6.0, and on 56F807
Thank you!
Labels (1)
0 Kudos
Reply
2 Replies

1,086 Views
dingding
Contributor II

Thanks for your help!

It does well.

0 Kudos
Reply

1,086 Views
alex_spotw
Contributor III
Hi:

First of all, I would not recommend doing floating point operations inside Interrupt Service Routines (ISR), because they might take too much time and you could loose characters from the serial port.

A better alternative is to wait until all data has been received and then do the calculation (outside the Interrupt).

As for your problem, you have to define Kp as volatile, so that it gets updated in the ISR. Otherwise, the compiler will optimize it out.

Regards,

Alex
0 Kudos
Reply