riccardo-m 0 Newbie Poster

Hi,

I'm trying to use the 8-bit result from an ADC to make a time delay. It is working except that time delay is only increasing after the input goes above 2.5V. The input is 0V to 5V from a 1k POT.

Any ideas why it would not start working until half way?

It is a 12F675, Main code below...

; ADC CONFIGURATION
	BCF STATUS,RP0 				; BANK 0
	BCF ADCON0, ADFM			; Left justified (clear and use just ADRESH for an 8bit result)
	BCF ADCON0, VCFG			; Vdd reference
	BCF ADCON0, CHS1			; Set AN0 as analogue input
	BCF ADCON0, CHS0			; Set AN0 as analogue input
	BSF STATUS,RP0 				; BANK 1
	MOVLW b'00010001'			; Fosc/8 (2us), AN0 is selected for reading
	MOVWF ANSEL

; The output pulse with delay
DISCHARGE
	BSF DISCHARG				; DISCHARGE
	CALL READPOT
	CALL WAITPOT
	BCF DISCHARG				; END DISCHARGE
	RETURN

; Get analogue input
READPOT
	BSF ADCON0, ADON			; Enable AD
	BSF ADCON0, GO				; Start AD conversion
AD	BTFSC ADCON0, GO			; TEST if conversion is finished
		GOTO AD					; Loop until conversion is done
	MOVF ADRESH, W				; High side byte from AD (8-bit)
	MOVWF POT					; Stores ns delay value in POT
	BCF ADCON0, ADON			; Disable AD
	RETURN

; Time dealy
WAITPOT
	INCF POT	; make sure not zero
WAITPOTL
	DECFSZ  POT,F		; Decrement POT
        GOTO WAITPOTL	; Loop until 0
	RETURN
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.