Hi to all and Happy New year.
Today I receive a UV sensor ML 8511.
Watching his datasheet the output voltage is linear to intensity of the UV light.
How to measured voltage convert into a UV index.
Supply voltage PIC and the sensor is 5.0V
AD conversion is 10 bit and I use 18F4520 chip
Code example to measure voltage:
' ** Setup the ADCIN Defines **
Define ADC_BITS 10 ' Set resolution of conversion
Define ADC_CLOCK 2 ' Set clock source (x/FOSC or FRC)
Define ADC_SAMPLEUS 50 ' Set sampling time (in uS)
' ** Declare the Variables **
AD_Raw Var Word ' 10-bit result of A/D conversion
AD_Result Var Word ' Quantasized ADC result
Average Var Word ' Variable for building up the average result
Samples Var Byte ' Amount of samples taken
Volts Var Byte ' Holds the Volts part of the result (only for display purposes)
Millivolts Var Word ' Holds the Millivolts part of the result (only for display purposes)
' quanta level = (5/1024) * 256 == 1250
Quanta Con 1250
' ** Define the bits within the ADCON1 register **
ADFM Var ADCON1.7 ' ADC result fotmat select bit
PCFG3 Var ADCON1.3 ' ADC port configuration bit
PCFG2 Var ADCON1.2 ' ADC port configuration bit
PCFG1 Var ADCON1.1 ' ADC port configuration bit
PCFG0 Var ADCON1.0 ' ADC port configuration bit
PCFG0=0
PCFG1=1
PCFG2=0
PCFG3=0 ' Configure for AN0-AN4 as analogue input
ADFM=1 ' Right justified result in ADRESL and ADRESH
' ** THE MAIN PROGRAM STARTS HERE **
main:
Average=0 ' Clear the Average variable befor use
For Samples=0 to 9 ' We will take 10 samples of the ADC
ADCIN 1,AD_Raw ' Place the conversion of channel0 into AD_RAW
Average=Average+AD_Raw ' Build up the Average result
Next ' Close the loop
Average=Average/10 ' Calculate the average by dividing by the number of samples taken
AD_Result=(Average) */ Quanta ' Quantasize the result
Volts= AD_Result/100 ' Calculate the Volts part of the result
Millivolts=AD_Result//100 ' Calculate the Millivolts part of the result
Lcdout $fe, 2 '
Lcdout "Napon = ", DEC volts, ".",dec Millivolts, "V" '
pause 100
goto main