Search code examples
cfixed-point

C Language Fixed Point Math


I am familiar with the Arduino programming tools but have relatively small experience with embedded programming. When using decimal numbers in the Arduino I never had any issues, so when I recently started playing around with TI's Launchpad F28069M(TMS320F28069M Chip), I was surprised that my math was not yielding my expected results. While doing research, I realized that the TI chip has a fixed point processor which may explain why my decimals are being truncated to 0. (See brief code example)

My questions are the following:

  1. How should I declare decimal numbers in my code?
  2. Should I use TI's IQ math?
  3. Why was I able to declare and perform math functions with decimal numbers in the Arduino without any issue?

My Code

Uint16 A;

main()
{
    A = .25;
}

Result from Expression Window in TI's CCS: Expression Window CCS

Expression Window CCS


Solution

  • Try with this code instead:

    float A;
    
    main()
    {
        A = .25;
    }