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

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

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

2,981件の閲覧回数
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,087件の閲覧回数
dingding
Contributor II

Thanks for your help!

It does well.

0 件の賞賛
返信

1,087件の閲覧回数
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 件の賞賛
返信