analogin puzzled
how much range should analogin be good over ?
i'm creating a voltmeter, using a sx28 and a HC4led
and have a program, but i keep having to change the multipilyer values to get the number on the HC4led right with my regular voltmeter.
im looking a a 0 -35 volt range but at 11 volts i need 164 as a multiplier, and at 35 volts i need 138..
i'm really not to sure what bean means by impedance of the voltage to the resistor![confused.gif](http://forums.parallax.com/images/smilies/confused.gif)
currently using a voltage divider 10k on one side then 60 k on the other then that goes straight to the sensor.
see comments for further stuff
if anyone can explain why this is happening, please enlighten me
'
' Device Settings
'
DEVICE SX28,OSC4MHZ,TURBO,STACKX,OPTIONX
FREQ 4_000_000
'
' IO Pins
'
Clk······ VAR RA.0
Dat······ VAR RA.1
InPin ··PIN RC.0 INPUT CMOS
OutPin ··PIN RC.1 OUTPUT
'
' Constants
'
MINUS···· ·CON 11 ' Used for DisplayValue parameters
BLANK···· ·CON 10 ' Used for DisplayValue parameters
volt_scale ·CON 138····· 'used to give a range between 0- 35 volts max expected is 32
'
' Variables
'
value···· VAR Byte (4)
segments· VAR Byte (4)
cnt······ VAR Byte
temp1···· VAR Byte
counter·· VAR Byte
Volt····· VAR byte
Voltage··VAR·Word
' =========================================================================
· PROGRAM Start
' =========================================================================
'
' Subroutine Declarations
'
DisplayValue··· SUB 4
UpdateValue···· SUB
DisplaySegments SUB 4
LEDOut········· SUB 1
putz······SUB
fancy_start···SUB
'
' Program Code
'
Start:
· HIGH Clk
Main:
'fancy_start
again:
value(3) = 0
value(2) = 0
value(1) = 0
value(0) = 0
ANALOGIN InPin, OutPin, Volt,5
Voltage = Volt
if Voltage = 0 goto display
Voltage = Voltage * volt_scale ··' mutiply to get right numbers
Voltage = Voltage / 10······' knock off last· digit· ( easier to multiply by 164, than 16.4 )
if voltage = 0 goto display
Voltage = Voltage / 10
·················' hundredths
value(3) = __REMAINDER
if voltage = 0 goto display
Voltage = Voltage / 10
················· ··' tenth's
value(2) = __REMAINDER
if voltage = 0 goto display
Voltage = Voltage / 10
··················· ·' ones
value(1) = __REMAINDER
if voltage = 0 goto display
Voltage = Voltage / 10
··················· ·' tens
value(0) = __REMAINDER
display:
DisplayValue value(0),value(1),value(2), value(3)
pause 100
· GOTO again
'
' Subroutine Code
'
Fancy_start:
for counter = 1 to 10
·
···FOR cnt = 0 to 3
··· ·segments(cnt) = 4
···
····gosub putz
···next
··segments(3) = 8
··gosub putz
··segments(3) = 16
··gosub putz
··FOR cnt = 3 to 0 step -1
··· ·segments(cnt) = 32
··· ·gosub putz
··next
··segments(0) = 64
··gosub putz
··segments(0) = 2
··gosub putz
·next
return
DisplayValue:
· PUT value,__PARAM1,__PARAM2,__PARAM3,__PARAM4
UpdateValue:
· FOR cnt = 0 to 3
··· temp1 = value(cnt)
··· READ DigitSegs+temp1,segments(cnt)
· NEXT
· GOTO DisplayArray
DisplaySegments:
· PUT segments,__PARAM1,__PARAM2,__PARAM3,__PARAM4
DisplayArray:
· HIGH Clk
· LEDOut segments(3)
· LEDOut segments(2)
· LEDOut segments(1)
· LEDOut segments(0)
· RETURN·
LEDOut:
· temp1 = __PARAM1
· SHIFTOUT Dat, Clk, MSBFIRST, temp1
· RETURN
putz:
· HIGH Clk
· LEDOut segments(3)
· LEDOut segments(2)
· LEDOut segments(1)
· LEDOut segments(0)
··· pause 100
·· segments(3) = 0
·· segments(2) = 0
·· segments(1) = 0
·· segments(0) = 0
return
'
' Data
'
DigitSegs:
· DATA 126,24,109,61,27,55,115,28,127,31,0,1
·
i'm creating a voltmeter, using a sx28 and a HC4led
and have a program, but i keep having to change the multipilyer values to get the number on the HC4led right with my regular voltmeter.
im looking a a 0 -35 volt range but at 11 volts i need 164 as a multiplier, and at 35 volts i need 138..
i'm really not to sure what bean means by impedance of the voltage to the resistor
![confused.gif](http://forums.parallax.com/images/smilies/confused.gif)
currently using a voltage divider 10k on one side then 60 k on the other then that goes straight to the sensor.
see comments for further stuff
if anyone can explain why this is happening, please enlighten me
'
' Device Settings
'
DEVICE SX28,OSC4MHZ,TURBO,STACKX,OPTIONX
FREQ 4_000_000
'
' IO Pins
'
Clk······ VAR RA.0
Dat······ VAR RA.1
InPin ··PIN RC.0 INPUT CMOS
OutPin ··PIN RC.1 OUTPUT
'
' Constants
'
MINUS···· ·CON 11 ' Used for DisplayValue parameters
BLANK···· ·CON 10 ' Used for DisplayValue parameters
volt_scale ·CON 138····· 'used to give a range between 0- 35 volts max expected is 32
'
' Variables
'
value···· VAR Byte (4)
segments· VAR Byte (4)
cnt······ VAR Byte
temp1···· VAR Byte
counter·· VAR Byte
Volt····· VAR byte
Voltage··VAR·Word
' =========================================================================
· PROGRAM Start
' =========================================================================
'
' Subroutine Declarations
'
DisplayValue··· SUB 4
UpdateValue···· SUB
DisplaySegments SUB 4
LEDOut········· SUB 1
putz······SUB
fancy_start···SUB
'
' Program Code
'
Start:
· HIGH Clk
Main:
'fancy_start
again:
value(3) = 0
value(2) = 0
value(1) = 0
value(0) = 0
ANALOGIN InPin, OutPin, Volt,5
Voltage = Volt
if Voltage = 0 goto display
Voltage = Voltage * volt_scale ··' mutiply to get right numbers
Voltage = Voltage / 10······' knock off last· digit· ( easier to multiply by 164, than 16.4 )
if voltage = 0 goto display
Voltage = Voltage / 10
·················' hundredths
value(3) = __REMAINDER
if voltage = 0 goto display
Voltage = Voltage / 10
················· ··' tenth's
value(2) = __REMAINDER
if voltage = 0 goto display
Voltage = Voltage / 10
··················· ·' ones
value(1) = __REMAINDER
if voltage = 0 goto display
Voltage = Voltage / 10
··················· ·' tens
value(0) = __REMAINDER
display:
DisplayValue value(0),value(1),value(2), value(3)
pause 100
· GOTO again
'
' Subroutine Code
'
Fancy_start:
for counter = 1 to 10
·
···FOR cnt = 0 to 3
··· ·segments(cnt) = 4
···
····gosub putz
···next
··segments(3) = 8
··gosub putz
··segments(3) = 16
··gosub putz
··FOR cnt = 3 to 0 step -1
··· ·segments(cnt) = 32
··· ·gosub putz
··next
··segments(0) = 64
··gosub putz
··segments(0) = 2
··gosub putz
·next
return
DisplayValue:
· PUT value,__PARAM1,__PARAM2,__PARAM3,__PARAM4
UpdateValue:
· FOR cnt = 0 to 3
··· temp1 = value(cnt)
··· READ DigitSegs+temp1,segments(cnt)
· NEXT
· GOTO DisplayArray
DisplaySegments:
· PUT segments,__PARAM1,__PARAM2,__PARAM3,__PARAM4
DisplayArray:
· HIGH Clk
· LEDOut segments(3)
· LEDOut segments(2)
· LEDOut segments(1)
· LEDOut segments(0)
· RETURN·
LEDOut:
· temp1 = __PARAM1
· SHIFTOUT Dat, Clk, MSBFIRST, temp1
· RETURN
putz:
· HIGH Clk
· LEDOut segments(3)
· LEDOut segments(2)
· LEDOut segments(1)
· LEDOut segments(0)
··· pause 100
·· segments(3) = 0
·· segments(2) = 0
·· segments(1) = 0
·· segments(0) = 0
return
'
' Data
'
DigitSegs:
· DATA 126,24,109,61,27,55,115,28,127,31,0,1
·
Comments
You will need to use an op-amp to buffer the voltage (you may be able to use the SX comparitor, I never tried it).
Basically you want to run your 35volts through a resistor divided to get it down to 5 volts. Then run that 5 volts through an op-amp to buffer the voltage level. Then run the output of the op-amp into the analogin circuit using the same value resistors on each side.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
“The United States is a nation of laws -· poorly written and randomly enforced.” - Frank Zappa
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.hittconsulting.com
·
thanks,
dan
the only thing i dont like is this cludge of a if then statement, would be nice to have it like this
if voltage >= 125 then volt_scale· = 145
instead of
if Voltage >= 125 then goto scale············ 'software cludge for high end
goto jump
scale:
volt_scale = 147
jump:
but it wouldnt work for me in the shorter version.
i think i could get my scale factor closer if i had larger power resitors than the 1/4 watts , then i could lower my divider farther.
anyways happy 4th , and heres the voltmeter as she stands now ( circut is in the comments )· wish we had the props schematicability for comments
dan
Post Edited (Sawmiller) : 7/4/2007 2:09:27 PM GMT
- Sparks