A to D conversion 16f690 help....

Thread Starter

Dodgydave

Joined Jun 22, 2012
9,953
:eek:
I am trying to do a simple a/d conversion using the 16f690 pic using the microchip assy board, i want to alter the voltage on port AN0 with a pot and display the result on portc with leds..ok

but how do you do it??
 

Thread Starter

Dodgydave

Joined Jun 22, 2012
9,953
PORTc is 8 bits wide portb is 4 port a is 6

yes i have got the cds with the programmer


this is what i have so far>>

Rich (BB code):
  BSF STATUS,RP0 ;Bank 1
 BCF STATUS,RP1 ;
 MOVLW b'01110000' ;A/D R/C osc
 MOVWF ADCON1 ;
 BSF TRISA,0 ;Set RA0 to input
 clrf TRISC
 clrf TRISB ; set port c output
 BCF STATUS,RP0 ;Bank 2
 BSF STATUS,RP1 ; 
 BSF ANSEL,0 ;Set RA0 to analog
 clrf ANSELH ; set port b/c to digital I/O
 BCF STATUS,RP1 ;Bank 0
 MOVLW b'10000001' ;Right just, Vdd Vref, AN0 source input
 MOVWF ADCON0 ;
More
 
 BSF ADCON0,GO ;Start conversion
 BTFSC ADCON0,GO ;Is conversion done?
 GOTO $-1 ;No, test again
 MOVF ADRESH,W ;Read upper 2 bits
 MOVWF RESULTHI ;
 BSF STATUS,RP0 ;Bank 1
 MOVF ADRESL,W ;Read lower 8 bits
 BCF STATUS,RP0 ;Bank 0
 MOVWF RESULTLO
    clrf PORTB
  movfw RESULTLO
 movwf PORTC
 
 goto  More
 
        end
 
Last edited by a moderator:

t06afre

Joined May 11, 2009
5,934
This is the ADC example. I think your code is missing some parts
Rich (BB code):
; PICkit 2 Lesson 4 - "A2D"
;
; This shows how to read the A2D converter and display the
; High order parts on the 4 bit LED display.
; The pot on the Low Pin Count Demo board varies the voltage 
; coming in on in A0.
;
; The A2D is referenced to the same Vdd as the device, which 
; is provided by the USB cable and nominally is 5V. The A2D
; returns the ratio of the voltage on Pin RA0 to 5V. The A2D
; has a resolution of 10 bits, with 1023 representing 5V and
; 0 representing 0V.
;
; *******************************************************************
; * See Low Pin Count Demo Board User's Guide for Lesson Information*
; *******************************************************************
; * NOTE: The PIC16F690 requires the AC162061 header for debugging *
; *******************************************************************
#include <p16F690.inc>
__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)
cblock 0x20
Delay1 ; Assign an address to label Delay1
Delay2
Display ; define a variable to hold the diplay
endc

org 0
Start:
; select Register Page 1
movlw 0xFF
banksel TRISA
movwf TRISA ; Make PortA all input
clrf TRISC ; Make PortC all output
movlw 0x10 ; A2D Clock Fosc/8
movwf ADCON1
banksel 0
;bcf STATUS,RP0 ; back to Register Page 0
bcf STATUS,RP0 ; address Register Page 2
bsf STATUS,RP1 
movlw 0xFF ; we want all Port A pins Analoga
movwf ANSEL
bcf STATUS,RP0 ; address Register Page 0
bcf STATUS,RP1

movlw 0x01
movwf ADCON0 ; configure A2D for Channel 0 (RA0), Left justified, and turn on the A2D module
MainLoop:
nop ; wait 5uS for A2D amp to settle and capacitor to charge.
nop ; wait 1uS
nop ; wait 1uS
nop ; wait 1uS
nop ; wait 1uS
bsf ADCON0,GO ; start conversion
btfsc ADCON0,GO ; this bit will change to zero when the conversion is complete
goto $-1
swapf ADRESH,w ; Copy the display to the LEDs
movwf PORTC
goto MainLoop
end
 
Top