Good day!
Hi, I'm a newbie in microcontroller interfacing and I would like to seek help.
Our project was to make an RC-meter using PIC18F4455 and right now, I'm working on the resistance-meter of our project.
The simple schematic I used is attached here.
The code with comments is shown below.
Currently I am testing if I have set up the ADC configuration correctly, so I am sending the contents of ADRESH and ADRESL registers to the hyperteminal of my PC using serial communication (RS-232).
I am using VDD (5V) for Vref+ and VSS (GND) for Vref-. I also initially set the resistors to be equal so I can expect a VDD/2 (2.5V) on pin AN0. I based my calculations for setting the acquisition time and conversion clock from the ADC tutorial of Gooligum electronics.
However, the problem is that no matter what values of resistors I used, I am sending the same characters to the hyperterminal.
Does anyone know why? Is it because I configured the ADC wrong? Am I missing something in the hardware? Or I have wrong computations?
Any help, comments, suggestions, links, references would really help!
Thank you so much!
Hi, I'm a newbie in microcontroller interfacing and I would like to seek help.
Our project was to make an RC-meter using PIC18F4455 and right now, I'm working on the resistance-meter of our project.
The simple schematic I used is attached here.
The code with comments is shown below.
Rich (BB code):
#include<P18F4455.INC>
;203008 - pickit number
CONFIG FOSC = INTOSC_EC
CONFIG WDT = OFF
CONFIG PBADEN = OFF
CONFIG MCLRE = ON
CONFIG DEBUG = ON
CONFIG ICPRT = ON
CONFIG LVP = OFF
CONFIG PWRT = ON
ORG 0x000
GOTO MAIN
MAIN
; configure clock
MOVLW b'01110010' ; set internal oscillator to 8MHz
MOVWF OSCCON
; configure serial communication
MOVLW b'10000000' ; to access Tx and Rx pins
MOVWF SPEN
MOVLW b'11111111' ; use alternate function
MOVWF TRISC
MOVLW b'00100100' ; transmit enabled; high speed baud rate
MOVWF TXSTA
MOVLW b'10010000' ; serial port enabled; receiver enabled
MOVWF RCSTA
CLRF BAUDCON
MOVLW d'25' ; for 19.2 kbps baud rate
MOVWF SPBRG
; configure ADC
MOVLW b'00000001' ; use AN0 for analog input, ADC enabled
MOVWF ADCON0
MOVLW b'00001110' ; Vdd=5, Vss=GND, only AN0 is analog
MOVWF ADCON1
MOVLW b'00010001' ; left-justified, 4 TAD, Fosc/8
MOVWF ADCON2
MAIN_LOOP
; pseudocode:
; wait 10us acq time
; begin conversion
; wait until completed (polling GO/DONE bit)
; begin transmission
; repeat
BSF ADCON0,1 ; begin conversion
WAIT_ADC
BTFSC ADCON0,1
GOTO WAIT_ADC ; wait til finished
; begin transmission
TRANSMIT1
BTFSS PIR1,TXIF
GOTO TRANSMIT1
MOVLW ADRESH
MOVWF TXREG
CLRF TXREG
TRANSMIT2
BTFSS PIR1,TXIF
GOTO TRANSMIT2
MOVLW ADRESL
MOVWF TXREG
GOTO MAIN_LOOP
END
I am using VDD (5V) for Vref+ and VSS (GND) for Vref-. I also initially set the resistors to be equal so I can expect a VDD/2 (2.5V) on pin AN0. I based my calculations for setting the acquisition time and conversion clock from the ADC tutorial of Gooligum electronics.
However, the problem is that no matter what values of resistors I used, I am sending the same characters to the hyperterminal.
Does anyone know why? Is it because I configured the ADC wrong? Am I missing something in the hardware? Or I have wrong computations?
Any help, comments, suggestions, links, references would really help!
Thank you so much!
Attachments
-
9.6 KB Views: 18