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.

Loading floating point value in HRPWM

Other Parts Discussed in Thread: TMS320F28035

I want to load HRPWM period from the result of some floating point calculations done in the CLA of TMS320F28035.  Can anybody suggest an example code or method ? 

  • The simplest way is to just use the MF32TOI32 instruction (or MF32TOUI32 ) to convert your float to a signed or unsigned integer respectively.

    Keep in mind that your floats have 24 bits of precision and also that the high resolution registers are significant in bits 15:8 and the specifications require that writes to bits 7:0 must be zero. 

    Generally, you want to do your calculations so that the float produces a positive 24 bit result that you will convert to unsigned integer and then left shift 8 bits with a MLSL32 instruction to align it. You can then write this result directly to your HRPWM period register with a single 32 bit write.

    Hope this helps.

     

     

     

     

     

     

  • Thank you Ritchie,

    The problem got modified a bit from what it was.

    The CLA computes the frequency information in the form of clock counts (period). It transfers the  counts to CPU as a float variable. For example it computed the period to be 333.4105 counts that is represented by hex as 0x43A6B48C. I want to load HRPWM  with minimum amount of manipulation of the data. I do not want to loose the fraction. Ideally there should be a routine that excepts the float and loads HRPWM. Let me know your way.

     

    sunil

  • Generally, it's easiest to treat this as 8 bits assuming you are using auto-conversion and the sfo library.

    You can Multiply your floating point count by 256 and then convert it to integer. This will produce a 24 bit result.

    Then  you can Multiply the integer by 256 with a shift left 8. This will give you a 32 bit integer result.

    You can then save this for the CPU or directly write it out to the HRPWM period register.

    Here is a code snippet that will do this 

    MMOVF32 MR0,#333.4105 ;simulate initial value

    MMOVF32 MR1,#256.0

    MMPYF32 MR0,MR0,MR1

    MF32TOUI32 MR0,MR0

    MLSL32 MR0,#8

    MMOV32 @_EPwm1Regs.TBPRDM.all,MR0

     

     

    It's far faster and easier to do this in the CLA becuase the CPU is fixed point and the CLA is native floating point.