This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

IQmath计算

Other Parts Discussed in Thread: TMS320F28035, C2000WARE

我的芯片是TMS320F28035,我需要计算一个占空比:

我要计算一个式子:dutybase=timbase*duty/100;

duty范围:10~50  (十进制)

timbase是固定值:4166(十进制)

然后我用Q格式计算,算式如下:

void Setduty(Uint8 duty)

{

Uint16 timbase,dutybase;

_iq q_base;

timbase=4166;

q_base=_IQ15div(_IQ14mpy(_IQ15toIQ(timbase),_IQ24toIQ(duty)),_IQ24toIQ(100));   //用Q格式计算

dutybase=_IQ15int(q_base);//把Q格式数据还原为寄存器数

}

当我传入duty=10的时候,这个时候dutybase的值为13(十进制) ,正常来说我得到的值应该是4166*10/100=416才对,如果我不用Q格式的话,如果这样写:

dutybase=timbase*duty/100;这样就得到的0,以前都是用arm开发,第一次用dsp,所以不是很理解这个Q值转换,如果不用Q值计算,用arm的习惯写出来的公式,得到的结果又不对,能帮我分析下我哪里有问题么?