-4

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

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • 8
    `Uint16` is a 16 bits unsigned integer ( no decimals...), so what is not clear???.... – LPs Jun 22 '16 at 06:29
  • 5
    You have *a lot* of misconceptions. – Marcus Müller Jun 22 '16 at 06:32
  • 3
    Uint16 is not a fixed-point type in the common sense. – phuclv Jun 22 '16 at 06:33
  • You are trying to put a 0.25 (floating point) into an 16 bit integer, 025 simply gets rounded to 0 and you get 0 in `A` which is expected. – Jabberwocky Jun 22 '16 at 07:55
  • 1
    I feel bad because this question get downvoted simply because people don't understand fixed point. Fixed point numbers are integers to machines and are usually `typedef` as existing integer types. For beginners I recommend TI's IQMath library. As you get more informed you can look for IQMath source code and use some lower level functions. The IQMath API is not perfect, e.g. IQ_N_div function does not handle the case when the input and outputs are different Q but the lower level implementation does. – user3528438 Jun 22 '16 at 17:13
  • I do appreciate the feedback !! I was scratching my head over this issue and now I realize that I was using an integer instead of float . Now my code runs fine !! – Joe Bingham Jun 23 '16 at 01:12

1 Answers1

-1

Try with this code instead:

float A;

main()
{
    A = .25;
}
Illishar
  • 886
  • 1
  • 11
  • 24