ADC input display on LCD in voltage

Go To Last Post
25 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 Task: Develop a program that displays the voltage at the input channel A0 as a single bar graph and number on the LCD. The voltage range is 0-5v.

How to take input from adc and then display it as voltage on lcd. I am using Avr studio 4.

Please guide me through it.

Last Edited: Mon. Jun 26, 2017 - 03:48 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What micro? In other words - is there enough room for a floating point library and a floating point display routine? (to be on the safe side you probably need a 4K micro or larger for all that - probably ~1K for the floating point maths and ~2K for the floating point printf()).

 

Oh and when you say "Studio 4" do you mean JUST Studio 4 which, by implication means the Atmel assembler or is C going to be involved in this somewhere?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Micro is atmega128. Avr studio 4 software that uses C language

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ahad Maqsood wrote:
Avr studio 4 software that uses C language
But Studio 4 does not come with a C compiler? Presumably you have added either "WinAVR" or "Atmel Toolchain for Windows" to it?

 

Anyway, in a 128K micro you should have no problem using floating point if you want to.

 

After that it's simply a case of translating the 0..1023 reading you get from the ADC into a 0 .. 5.0V value to show on the display. As you can use floating point you might as well use:

float volts = (ADC / 1023.0f) * 5.0;
sprintf(buffer, "V = %0.2f", volts);

or something along those lines.

 

Say the reading was 735 then you would get 735 / 1023.0f = 0.71848 then 0.71848 * 5.0 is 3.59238. Using "%0.2f" means "show this with just 2 decimal places" so the display value in buffer[] would be "V = 3.59". Then it's just a question of sending the contents of buffer[] to be displayed on the LCD.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So why are you posting in the Site Feedback forum?!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
So why are you posting in the Site Feedback forum?!
ignore that comment  - I have moved it.

 

(Andy either use "report" or tell the user to post elsewhere - don't do both - it will just cause confusion).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ahad Maqsood wrote:
...and number on the LCD...

Quite a spec you have given.  Tell us more about this assignment.  School work?  Work for hire?

 

There are many different types of "LCD".  Which type/size/characteristics are we to work with?

Image result for lcd

Image result for lcd

Image result for lcd

...and others.

 

I've posted my "character LCD" bar graph before...

http://www.avrfreaks.net/comment...

 

 

 

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Mon. Jun 26, 2017 - 04:06 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Please show how to send buffer value to LCD.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In case the post from theusch didn't make it clear: We can say nothing meaningful unless you tell us what type of display you're working with. And make and model, preferably. 

 

7-segment?

Character based?

Graphics display?

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just to note that whatever kind of "LCD" it is you are talking about there's a pretty strong chance someone has already written some "library" code to support it. So there a probably functions available like lcd_init(), lcd_putchar() and lcd_putstring(). But as the others have said you will have to say what kind of LCD display it is first. I'm guessing that of the choices Lee showed it's most likely to be something like:

Image result for lcd
if it is then the kind of code you are looking for is "HD44780" - it is VERY common.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, I would shun 7 segments, as they are complicated to program (eat 7+n pins, if multiplexing n denotes the number of digits you want to display or the length of the bargraf; if they are not multiplexed, change "+" into "*" .... and current consumption is likely to increase, too). They may be more expensive than other types...

 

Nobody can give a ready solution with graphic (monochrome? colored? I2C interface?SPI interface? other?) displays, without a crystal ball or telepathic talents. Edited : some maybe cheaper, now, than character devices....

 

For character based LCD, http://www.johanekdahl.se/rwiki/... gives links to documentation, fully tested libraries and a simple, demo oriented  library  (carefully initialises the LCD; send a char to the LCD and goes to the next position).

I suppose you have a 16x1 char LCD, and a 16 bits rawvalue (0..1023)

integer result (in volts) is (rawvalue*5)/1023, very near (0.1% error, less than usual 5v references) (rawvalue*5)/1024 -> this value can be converted into an integer, and send, char after char, to the LCD.

Then comes a decimal point -> sending it to the LCD is very trivial

Suppose yoy want 1+2 digits (ex : display 2.57) decimal part is ((rawvalue *500uL) /1024uL)  % 100 ; then, one justs has to convert it into decimal, with leading zeroes,  and send each and every char to the LCD

 

 

For an horizontal bargraph it should be  say, max 16 chars long (and a char like '*' or '#' might be pretty)

you divide the maximum voltage into 1024/16 values == 64 value

 

for (int iv =  0; iv  < rawvalue; iv = iv +64)  LcdSendByte  LcdSendCharacter ("#') ; // edited....

might  be enough....

 

Last Edited: Mon. Jun 26, 2017 - 05:59 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
there's a pretty strong chance someone has already written some "library" code to support it.

Likewise for reading the ADC.

 

Ahad Maqsood wrote:
Please guide me through it.

The most important thing is not to try to do everything all at once!

 

Start simple; Take it one step at a time.

 

eg, start by just writing fixed text such as "Hello, World!" to the LCD.

 

Then add a fixed number.

 

Then a run-time variable number - just a count in a loop.

 

etc, etc, ...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The standard HD44780 char LCD display can have custom chars you can program to form the "ends"  of the bars...then use the built-in solid block chars also, as needed.  The custom chars can be changed  "on the fly", if needed.  Perhaps some of the mentioned libs have such features.

 

You could easily use fixed point for the calcs, though there seems to be plenty of room for floating point overhead.

When in the dark remember-the future looks brighter than ever.