Displaying Voltage From ADC On LCD Display

325 views
Skip to first unread message

oxnard linux junkie

unread,
Jun 22, 2009, 7:24:48 PM6/22/09
to GCC-HCS12
Hello,
I would like to display the ADC atd_result(0) in example
http://gcc-hcs12.com/downloads/HCS12_11_ATD.zip on to the on board LCD
display. After some investigating I've discovered that I might have to
convert the integer value "atd_result(0) into a string value in order
to use it as the argument for the 'LCDWriteline(1, ...)' (multiplied
by .019 be be used as a volt meter and have a voltage value).


-I have tried to multiply the atd_result(0) by the value obtained from
(5/255=.019) to have a simply volt meter but I received errors. Can
the atd_result(0) variable be multiplied by anything or is it some
sort of matrix?

- in C#, a popular function to convert integers to string values are
"sprintf()", does the HC12 libraries have anything simliar to this?

Navid

unread,
Jun 22, 2009, 8:09:13 PM6/22/09
to GCC-HCS12
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


oxnard linux junkie

unread,
Jun 23, 2009, 3:02:12 AM6/23/09
to GCC-HCS12
Hello,

Sorry about the "C#". I'm not a seasoned programmer (I'm an RF guy) so
I'm taking jabbs from IRC and various forums for not knowing the buzz
words and correct context. Please bare with me :-/


1.
What are the consequences of using flash memory instead of RAM?
Currently I would just like to read in the ADC string, convert it into
a numerical value which I can use for other programs (later). If I
require more memory, I guess I'll have to find a way to purchase a
newer generation board and use the SD memory. I'll approach this issue
pending my final memory requirements.

I really appreciate the example. I didn't realize bringing a floating
point simulation was an inefficient way of performing this
calculation. This is example is very straight forward and don't worry
about "being dummy"; Ironically I have C# 2005 for Dummies by Davis
and Sphar right in front of me so its well within my scope at the
time. The simpler it is, the most likely I can move on with "the more
complicated stuff" :)


2.

I'd like to eventually create a sample program to see if the CPU usage
will really be an issue.

3.

No sprintf(), bummer. Would the example you showed in 1. be a
substitution for converting the integer into a string or is that only
for the terminal? It sounds like I'm still out of luck to display that
value on the LCD screen?

How can I find out the CPU usage during the loading of my program?

I'm not sure what you mean by "IR voltage values". I like the idea of
having intervals for voltages instead of using my for loops.

It would be great to have a general example on how to interface a FPU
chip to relieve the HCS12 from inefficiencies.


This helps very much. I really appreciate your detailed responses.




On Jun 22, 5:09 pm, Navid <navid.mohagh...@gmail.com> wrote:
> 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_unithttp://en.wikipedia.org/wiki/Fixed-point_arithmetic

Navid

unread,
Jun 23, 2009, 11:34:45 PM6/23/09
to GCC-HCS12
Hi,

> Sorry about the "C#". I'm not a seasoned programmer (I'm an RF guy) so
> I'm taking jabbs from IRC and various forums for not knowing the buzz
> words and correct context. Please bare with me :-/

no no worries at all ... I was just joking ...


> What are the consequences of using flash memory instead of RAM?
> Currently I would just like to read in the ADC string, convert it into
> a numerical value which I can use for other programs (later). If I
> require more memory, I guess I'll have to find a way to purchase a
> newer generation board and use the SD memory. I'll approach this issue
> pending my final memory requirements.

Please have a look at the above mentioned flash clips ... if you like
to just show a numerical value of the ADC, you can simply use what I
mentioned:
int point = result % 10 = 9
result = (int) input / 51 = (int) 1.96 = 1
which then you can show it as 1 point 9

Adding a new memory to the board is not easy at all and new
generations doesn't have more RAM ... once you reach the Flash
tutorials you will see what I mean ...

> I'd like to eventually create a sample program to see if the CPU usage
> will really be an issue.

We don't have any program that act as a windows task manager, but one
way to prove that floating point operation will kill the CPU is to
perform 200 floating point operation and then turn on the test LEDs
(i.e. 7segment display) on the board ... you will see it will take a
while till the LEDs become on!


> No sprintf(), bummer. Would the example you showed in 1. be a
> substitution for converting the integer into a string or is that only
> for the terminal? It sounds like I'm still out of luck to display that
> value on the LCD screen?

One trick we can do is:

imaging having result = 127.5 and you like to display it ... we can
have:
char chars[5];
chars[0] = 1 + '0";
chars[1] = 2 + '0';
chars[2] = 7 + '0';
chars[3] = '.';
chars[4] = 5 + '0';


> It would be great to have a general example on how to interface a FPU
> chip to relieve the HCS12 from inefficiencies.

This needs to use either of I2C or SPI to interface HCS12 and FPU
chips ... I don't have the board otherwise I would help you to make
one ...
Reply all
Reply to author
Forward
0 new messages