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.

Help with pic16f684 adc

Status
Not open for further replies.

slimjims

Newbie level 3
Joined
Jun 19, 2011
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,303
It's been awhile since I've attempted any assembly programming, and I always remember having lots of trouble debugging. Anyways I'm to get back into it, I'm trying to read voltage values from a photo-resistor. Everything seems to work fine except the only values that are returned are 0x01 and 0x61. I can't figure out what might be causing the problem everything seems to be exactly how it should be.

Code:
;	
LIST R=DEC
LIST P=16f684
INCLUDE p16f684.inc
INCLUDE macros.inc
 __CONFIG _FCMEN_OFF & _IESO_OFF & _BOD_OFF & _CPD_OFF & _CP_OFF & _MCLRE_ON & _PWRTE_ON & _WDT_OFF & _INTOSCIO


 PAGE
 org    0
;Configure EEPROM
 bcf	STATUS, 5
 bcf	INTCON, GIE		; disable interrupts

 bank1
 clrf	EEADR
 clrf	EEDAT
;Configure ADC
 movlw	7
 movwf	CMCON0			; turn off comparator

 bsf	TRISA, 0		; set RA0 to input
 bsf	ANSEL, 0		; set ANS0 to analog input
 movlw	01010000b
 movwf	ADCON1			; clock set to Fosc/16

 bcf	STATUS, 5
 movlw	00000001b		;configure ADCON0
 movwf	ADCON0		
;Start process
;wait 8uS, maximum required aquisition time
;In this example I'm gonna use it to do any 
; eeprom maintennance. In this case write eedat to eeprom
 pauc	1
main: 
 bcf	STATUS, 5
 bsf	ADCON0, GO		; begin conversion
 btfsc	ADCON0, GO
 goto	$-1			; wait for completion
 movf	ADRESH, 1
 bank1
 movwf	EEDAT 




 bsf	STATUS, 5
 bsf	EECON1, WREN
 movlw	0x55
 movwf	EECON2
 movlw	0xAA
 movwf	EECON2
 bsf	EECON1, WR		; write begins

 btfsc	EECON1, WR
 goto	$-1			;wait for write to end
 nop
 nop
 incf	EEADR, 1
 bcf	STATUS, 5
 bcf	PIR1, EEIF
;back to ADC stuff


 tenth	8
 goto	main

end
 

Thanks for the response, I'm not sure how I missed that. :-? But after tweaking different values (clock speed, delays, etc.) I'm still at a total loss as to what could be preventing this from working. I've cleaned up the code a little, and if anyone wants to take a shot at fixing it I'd appreciate it.

Code:
LIST R=DEC
LIST P=16f684
INCLUDE p16f684.inc
INCLUDE macros.inc
 __CONFIG _FCMEN_OFF & _IESO_OFF & _BOD_OFF & _CPD_OFF & _CP_OFF & _MCLRE_ON & _PWRTE_ON & _WDT_OFF & _INTOSCIO

;  Variables
 CBLOCK 0x020
   count0
   count1
   count2
 ENDC


 PAGE
 org    0

eeprom_config:
 bank0
 bcf	INTCON, GIE		; disable interrupts
 bank1
 clrf	EEADR
 clrf	EEDAT


adc_config:
  bank0
  movlw	7
  movwf	CMCON0			; turn off comparator
  bank1
  movlw	01010000b
  movwf	ADCON1			; clock set to Fosc/16
  bsf	TRISA, 0		; set RA0 to input
  bsf	ANSEL, 0		; set ANS0 to analog input
  bank0
  movlw	00000001b		;configure ADCON0
  movwf	ADCON0		
  pauc	1                   ;delay macro  -  ten cycles


main:
  bsf	ADCON0, GO		; begin conversion
  btfsc	ADCON0, GO
  goto	$-1			; wait for completion
  movf	ADRESH, 1
  bank1
  movwf	EEDAT 

save:
  bsf	STATUS, 5
  bsf	EECON1, WREN
  movlw	0x55
  movwf	EECON2
  movlw	0xAA
  movwf	EECON2
  bsf	EECON1, WR		; write begins
  btfsc	EECON1, WR
  goto	$-1			;wait for write to end
  nop
  nop
  incf	EEADR, 1
  bcf	STATUS, 5
  bcf	PIR1, EEIF

 tenth	8                      ;delay macro   -   800 cycles
 goto	main

end
 

You should use the proper mneumonics for assembly instructions. "movf ADRESH, 1" in particular isn't moving the value into the W register.

Mike
 

Make port A as input (by entering values in TRISA)
movlw 7 .....you hav to specify whether it is hex,binary or digit movlw H'07' or movlw D'7' etc
use some delay instead of pauc 1
 

Thanks, that was the problem. I must have misread the instruction set summary or something.

---------- Post added at 18:10 ---------- Previous post was at 18:08 ----------

and thanks for that suggestion sankar.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top