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.

UCD3138A: Why does the "feed forward gain" multiply by 0x7fffffff become q30, and why not multiply by 0x4000 0000?

Part Number: UCD3138A

In the ucd3138a PFC code officially provided by Ti, there is a macro definition to calculate the "feedforward gain". Why does the "feedforward gain" multiply by 0x7fffff become q30, and why not multiply by 0x4000 0000?

The code is:

//feedforward gain
#define K_FEED_FORWARD ((Uint32)(0.5 * VAC_MIN_OFF * 1.414 * VAC_VOLTAGE_DIVIDER * 0x7FFFFFFF))//Q30

  • In general, the desire is to avoid overflowing the 32 or 64 bit number, and to provide as much resolution as possible.  Sometimes there's a little bit of leeway in there. 

    I find that the designation of Q30 is internally consistent with the integer math philosophy of whoever writes the code, but sometimes it doesn't make any sense to me.  I don't worry about it too much, but instead just make sure that it doesn't overflow, and the result works out to be scaled correctly.  

    I always have to do a spreadsheet to figure it out.  Maybe the multiplication by .5 at the beginning brings it down to your 0x4000 0000.  I'm not sure.