After Adc Conversion,store At Where??

Status
Not open for further replies.

babboy12345

New Member
If I Feed A 1v Sine Wave Signal To Adc,after Conversion Done,will Store At ADRESH AND ADRESL.My question is ,adc use 2.5v/1024 = 2.44mV,if i wan show 1v means = hex 19A. In 10bits form is 01 1001 1010 . If i need to minus 19A hex to zero, means i need use both adresh and adresl???
 
Last edited:
If you want 10 bit resolution then you need both registers, but if you only want 8 bit, you can configure the ADC accordingly - check my tutorials.
 
you mean tutorail 11?? Nigel,if i just wan convert 0.1v to adc, means i just need HEX 0x29,only 6bits rite? Is that the 6 bits at ADRESH? i read ur tutorail already,but not understand why u use both adresl and adresl.
 
you mean tutorail 11?? Nigel,if i just wan convert 0.1v to adc, means i just need HEX 0x29,only 6bits rite? Is that the 6 bits at ADRESH? i read ur tutorail already,but not understand why u use both adresl and adresl.

Because I'm using the ADC as 10 bits resolution - it would seem foolish to write a program to only use a small part of the ADC range. If you want lower resolution, then configure it for 8 bits, then you just need a single register, and it's in the correct bank.
 
bRO NIGEL. NOW MY getAD correct?? can pls tell me if got wrong?

Code:
getAD	bsf		ADCON0,GO
		btfsc	ADCON0,GO
		goto	$-1 
		
		movf	ADRESH,W
		return
 
You're using BSF instead of BCF, check my analogue tutorial.

I'm presuming you're clearing ADFM to make it 8 bit?.
 
i'm using 10bits resolution , Nigel, please check my code again,because i had change it after reading your tutorial again.

Code:
		LIST P=16F877A
		INCLUDE "P16F877a.inc"
		



status	EQU	0x03
TRISA	EQU	0X85
PORTA	EQU	0X05
TRISB	EQU	0X86
PORTB	EQU	0X06
CHK1 	EQU 	0X21
CNT1	EQU	0CH
CNT2	EQU	0DH
count	EQU	0x20h
NumH	equ	0x22h

		org		0x000
		nop		
		
		BSF		STATUS,RP0
		
		MOVLW	H'FF'
		MOVWF	TRISA
		movlw	H'00';
		movwf	TRISB;

		banksel	PORTA	
		BCF		STATUS,RP0
		clrf 	PORTB

		banksel	ADCON1
		movlw	b'10000000'
		movwf	ADCON1

		banksel	ADCON0
		movlw	b'10000001'
		movwf	ADCON0
		goto	start

getAD		bsf	ADCON0,GO
		btfsc	ADCON0,GO
		goto	$-1
		
		banksel	ADRESH
		movf 	ADRESH,w
		movwf	NumH
		return		

delay		MOVLW	D'5'
		MOVWF	CNT2

CON1		MOVLW	H'FF'
		MOVWF	CNT1
		DECFSZ	CNT1,1
		GOTO	$-1
		DECFSZ	CNT2,1
		GOTO	CON1
		RETURN

start	call 	getAD		; get adc result store at NumH
		sublw	0x29	 ;adc result in NumH will minus with 0x29....
		btfss	status,2 ;jump to  bsf if after subwf is = zero
		goto	start	;if not = zero,start again
		bsf	PORTB,0
		call	delay
		end
 
Last edited:
You're not using it as 10 bit, you're only using it as 2 bit, as you're only reading the top two bits of the conversion. To use 10 bit's you have to use BOTH registers.

If you clear ADFM instead of setting it, that code should give you 8 bits.

There's also no need for the 'banksel ADRESH' as that's already in the correct bank.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…