ADCH 8bit --> 2 x 4 bit conversion

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

Hey AVRFreaks

When you read the ADC0 on an Atmega8, you get an 8bit value in the ADCH. I hope I'm correct on that.

I want to display the ADC reading on 2 x 7 segment displays that is connected to one 74HCT47 7 segment driver and I control the displays with transistors. The ADC data will be shifted into a shift register, one display switched on, switched of again then the next display's data will be shifted into the shift register.

Now the question, how do I split the data in ADCH that is 8 bits so that I can send the first 4 bits to the shift use those bits and then shift in the next 4 bits and use them then?

Regards,

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

Quote:
When you read the ADC0 on an Atmega8, you get an 8bit value in the ADCH.
Well, you can get an 8 bit value in ADCH. You will have to tell the ADC to do that, though.
Quote:
Now the question, how do I split the data in ADCH that is 8 bits so that I can send the first 4 bits to the shift use those bits and then shift in the next 4 bits and use them then?
You don't. An 8 bit value has the range of 0 to 255, so you need 3 digits to display the value. Unless, of course, if you want hexadecimal output (and your 7 segment drivers can handle it), then you just output the 4 bits you want for each display.

Regards,
Steve A.

The Board helps those that help themselves.

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

Quote:

Quote:
Now the question, how do I split the data in ADCH that is 8 bits so that I can send the first 4 bits to the shift use those bits and then shift in the next 4 bits and use them then?
You don't. An 8 bit value has the range of 0 to 255, so you need 3 digits to display the value.

Unless the value is displayed in hex..

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"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

Koshchi wrote:
You don't. An 8 bit value has the range of 0 to 255, so you need 3 digits to display the value.

I can add the third display but I doubt if the measurement would go up do 80 so a third display will propebly never be used. Come to think of it, I'll add the third display for futue expansion.

The shift register contains 8 values, but only 4 lines are hardwired and the other 4 pins is NC.

WIll it work if I shift in the 8 bits, switch the first display (only 4 bits will be utilised as only 4 is wired) then I clock the shift 4 more times to shift the data 4 bits then switch the next display?

Regards,

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

Quote:

I can add the third display but I doubt if the measurement would go up do 80 so a third display will propebly never be used.

Which suggests you ADC voltage never exceeds 80/256 * Ref? If Ref=5V then are your readings all below 1.56V. Or are you saying you are performing some conversion on the ADCH value after you've read it to limit its range to 0..80?

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

There is no conversion ans the max voltage read will be about 1.2V.

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

Quote:
I can add the third display but I doubt if the measurement would go up do 80 so a third display will propebly never be used.
This implies that you want to display a decimal value. Then a simple split into 2 x 4 bit won't help you. You need to split it like this:

uint8_t digit0 = adc_value % 10;
uint8_t digit1 = adc_value / 10;

Stefan Ernst

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

O yes, that rings a bell, I completely forgot about that.

Thanx, I'll give it a try.

It's been way too long since I last did some programming......it's a shame that it took me so long to start again.

Thanx sternst

Edit: Thanx, it worked, now just to play around with the values a bit.