trying to read voltage and getting no where :(
I am attempting to read 5v DC and less and store 1 through 10 in a variable based on the input. 0 volts would be 1, and 5 volts would be 10. I have tried using the ANALOGIN and the RCTIME and am getting nothing [noparse]:([/noparse] I have tried different SX's and it still does not work. I figure ANALOGIN would be better since the examples say "Voltage to measure". I have everything hooked exactly like the example and I am not getting the slightest reading from it. I have tried using the DEBUG feature and watching the output. It is always 0. All the wires are connected properly with no loose connections. Can someone help me figure why this is not working? For right now, I am using the SX-Tech with the SX28 to do the testing.

Comments
!!
Let's say the results VAR is volts.
volts = volts-203
volts = volts/8
That'll give a result of volts as volts.
If you want 1 to 10 then divide by 4 instead of 8
·······································50K
····························+ 5V ----\/\/\/
GND
······································· ▲
······································· |
·············· 10K··········· 10K······ |
·RA.1 Pin
\/\/\/----+---\/\/\/
+
························ |
·RA.0 Pin
+--|(--- GND
·························· 0.01uF
···························"103"
ANALOGIN InPin, OutPin, a, 1 if a < lowa THEN lowa = a endif if a > higha THEN higha = a endif a = higha - a of = higha - lowa big = a * 100 big = big / of a = big_LSB watch big watch lowaif there is an easier way to do this, please let me know [noparse]:)[/noparse]
My next step is to make the 0 to 100 = 255 to 0
the_byte = 255 * the_percentage
ANALOGIN InPin, OutPin, a, 1 if a < lowa THEN lowa = a endif if a > higha THEN higha = a endif a = higha - a of = higha - lowa big = a * 100 big = big / of a = big_LSB / 100 a = __REMAINDER digit = 255 ** a watch digit watch lowa watch higha watch bigthe variable "digit" is always returning 0. I tried switching to */ and it almost matched the variable "big". I am having a hard time understanding this [noparse]:([/noparse] I really appreciate the help so far! I am learning that is for sure :P What do you think I need to change?
Getting used to */ and ** takes a little doing; once you understand them, though, they're very useful with fixed fractional values.
Tip: Use */ for values greater than 0.99 and ** for values less than 1.0. Note that both require a word variable, so result in the code above is a word.
*EDIT* : One more thing.... there are no displays hooked up to ensure there is no extra power consumption.
Here is my code :
DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX FREQ 4_000_000 ID "Temp" InPin PIN RC.0 INPUT CMOS OutPin PIN RC.1 OUTPUT DigCtrl PIN RA Segs PIN RB MaxDigit CON 4 a VAR Byte lowa Var Byte higha VAR Byte of VAR Byte digPntr VAR Byte display VAR Byte(MaxDigit) digit VAR WORD tmpB1 VAR Byte tmpB2 VAR Byte tmpB3 VAR Byte tmpB4 VAR Byte pressure VAR Byte big VAR Word INTERRUPT 200 ISR_Start: Next_Digit: INC digPntr ' point to next digit IF digPntr = MaxDigit THEN ' check pointer digPntr = 0 ' wrap if needed ENDIF Update_Segs: Segs = %00000000 ' blank segments READ DigMap + digPntr, DigCtrl ' update digit control Segs = display(digPntr) ' output new segments ISR_Exit: RETURNINT PROGRAM Start Start: DigCtrl = %1111 ' disable all digits TRIS_A = %0000 ' make dig pins outputs TRIS_B = %00000000 TRIS_C = %00000000 Segs = %00000000 lowa = 240 higha = 240 Main: ANALOGIN InPin, OutPin, a, 1 if a < lowa THEN lowa = a - 1 endif if a > higha THEN higha = a + 1 endif a = higha - a of = higha - lowa big = a * 100 big = big / of a = big_LSB digit = 100 - a digit = digit */ $28C watch digit watch lowa watch higha watch big pressure = digit_LSB PWM RC.2, pressure, 200 tmpB2 = a / 100 ' get hundreds digit tmpB1 = __REMAINDER ' save 10's and 1's READ SegMap + tmpB2, display(2) ' get segment map 100's tmpB2 = tmpB1 / 10 ' get 10's digit tmpB1 = __REMAINDER ' save 1's READ SegMap + tmpB2, display(1) ' get segment map for 10's READ SegMap + tmpB1, display(0) ' get segment map for 1's GOTO Main SegMap: ' segments maps DATA %00111111 ' 0 DATA %00000110 ' 1 DATA %01011011 ' 2 DATA %01001111 ' 3 DATA %01100110 ' 4 DATA %01101101 ' 5 DATA %01111101 ' 6 DATA %00000111 ' 7 DATA %01111111 ' 8 DATA %01100111 ' 9 DigMap: ' digit select map DATA %11111110 DATA %11111101 DATA %11111011 DATA %11110111I appreciate the help!
Post Edited (eagletalontim) : 1/4/2009 6:14:33 AM GMT
ANALOG in works so it must be something on your end. Don't assume your connections are correct if you're getting bad values; rebuild the circuit. After you've done that verify it with known inputs. I always do this with ADC circuits, testing with 0, 2.5, and 5 volts.
With the analogin, I have tried on 2 different boards and both boards gave jumpy results. It does not jump much, but 2 volts on the output is a big matter on what I need to get accomplished. I also set up the same circuitry on the SX-Tech and ran the debug to see if it would give steady results. I did not. I got frustrated with it last night and just went to bed to sleep on it. I reassembled everything this morning and it still does the same thing. I can step back 5 feet away and watch the meter still bounce even after letting it sit for 30 minutes or more [noparse]:([/noparse]
$20 = 32
That·is (2 X 16) + (0 X 1) = 32 + 0
$33 = 51;
(3 X 16) + (3 X 1) = 48 + 3 = 51
$4C = 76
(4 X 16) + (12 X 1) = 64 + 12 = 76
Post Edit --
$324 is equal to 804
(3 X 256) + (2 X 16) + (4 X 1) = 768 + 32 + 4
804 / 256·≈ 3.1406 ≈ pi
Post Edited (PJ Allen) : 1/4/2009 6:22:59 PM GMT
The software A/D converter is very picky about precise timing....... it relies on balancing aggragate high durations and low durations of a simple R/C Digital to Analog converter (in this case a specialized PWM). Any changes in interrupt durations at runtime will adversely affect the results.
I see in your code you are using WATCH statements. The A/D conversion will not work if those are active as the time interruption to display them corrupts the strict timing requirements.
I use my own assembler version of A/D all the time, and it works well. With some tweaking you can get it stable to 12 bits or more.... that is 1 part in 4096. And with some filtering/averaging approach 16 bits!
If as you say, everything is correct, and the source is indeed stable, then the only thing left is timing inconsistencies.
Cheers,
Peter (pjv)
Is ANALOGIN any good with internal RC, or should that be done only with XTAL/OSC/Resonator ?
Yeah, converting between Hex and Decimal always makes my head go *Sproing!*. Just use the calculator on your laptop/computer. Put it in scientific mode. It should default to decimal. Enter the number you want to convert and hit the Hex button presto bango, there you go. Or, you could do it like PJ Allen did as a good excercise, both ways work. There are numerous examples of */ and ** in the PBASIC help file as well, I think it even shows using a hex value as a mulitiplier factor.
I've never understood how hex was easier to read than decimal, but I imagine if your work on Micro's alot like Johnnymac, you would eventually prefer to see a hex value (i.e. the LSB and MSB). Keep at it!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Shawn Lowe
When all else fails.....procrastinate!
Only when using the */ operator. The SX/B help file describes how it works.