PDA

View Full Version : help using adcin



harryweb
- 29th January 2006, 16:41
HI,
I'm newbie with adcin... I wrote this little prog for a pic16f87x, and it works fine.
DEFINE OSC 4
DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50
bat var word
temp VAR WORD
ADCON1 = 0

TRISB = %00000000
PORTB = 0

TRISA = 255
PORTA = 0
startval:
GOSUB measure
serout2 portb.0,84,[DEC bat," ",DEC temp," "]
PAUSE 1000
GOTO startval

measure:
ADCIN 0,bat
adcin 1,temp
RETURN

But now, I would like to use a pic18f1220 and there is something wrong... the value for "temp" is now always the same as "bat" (adcin 0 versus adcin 1).

Someone can explain ?
regards
Herve

mister_e
- 29th January 2006, 18:35
Chances are that the internal comparator are disabled at POR.

i'd tested it here and's working as it's supose to. So i'll guess on a hardware problem. Maybe a way to high impedance on the A/D inputs, bad PSU filtering,... or worst... a short circuit between them ;)

Sorry it's working here.

BTW, you can even try to increase the ADC_SAMPLEUS value.. maybe.

F1CHF
- 30th January 2006, 00:36
I'm working on same job but using a 16F88
i spend hours becaus a got garbagge on serial output
I find a solution
Increase define char_pacing !

by the way I have a problem .... value are not stable
one unit less .. one unit more ... input is done with two resistors !
quite strange ...

here is my poor job !
' program to display result of 10-bit A/D conversion on LCD
' Connect analog input to channel-0 (RA0)
adval var word
advalcd var word
advalcomp var word
DEFINE CHAR_PACING 1000

' Definition des parametres ADCIN
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS
TRISA = %00000001 ' Set PORTA to all input
ADCON1 = %10000000 ' Set PORTA analog and right justify result
Pause 500 ' Wait .5 second

loop: ADCIN 0, adval ' Read channel 0 to adval
adval.highbyte = ADRESH 'HIGH byte of result to adval
adval.lowbyte = ADRESL 'LOW byte of result to adval

Lcdout $fe, 1 'nettoyage ecran
Lcdout "ADVAL ", #adval 'Affichage de la valeur en decimal

serout porta.3,N9600,["Position = ",#advalcd," Degres "]
pause 500
Goto loop 'Do it forever
End

Dave
- 30th January 2006, 12:12
F1CHF, The probable reason for the A/D reading jumping around is the input has some noise on it and it is being digitized. With a 5 volt reference for the A/D the minimum resolution per bit is 4.9 Millivolts. You should either do some kind of analog filtering using an RC network or do some kind of software filtering. The A/D is only telling you what it sees. Also make sure you have a ROCK stable reference voltage at the PIC. If you have access to a scope, use it, you will be supprised at what you see...

Dave Purola,
N8NTA

F1CHF
- 30th January 2006, 23:31
Sir ... you got it !
I use to "play" with a homemade dev board with a lot of stuff things
like LCD, switches, push button, led, In situ prog, etc ...
this developpement board is OK for normal use.
In this case .. I discover that the small power supply has a 0.120 volt
ripple .. with some spikes !
2200 µF on the power itself, the well know trio of decoupling capacitors
near the +5 volts regulator, and also near VCC and VDD on the PIC !
you got it !
I have forgotten the basic rule of electronic .. have a CLEAN power supply!
it was clean for basic opération since 5 years ! not for analogique use !
you are the winner !

I am working on the following project :
Using an On Screen Display IC (STV5730) show the antenna rotor position
used in a radio amateur TVA repeater.
I need to find a very good potentiometer to avoid variations in the reading
thanks a lot 73's from F1CHF

harryweb
- 31st January 2006, 07:46
Bonjour CHF,

J'ai essayé avec ta méthode, sans succès.... bon c'était de la simulation et ce prg fonctionne (en simul) sur pic16f88, pic16f87x.... je vais essayer avec un vrai 18f1220.

Mais j'y pense, f1chf.... ne nous connaissons nous pas ? ce call me rappelle qq chose... du temps ou je faisais de l'émission OM et de la TVA... mon ex call F1SLU herve (pres de melun)

73's