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

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

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

3,518 次查看
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!
标签 (1)
0 项奖励
回复
2 回复数

1,624 次查看
dingding
Contributor II

Thanks for your help!

It does well.

0 项奖励
回复

1,624 次查看
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 项奖励
回复