PDA

View Full Version : How do I use 10 bit A/D on 8 bit Pic? 12F675



polymer52
- 9th December 2009, 22:24
How do I input the 10 bit A/D value, do math on it and use the value in the program or output it to debug?
All the examples I've seen only use 8 bits.
Does it have to be split into 2- 8 bit bytes then ...?

mackrackit
- 10th December 2009, 00:33
Yup, needs split.
A couple of the hard to find examples.... can be found here

http://www.melabs.com/resources/samples.htm

and here is one on the forum
http://www.picbasic.co.uk/forum/showthread.php?t=11947

Charles Linquis
- 10th December 2009, 00:40
You don't need to split it. Just save it in a WORD variable. Yes, the PIC is an 8-bit device, but can easily work on number 16 bits long.

polymer52
- 10th December 2009, 13:29
Ok so if I read that right I can store the highbyte & lowbyte A/D value in a word variable (adval) then I can do math on the entire 10 bits of the word?
For example:


ADCIN 0, adval ' Read channel 0 to adval

adval=adval *2/10 'do math on 10 bit adval

Debug "A/D Value: ",dec adval,10,13 'Send decimal value out

mackrackit
- 10th December 2009, 16:44
Yes, that should work. Just watch that the math does not over flow the word size var.

polymer52
- 10th December 2009, 18:11
Yes, that should work. Just watch that the math does not over flow the word size var.

So I can actually do 16 bit math?
Cool!
Thanks

mackrackit
- 10th December 2009, 18:52
And if you use an 18F part with PBP2.5 or greater you can do 32 bit math.
http://www.melabs.com/resources/articles/longs.pdf

n0yox
- 1st April 2020, 16:51
Can anyone tell me what I am doing wrong? This code just returns " 0 0 " with 3 volts on gpio.0

DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50

CMCON = 7
ANSEL = %00000001
ADCON0.7 = 1
TRISIO = %00000001
adval var word
ADH var word
ADL var word
over:
pause 1000
ADCIN 0, adval ' Read channel 0 to adval
Serout2 5,16488,[#adval.HighByte," ",#adval.LowByte,13]
goto over

n0yox
- 1st April 2020, 20:10
I got it fixed it was a hardware issue. Thank you!