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"
if 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
the 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 :
I 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.