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.

Qn representation - Fixed Point Arithmetic on MSP430

Other Parts Discussed in Thread: MSP430G2553

Hi,   

I'm trying to implement a PI control   on MSP430G2553 for a Buck Converter.    But the uC is taking to long to execute the maths on floating point.

So, i decided to use the floating point -> fixed point transformations and fixed point arithmetic   using the IQMath library.

 But , its the my first time on that.   I've studied the Qn representation and I understood tha basis.   But I still have a difficult:

I don't know how to choose the best  "n" representation for  numbers smaller than one.   I did  a table showing maximum numbers that can be represented for each Qn.  And the resolution.   

 I know that 0.52 is better representated on Q15   and

0.49 on Q16,  but  why?

Can you help me?

Thanks

  • BTW this forum have some PID thread here. If you use search - you will find it.
    In your place I would forget about Qn representation but use scaling approach instead.
    For further reference look for Atml appnote AVR221 which is about discrete PID controller resulting in compact and fast code, still doing it's job

  • The use of Floating-point variables is good for statically calculations but not to control a Buck converter (or any power converter). It is wasting a lot of time, especial on a none floating-point processor, as you already experienced.

    The use of decimals with an integer values isn’t difficult. When you multiply these values with 1000 you get a decimal precision of 3-digits. For example when you multiply your values 0.52 and 0.49 with 1000 you get 520 and 490. You only need to keep track yourself when using these values to multiply with another value you get a 1000 times higher result, and when division a 1000 times lower.

    Now are multiplication and division also time consuming and it’s difficult to keep track of the amount of decimals after calculation, the use of Q-values makes this easier.
    If you would convert your values to for example Q10 which is 1<<10 = 1024 and is nearly the same as 1000 (so already easy to read) you will get 532 and 501, but converting these values back you get a little error: 0.519 and 0.489. A higher Q value will be more precise but you are losing integers and so the range of your value. In most cases, and certainly for power converters or motor controllers, losing a few bits of precision isn’t a problem. The output resolution of converters isn’t (only) defined by the resolution of the PWM and the values but mainly by the frequency.

    When multiplying Q10 values then the Qn of the result is 10+10=20, or when multiplying a Q10 value with a Q4 value you get 10+4 is a Q14 result. Take care that you are using a 32-bit result (not always necessary) when multiplying and shift the result to the desired Q-value.
    This is easy to handle and when debugging the program with CCS you can select ‘Q-value’ in the ‘Expressions View’ and CCS shows you the value as a float with the correct decimals.
    The use of IQmath.lib is not necessary but have some handy macro’s.
    When using a MCU with MPY then converting a 32-bit Q16 result can be easy done by only reading the 16-MSBits to an 16-bit variable and don’t use the 16-LSBit result.

    For Power Converters is mostly used a 2P2Z Controller, this gives you an easy possibility to control switch current and voltage.

**Attention** This is a public forum