I am having a problem with using a math formula to calculate
a PPM value from an ADC reading. I am reading a 0-5 volt
on my input with 10 bit resolution. On the output I see
that the adc value is working as it should. Lets say I get
a reading on the ADC of 11260. When run through the line
"ppm = (AD/64320)*5000" the ppm variable should contain
875.31. When I run the code on the PIC and debug to my
serial port PPM = 0. I am doing something wrong? Any help
would be greatly appreciated. :^)
Source code follows below:
'----[ INCLUDES / DEFINES ]----
include "modedefs.bas" 'Include serout defines
'----[ VARIABLES ]----
SO VAR PORTB.7 ' Define serial output pin
SI VAR PORTB.5 ' Define serial in pin
TEMPB var byte
AD var word ' ADC Channel 0 Conversion Value
PPM var word ' Parts Per Million
'----[ INITIALIZATION ]----
ANSELH = %00000001
TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10000010 ' Set PORTA analog and right justify result
TRISB = %01110000 'SET PORT B PINS TO OUTPUT EXCEPT PORT RB5 (RX)
PORTB = %00000000 'INIT PORT B TO ALL ZEROS AND POWER LED OFF
'----[ MAIN CODE ]----
Main:
ADCIN 0, AD ' Store value of analog input in AD0
Serout SO,N2400,["ADC0 -> ",#AD,10,13]' Print Data
ppm = (AD/64320)*5000
Serout SO,N2400,["ADC0 PPM -> ",#ppm,10,13]' Print Data
Pause 2000
Goto MAIN
Bookmarks