Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

10bit to 8bit

Status
Not open for further replies.

Eng.Abbasi

New Member
hello every one
i have a question about the adc of pic16f877a
how can i use 256 level of quantization not 1024 (8 bit instead of 10bit)
i have an idea but if some one comment on it or give another idea i'll be grateful

2^10/2^8 = 4
so i can assign one from each 4 level to one level as :
0--->0
1,2,3 are neglected
4-->1
5,6,7 are neclected
8-->2
and so on
help me plz
 
Just set the ADC to left justified by clearing bit ADFM (bit 7 of ADCON1) and only read the high byte (ADRESH) of the ADC converter.

Mike.
 
Hi,
if you want to use 8 bit and if you use picbasic pro,it is very simple :

x var byte
adcin 0,x ' 0 is the number of adc channel and x is the variable

by that instruction the 8 bit adc from channel one is put in the x variable
 
Last edited:
If it was me I would read the 10 bits and use a rounding algorithm. If the low two bits are 00 or 01 drop them and take the most significant 8 bits. It the low two bits are 10 or 11, then round up by adding 1 to the most significant eight bits.
 
Wouldn't a rounding algorithm give incorrect values. For example, if you set VRef to 2.56V then a reading of one should represent 10mV. With rounding, 5mV will give a reading of 1.

Mike.
 
Doesn't rounding works both ways?

Without rounding, 9mV would yield a 0 result. So it will depend on the significance of the result and the way the user wants it to be.
 
Fairly obviously, binary rounding isn't much use, as there's no fractions to round!.

As suggested in the first reply it's EXTREMELY simple to just use the top 8 bits, and the PIC even has a flag you can set to do this - as reading the datasheet (or my tutorial) shows.
 
simple answer is just bit shift it right by 2 places
i do it all the time in basic on the 877A

temp_res = Adc_Read(2) >> 2 ' read adc pin 2 and shift right 2 places

reads a 10 bit val and gives 8 bit answer in temp_res
 
Nigel Goodwin said:
Fairly obviously, binary rounding isn't much use, as there's no fractions to round!.

As suggested in the first reply it's EXTREMELY simple to just use the top 8 bits, and the PIC even has a flag you can set to do this - as reading the datasheet (or my tutorial) shows.
I'm actually a bit surprised at this answer, since I can place the binary point anywhere I choose within the word. I find "binary rounding" quite useful in many contexts.
 
Papabravo said:
I'm actually a bit surprised at this answer, since I can place the binary point anywhere I choose within the word. I find "binary rounding" quite useful in many contexts.

i guess Mr. nigel is generally true becuase when i want to devided the redundant two bit equally on the whole signal so i have to move four bit four bit [(2^10)/(2^8)=4] then i can remove the three bits between them , this is work when i want general application (my analog data not concentrate redundantly on certain region and little in other ).
this as i thought.
 
Papabravo said:
I'm actually a bit surprised at this answer, since I can place the binary point anywhere I choose within the word. I find "binary rounding" quite useful in many contexts.

Please give an example?.

I can't see any use for it?, but I'm willing to be convinced!
 
p3t3rv said:
simple answer is just bit shift it right by 2 places
i do it all the time in basic on the 877A

temp_res = Adc_Read(2) >> 2 ' read adc pin 2 and shift right 2 places

reads a 10 bit val and gives 8 bit answer in temp_res

That would be the obvious answer on an inferior device, but PIC's are generally quite clever, and (as already given) by setting a single bit in a register you get a direct 8 bit result. Faster and easier than a 10 bit, never mind a ten bit scaled down to 8 bit - although speed is rarely a concern.

If you're limited to using PIC BASIC though, limitations of the compiler may prevent you?.
 
Papabravo said:
I'm actually a bit surprised at this answer, since I can place the binary point anywhere I choose within the word. I find "binary rounding" quite useful in many contexts.
Nigel's "style" is providing authoritative unqualified opinions and comments that often infer "the right way", "the only way", or "my way". The "right way" and "only way" comments only seem to invite correction (and/or criticism) on rare occasions when they're based on not quite up-to-date knowledge or experience in certain areas. Nothing that a couple well chosen qualifiers couldn't fix. I'm afraid you'll never get him to budge on "my way" clashes (grin).

Mike
 
Mike said:
Nigel's "style" is providing authoritative unqualified opinions and comments that often infer "the right way", "the only way", or "my way". The "right way" and "only way" comments only seem to invite correction (and/or criticism) on rare occasions when they're based on not quite up-to-date knowledge or experience in certain areas. Nothing that a couple well chosen qualifiers couldn't fix. I'm afraid you'll never get him to budge on "my way" clashes (grin).

I'm happy to be convinced! - do you have any views on 'binary rounding'?.
 
Mike said:
Nigel's "style" is providing authoritative unqualified opinions and comments that often infer "the right way", "the only way", or "my way". T

Mike

Finally some one, \_/\/\/\_/

Sorry Nigel its thru .


Steve
_____
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top