How to use Analogin for voltage measurements up to 255V or mod Analogin for 12
Hey everyone!
I am trying to use the Analogin command·to read·up to 255V. I have calculated that I need a 1 MOhm resistor to achieve this.·Unfortunately·it would seem that this is too high of a value to charge/discharge the capacitor when·I measure voltages from 0-15V (thats all I have available).
··················· 10K·············· 1M
'RA.1 Pin ----\/\/\/
+---\/\/\/
Voltage to measure
'································|
'RA.0 Pin
+
'······························· | 0.01uF
'································+--|(-- GND
In this configuration the reading is ~127,~128·when I am measuring·anything from 0-10V and it slowly rises·as I go above 10V.
I can't figure out how to get·calibrate this·ADC. I would greatly appreciate any help.
Oh, and is·there a way to write a VP·ADC for greater than 8·bit precision, say 12 bit?
Thanks
My code so far:
Uses a 3 digit 7 segment·array as output.
'
'DIRECTIVES
'
DEVICE········· SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ··········· 4_000_000
'
'I/O Pins
'
Seg7··········· PIN RC··· output········ ········ '7 segment ouptut
Digit1·········· PIN RB.7· output········ ········ 'pin for least significant digit
Digit2·········· PIN RB.6· output·
Digit3·········· PIN RB.5· output········· ······· 'Most significant digit
InPin ·········· PIN RA.0· INPUT CMOS··········'Analogin command
OutPin ········ PIN RA.1· OUTPUT··············· 'Analogin command
'
'Constants
'
turnoff··CON ·1································· 'High because digits are common cathode. If common anode flip values.
turnon· ·CON·0·································· 'If low then current will flow from segment to common.
'
'Variables
'
DispTime········ ·VAR·BYTE··················· 'speed of counter.
SensorReading··VAR BYTE
SenOnesVal····· VAR·BYTE
SenTensVal····· VAR·BYTE
SenHundVal····· VAR·BYTE
'
'MAIN PROGRAM
'
PROGRAM Start
Start:
·DO
·····ANALOGIN InPin, OutPin, SensorReading, 4
···· SenHundVal = SensorReading/100
···· SenTensVal = __REMAINDER/10
·····SenOnesVal = __REMAINDER
···· DispTime = 0
·· DO
···· Digit1· = turnon
···· READ Dig_Map + SenOnesVal, Seg7··
···· PAUSE 1
···· Digit1· = turnoff
···· Digit2· = turnon
···· READ Dig_Map + SenTensVal, Seg7
···· PAUSE 1
···· Digit2· = turnoff
···· Digit3· = turnon
···· READ Dig_Map + SenHundVal, Seg7
···· PAUSE 1
···· Digit3· = turnoff
··· ·INC DispTime
···LOOP UNTIL DispTime = 150
·LOOP
END
Dig_Map:
' bafg.cde
DATA %11100111 ' 0
DATA %10000100 ' 1
DATA %11010011 ' 2
DATA %11010110 ' 3
DATA %10110100 ' 4
DATA %01110110 ' 5
DATA %01110111 ' 6
DATA %11000100 ' 7
DATA %11110111 ' 8
DATA %11110110 ' 9
I am trying to use the Analogin command·to read·up to 255V. I have calculated that I need a 1 MOhm resistor to achieve this.·Unfortunately·it would seem that this is too high of a value to charge/discharge the capacitor when·I measure voltages from 0-15V (thats all I have available).
··················· 10K·············· 1M
'RA.1 Pin ----\/\/\/
+---\/\/\/
Voltage to measure
'································|
'RA.0 Pin
+
'······························· | 0.01uF
'································+--|(-- GND
In this configuration the reading is ~127,~128·when I am measuring·anything from 0-10V and it slowly rises·as I go above 10V.
I can't figure out how to get·calibrate this·ADC. I would greatly appreciate any help.
Oh, and is·there a way to write a VP·ADC for greater than 8·bit precision, say 12 bit?
Thanks
My code so far:
Uses a 3 digit 7 segment·array as output.
'
'DIRECTIVES
'
DEVICE········· SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ··········· 4_000_000
'
'I/O Pins
'
Seg7··········· PIN RC··· output········ ········ '7 segment ouptut
Digit1·········· PIN RB.7· output········ ········ 'pin for least significant digit
Digit2·········· PIN RB.6· output·
Digit3·········· PIN RB.5· output········· ······· 'Most significant digit
InPin ·········· PIN RA.0· INPUT CMOS··········'Analogin command
OutPin ········ PIN RA.1· OUTPUT··············· 'Analogin command
'
'Constants
'
turnoff··CON ·1································· 'High because digits are common cathode. If common anode flip values.
turnon· ·CON·0·································· 'If low then current will flow from segment to common.
'
'Variables
'
DispTime········ ·VAR·BYTE··················· 'speed of counter.
SensorReading··VAR BYTE
SenOnesVal····· VAR·BYTE
SenTensVal····· VAR·BYTE
SenHundVal····· VAR·BYTE
'
'MAIN PROGRAM
'
PROGRAM Start
Start:
·DO
·····ANALOGIN InPin, OutPin, SensorReading, 4
···· SenHundVal = SensorReading/100
···· SenTensVal = __REMAINDER/10
·····SenOnesVal = __REMAINDER
···· DispTime = 0
·· DO
···· Digit1· = turnon
···· READ Dig_Map + SenOnesVal, Seg7··
···· PAUSE 1
···· Digit1· = turnoff
···· Digit2· = turnon
···· READ Dig_Map + SenTensVal, Seg7
···· PAUSE 1
···· Digit2· = turnoff
···· Digit3· = turnon
···· READ Dig_Map + SenHundVal, Seg7
···· PAUSE 1
···· Digit3· = turnoff
··· ·INC DispTime
···LOOP UNTIL DispTime = 150
·LOOP
END
Dig_Map:
' bafg.cde
DATA %11100111 ' 0
DATA %10000100 ' 1
DATA %11010011 ' 2
DATA %11010110 ' 3
DATA %10110100 ' 4
DATA %01110110 ' 5
DATA %01110111 ' 6
DATA %11000100 ' 7
DATA %11110111 ' 8
DATA %11110110 ' 9