PDA

View Full Version : I neat some help on 12F675 ad



Kmt
- 22nd November 2007, 16:28
Hi

I have make this program, but i have some problems with the AD 0 on a 12F675. I try to measure m volt (400mV) on this, it look to be ok, then the mV drobt dovn to 200mV, and the output4( gipo4) shut go low after som time, but it stay high???..
But if i drobt the it down to 0V output 4 go low.

Can som body on thi forum help me on this.

This is the program.

@ DEVICE pic12F675, INTRC_OSC_NOCLKOUT
@ DEVICE pic12F675, WDT_ON
@ DEVICE pic12F675, PWRT_ON
@ DEVICE pic12F675, MCLR_OFF
@ DEVICE pic12F675, BOD_ON
@ DEVICE pic12F675, CPD_OFF
@ DEVICE pic12F675, PROTECT_OFF

DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50
DEFINE OSC 4


'GPIO.0 AD 0
'GPIO.1 AD 1
set VAR GPIO.2
relae VAR GPIO.4
led2 VAR GPIO.5


ledlys VAR BYTE
setpt1 VAR WORD
gange VAR BYTE
adval0 VAR WORD
adval1 VAR WORD
i VAR BYTE
relaeset VAR BIT
time VAR BYTE


CMCON = 7 'comparators off
ANSEL = %00110011 'GPIO.0,1 - A/D in ,rest digital
ADCON0.7 = 1 'right justify for 10 bit
TRISIO = %00000111 'GPIO.0 = input, rest output

relaeset = 0
relae = 0
time = 0
ledlys = 0


Main:
GOSUB laesead
If set = 1 THEN
i = 1
FOR i = 1 TO 75
led2 = 1
PAUSE 50
led2 = 0
PAUSE 50
NEXT i
IF set = 1 THEN ' Save setpt
led2 = 1
GOSUB setpt
PAUSE 5000
relae = 1
relaeset = 1
led2 = 0
time = 0
ELSE
relae = 1
relaeset = 1
time = 0
ENDIF
ENDIF
IF (adval0 > setpt1) AND (relaeset = 0) THEN 'turn on
relae = 1
relaeset = 1
time = 0
ENDIF
IF (adval0 <= setpt1) AND (relaeset = 1) THEN
time = time + 1
IF time = 6 THEN
relae = 0
relaeset = 0
ENDIF
ELSE
time = 0
ENDIF
IF ledlys < 2 THEN
ledlys = ledlys +1
ENDIF
IF ledlys => 2 THEN
IF adval1 < %1111001100 THEN ' low batteri
i = 1
FOR i = 1 TO 10
led2 = 1
PAUSE 250
led2 = 0
PAUSE 250
led2 = 1
PAUSE 250
led2 = 0
PAUSE 250
NEXT i
ENDIF
led2 = 1
pause 15
led2 = 0
ledlys = 0
ENDIF
NAP 7
NAP 7
NAP 7
NAP 7
NAP 7
NAP 7
GOTO main

setpt:
GOSUB laesead
setpt1 = adval0
RETURN

laesead:
'adval0 = 0
ADCIN 0, adval0 'read ad0 mv
ADCIN 1, adval1 'read ad1 batteri
RETURN


END


Thaks

Kent

mister_e
- 22nd November 2007, 17:01
i haven't check your whole code and it's logic, but i'll suggest you to send the result of your ADC result to your PC to see what happen with your result.

You may need to do some averaging and/or use external filter to smooth your results, try to put a 0.1uF capacitor on each ADC input and see if it do something better.

If you have any, please post your schematic.

Kmt
- 22nd November 2007, 18:48
I have found the fault, i reset a variabel whole time, it work now.

I will put a0.1uF capacitor on each AD. thanks Mister e

Kent