PDA

View Full Version : PIC18F14K50 ADC problem



picmilan
- 31st July 2016, 00:09
Hello again!

I am trying to get ADC working using AN7 pins but I keep getting zero for PORTC.7 and 20 when I use ADCIN 7.I am using a 24 MHz crystal.
It worked with PIC18F2450 but doesn't work with PIC18F14K50.


Here is my code:


DEFINE LOADER_USED 1
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_BAUD 115200
DEFINE HSER_SPBRG 12
DEFINE HSER_CLOERR 1

DEFINE OSC 24

ADCON0 = %00011100
ADCON1 = %00000000
ADCON2 = %10110101

ANSEL = %10001000
ANSELH = %00000011

TRISC.4 = 0 'led RC4
TRISC.6 = 1

TRISC.0 = 0
TRISC.1 = 1
TRISB.5 = 1 'RX
TRISB.7 = 0 'TX
adcVal VAR Byte
tx1 VAR PORTB.7
rx1 VAR PORTB.5

LED VAR PORTC.4
Pause 1000
MoveX = 0
mainloop:


high LED
Pause 1000
ADCIN 7, adcVal
HSEROUT[adcVal]
low LED
Pause 1000
Pause 200
Goto mainloop

I thing the problem is configuration again.Would appropriate any help.

richard
- 31st July 2016, 00:50
ADCON2 = %10110101


adcin does not support acqt


ADCON2 = %10110101

@24 MHz fosc/16 is out of specs use fosc/32



ADCIN 7, adcVal

without setting any defines is asking for trouble





DEFINE ADC_BITS 8
DEFINE ADC_CLOCK 3 or 2

DEFINE ADC_SAMPLEUS 50