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.

TMDSSOLARUINVKIT: IQmath + If Statements

Part Number: TMDSSOLARUINVKIT


Dear All,

I would like to know if it is possible to mix different Q formats with the if statements, for example:

#define VPV_MIN        _IQ7(15.0)

Gui_Vpv = _IQ20mpy(pv_meas_vol_avg>>4,_IQ20(PV_VOL_SENSE_MAX));

if(Gui_Vpv > VPV_MIN)

{

}

When i run that code, I always get a true condition in the if statement. I got that fixed by giving to VPV_MIN the same Q format of Gui_Vpv, so the question is, Can I use different Q Formats with the if()? If I can, Is there a bug with the IQmath library?

Thank you

Diego

  • Diego,

    A numerical comparison only makes sense if the IQ formats are the same. Fundamentally, both Gui_vpv and VPV_MIN are long integers. The IQ format only affects our interpretation of the integer in terms of the position of a notional binary point. The comparison will return true if the two's complement of Gui_vpv evaluates greater than the two's complement of VPV_MIN. This is independent of IQmath.

    To make the comparison valid you would have to align the binary points: for example, by right-shifting Gui_vpv by 13.

    Regards,

    Richard