Hi,
First of all, please do not insult me with C# lool, I am joking ...
The first thing I want to bring to your attention is that we are
working in the embedded world and we are talking about 12kB of
ram ...
This means:
1- On PC we can perform 100*0.19 and the result will be easily shown
as 19 ... but once we are working with integer CPUs like HCS12, we
have to emulate the floating point operations using integers and this
will add at least 10kB of extra code to the program which may force
you to use the onboard flash instead of RAM ...
http://en.wikipedia.org/wiki/Floating_point_unit
http://en.wikipedia.org/wiki/Fixed-point_arithmetic
so my first suggestion is that you do not directly multiply your input
by 0.19 (why? since the compiler has to bring floating point
simulation to your program!) ... And instead, you do this:
(input * 5 ) /255 or simply do this: int result = input / 51
example:
int input = 100;
int result = 0;
result = (int) input / 51 = (int) 1.96 = 1
now you may say, you need more accuracy so you can do this:
result = (int) ( (input * 10 ) / 51 ) which gives you 19 and you can
do this:
int point = result % 10 = 9
result = (int) input / 51 = (int) 1.96 = 1
which then you can show it as 1 point 9
this is very dummy and I am trying to show it as simple as
possible ... obviously fix point floating point simulation is being
done by the compiler but you need to pay for it by allocating more
space in your program ... if you need to use flash please have a look
at the banked and flat flash clips ...
Introduction to flash and restoring Dbug12 - Related file: Dbug12
v4.29
Hello flash - Source code: HCS12_14_FLASH
Programing flash (FLAT/LARGE mode) - Source code: HCS12_15_FLASH_FLAT
Programing flash (BANCKED mode) - Source code: HCS12_16_FLASH_BANCKED
2- if you really want to do full floating point operations, you need
to consider a noticeable cpu usage for added transparent simulation
program ... and you should not kill an integer CPU by constantly
calling floating point operations in a loop!!!
3-Not only we are not in C#, but also we are not even using standard C
library ... sorry no sprintf for now!! However there are some ways you
can use smaller versions of these functions, but that will take many
pages to explain ... as soon as I find some time and if you really
like I can write about it ...
Finally the best I recommend is to have your IR voltage values in
different intervals and do not kill the CPU with many floating point
operations ... or even interface a FPU chip to your hcs12 (advance
topic that I can explain if you like)
Hope this helps,
Navid