Other Parts Discussed in Thread: C2000WARE
Dear team:
I want to calculate an equation:
dutybase=timbase*duty/100;
The scope of Duty: 10~50 (decimal system)
timbase is a fixed value: 4166 (decimal system)
Then I use the Q format to calculate, the code is as follows:
void Setduty(Uint8 duty)
{
Uint16 timbase,dutybase;
_iq q_base;
timbase=4166;
q_base=_IQ15div(_IQ14mpy(_IQ15toIQ(timbase),_IQ24toIQ(duty)),_IQ24toIQ(100));
dutybase=_IQ15int(q_base);
}
When I pass in duty = 10, the dutybase value is 13 (decimal). Normally, the value I get should be 4166 * 10 / 100 = 416. If I don't use the Q format:
dutybase=timbase*duty/100;
This results in a value of 0.
What is the cause of this problem?
Best regards