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.

Storing a float32_t variable into a register (very basic)

Other Parts Discussed in Thread: C2000WARE

Hello. I am a total beginner when it comes to C-programming. I want to implement a PID-control using the C2000Ware DCL PID, see figure: 

I want to put my control effort "u_k" into a register, see picture below:

How would I, in an efficient way, translate the control effort "u_k" into something I can put into this register? I don't have a good understanding of floating numbers and such. 

Best regards

  • To convert a floating point control signal to a fixed point value, you will need to do the "scaling". Depending on the maximum control signal u definition in the PID controller, you would like to map it to the full scale of your destination register, and do a data conversion afterwards.

    For example, if your u is limited to between 0.0 and 1.0, and output is between 0 and 65535, you can set the register value to

    (uint16_t)(u_k * 65535.0)

    One other tip: if you want your control output to update synchronous to your PWM output, it is reconnected to update the shadow registerRAMPMAXREF_SHDW instead of changing the register directly.

    Hope this will resolve your question.

    Han