PDA

View Full Version : 16F88 ADC Problems



fanman
- 14th June 2011, 13:20
Hi guys, I'm new to this. I'm trying to get my PIC 16F88 to read in analogue on RB6 & RB7 and strobe a LED on RB2. I can get the LED to light up but it appears that the ADC is not reading in any values. I'm having problems configuring the ADC. Please help !!!

I have included the main part of my program below..... :o

Thanks

--------------------------------------------------------------------------

define OSC 20 '20MHz Must set Osc to HS when programming not XTL
'
' Set CONFIG1: --11 1111 0110 1110
' Set CONFIG2: ---- ---- ---- --11
'
INCLUDE "modedefs.bas" ' Include for SEROUT command
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 1 ' Set clock source, not sure if this is correct
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds
' Set ADC Registers
TRISB = %11111011 ' 1=In, 0=Out
ANSEL = %01111111 ' 1=Analogue, 0=Digital
ADCON0 = %10111000 ' Configure and turn on A/D Module.
ADCON1 = %10000000 ' Right Justify A/D result
ADCIN PORTB.6, Accel ' Read channel 5 to Accel
ADCIN PORTB.7, Gain ' Read channel 6 to Gain
pause 1000
serout 2,N9600,["g = ", #Accel," gain = ", #Gain,10,13]
high PORTB.2 'drive LED high


--------------------------------------------------------------------------

mister_e
- 14th June 2011, 17:33
ADCIN must use the ADC channel number, not it's pin name

ADCIN 5, Accel ' Read channel 5 to Accel
ADCIN 6, Gain ' Read channel 6 to Gain

fanman
- 14th June 2011, 23:47
Thanks Steve, but how does the ADC know which port to read in? For example, we could read in PortA.1 or PortB.1

cheers

Mark.

mister_e
- 15th June 2011, 02:12
It's all about it's associated Channel number.

http://www.twig.com.au/store/images/PIC16F88.jpg?osCsid=13106714300590cf7b6a1f522d69af b9


PortB.0.= AN0 = Channel 0 = ADCIN 0, bVar
PortB.7 = AN6 = Channel 6 = ADCIN 6, bVar


PBP manual:



ADCIN

ADCIN Channel,Var

Read the on-chip analog to digital converter Channel and store the result in Var. While the ADC registers can be accessed directly, ADCIN makes the process a little easier



Manual Really said Channel... not pin name.

Further details, open the datasheet, and see how you manually implement it... you also select/assign a channel number to the PIC register, not a pin name.



hth