In SX Microcontrollers, SX/B Compiler and SX-Key Tool, Sawmiller wrote: 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.. [u][b]i'm really not to sure what bean means by impedance of the voltage to the resistor :confused: [/b][/u] 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 ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=200009 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2007 (http://www.dotNetBB.com)