Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

pic16f876 ADC problem

Status
Not open for further replies.

suwaii

Member level 4
Joined
Jan 21, 2006
Messages
68
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,830
i try to convert analog to digital using pic16f876 and input signal= 3v
Vref+=5v,Vref=0....so that we sould get 3*1024/5=614 decimal= 266 hex
when we make ADFM=1 and we use this code:
movfw ADRESL
movwf PORTC

movfw ADRESH
movwf PORTB


we get the result only the ADRESH=2 on portB and portC
but we do not get ADRESL whis equal to 66 on portC
why... could any on tell me how we make ADRESH on portB and the same tme
ADRESL=portC to get 2 on portB and 66 on portC

and this is the complete code :



list p=16f876
#include <P16f876.INC>

ERRORLEVEL -302


wait EQU 0x20

init

bsf STATUS, RP0 ; auf Bank 1 umschalten
movlw B'00000000' ; PortB alle output
movwf TRISB
movwf TRISC
bcf STATUS, RP0 ; auf Bank 0 zurückschalten
clrf PORTB ; alle LEDs ausschalten
clrf PORTC

BSF ADCON0, 0 ; ADON=1


BCF ADCON0, 5 ; ADCHS2=0
BCF ADCON0, 4 ; ADCHS1=0
BCF ADCON0, 3 ; ADCHS0=0


BSF ADCON0, 7 ; ADCS1=1
BSF ADCON0, 6 ; ADCS0=1


BSF STATUS,RP0 ; Bank1
BSF ADCON1, 7 ; ADFM=1
BCF STATUS,RP0 ; Bank0




Main

BSF ADCON0, 2 ; ADC starten
loop
BTFSC ADCON0, 2 ; ist der ADC fertig?
GOTO loop ; nein, weiter warten



movfw ADRESL ; obere 8 Bit auslesen
movwf PORTC


movfw ADRESH ; obere 8 Bit auslesen
movwf PORTB ; obere 8 Bit nach PortB



clrf wait
warten
DECFSZ wait, f
goto warten

goto Main

end
 

Hi,

You forgot bank addressing... You have to change to bank1 to access ADRESL.

Something like this:
Code:
movf	ADRESH,	W
movwf	Hi

bsf	STATUS, RP0	;ADRESL	is in the BANK1
movf	ADRESL,	W	;Get A/D result	(low byte)
bcf	STATUS, RP0
movwf	Lo

Hi:Lo contains your ADC. HTH.

Regards,
Admir.
 

Hi
Yes u forgot bank addressing
if you are using mplab
u can type
banksel ADRESL

then don't forget to return back to bank0.

I myself use the following macros instead

Code:
BANK0 macro
 BCF		STATUS,RP1
 BCF		STATUS,RP0
 endm
BANK1 macro
 BCF		STATUS,RP1
 BSF		STATUS,RP0
 endm
BANK2 macro
 BSF		STATUS,RP1
 BCF		STATUS,RP0
 endm
BANK3 macro
 BSF		STATUS,RP1
 BSF		STATUS,RP0
 endm

then u can use this code to get the A2D value

Code:
GET_ANALOG
		BSF		ADCON0,GO
G_REDO	
		BTFSC	ADCON0,GO
		GOTO	G_REDO
		BANK1
		MOVF	ADRESL,W		
		BANK0
		MOVWF	PORTB
		MOVF	ADRESH,W
		MOVWF	PORTC
		RETURN
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top