Searching \ for '[EE]: CHEAP voltage sensing??' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/power.htm?key=voltage
Search entire site for: 'CHEAP voltage sensing??'.

Exact match. Not showing close matches.
PICList Thread
'[EE]: CHEAP voltage sensing??'
2001\10\18@060722 by Roman Black

flavicon
face
Hi, I have a sensor that outputs about 10
voltage levels between 0v and 5v dc. Close
to evenly spaced but all different.
Because of impedances, the smallest resistor
I can attach to the sensor wire is about 100k.

I have only 5 PIC input/output pins available,
and no analog inputs unfortunately. The other
problem is minimum parts cost and board space,
maybe 1cm x 2cm. PIC is a 16C505. I can spare
a transistor but would prefer to do it with
discretes if possible. :o)

My best attempt yet was to use a few high
value resistors, as simple voltage dividers
with the 100k input resistor, switched by
4 of the PIC pins and another pin to test.
It's messy but maybe workable.

Any other suggestions??
-Roman

--
http://www.piclist.com hint: To leave the PICList
spam_OUTpiclist-unsubscribe-requestTakeThisOuTspammitvma.mit.edu


2001\10\18@070212 by mike

flavicon
face
On Thu, 18 Oct 2001 19:59:13 +1000, you wrote:

{Quote hidden}

How about this : 100K from sensor to pic pin A, with cap to ground.
10K from pic pin B to pin A.
Adjust PWM ratio on pin B until pin A switches.
To cope with full range, do it from both directions - i.e. start with
cap at 5V, PWM decreasing, look for high-low transition, then start at
0V, PWM increasing, look for low-to-high transition. You are effectively finding how much PWM drive is required to push the
output past the pin threshold against the current from the sensor -
this should bear some reasonable resmblence to the sensor voltage, and
I would think would be good enough to discriminate 10 levels.

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam@spam@mitvma.mit.edu


2001\10\18@070805 by Gerhard Fiedler

flavicon
face
With that resolution, you may try the RC method IRC outlined in a Microchip
app note (don't know which one). In the simplest version, you feed a port
through a RC low pass, discharge the C by setting the port low (as output)
and then measure the time until it becomes high (as input). This is as
CHEAP as it gets... :)

ge

At 19:59 10/18/2001 +1000, you wrote:
>Hi, I have a sensor that outputs about 10
>voltage levels between 0v and 5v dc. Close
>to evenly spaced but all different.
>Because of impedances, the smallest resistor
>I can attach to the sensor wire is about 100k.

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestspamKILLspammitvma.mit.edu


2001\10\18@071237 by Vasile Surducan

flavicon
face
use a repeater ( transistors if the mimimum level is allowing and the
thermal variation don't bother you,
or better an operational amplifier) to obtain a smaller output impedance,
then use Scott's method of measuring voltages using
digital pins. But I say also: change the pic to a 16F628 or
16F873/874/876/ or 16F74.

nothing but the best,
Vasile

On Thu, 18 Oct 2001, Roman Black wrote:

{Quote hidden}

--
http://www.piclist.com hint: To leave the PICList
EraseMEpiclist-unsubscribe-requestspam_OUTspamTakeThisOuTmitvma.mit.edu


2001\10\18@071244 by Spehro Pefhany

picon face
At 12:03 PM 10/18/01 +0100, you wrote:
>Adjust PWM ratio on pin B until pin A switches.
>To cope with full range, do it from both directions - i.e. start with
>cap at 5V, PWM decreasing, look for high-low transition, then start at
>0V, PWM increasing, look for low-to-high transition.
>You are effectively finding how much PWM drive is required to push the
>output past the pin threshold against the current from the sensor -
>this should bear some reasonable resmblence to the sensor voltage, and
>I would think would be good enough to discriminate 10 levels.

Maybe duplicate the circuit using a third pin, one more cap and two
more resistors (one to the test pin, one to the supply voltage), and
divide the results. This would eliminate the threshold from the
equation, assuming the inputs matched, and you could use 1% resistors
for the small cost difference. 5V is handily right in the middle of
your sensor range.

Best regards,

Spehro Pefhany --"it's the network..."            "The Journey is the reward"
speffspamspam_OUTinterlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
     /.-.\
    (( * ))
     \\ //     Please help if you can:
      \\\      dailynews.yahoo.com/fc/US/Emergency_Information/
     //\\\
    /// \\\
    \/   \/

--
http://www.piclist.com hint: To leave the PICList
@spam@piclist-unsubscribe-requestKILLspamspammitvma.mit.edu


2001\10\18@084628 by Roman Black

flavicon
face
Mike Harrison wrote:
{Quote hidden}

Absolutely brilliant Mike!! :o)

Much better than anything I have been
trying, and with only 2 PIC pins, a
resistor and a cap!

I looked at some systems of charging and
discharging a cap, like the "standard"
way of measuring a pot with a PIC etc.
But the double ended thing put me off,
as did the time constants with the 100k
resistor.

But this is brilliant! Just use a ramped
(sawtooth?) pwm from 0% to 100% duty, then
read the trip point each time. It should
even be able to measure voltages close to
0v or 5v, which is tricky with the old
system. Thanks Mike!

Also thanks to everyone else who offered
suggestions! The PIClist is great.
-Roman

--
http://www.piclist.com hint: To leave the PICList
KILLspampiclist-unsubscribe-requestKILLspamspammitvma.mit.edu


2001\10\18@095018 by Eoin Ross

flavicon
face
You could use an analog multiplexor - but does that go outside the bounds of your assignment?
examples are (16 channel)
MAX306
MPC506

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestTakeThisOuTspammitvma.mit.edu


2001\10\18@095038 by Scott Dattalo

face
flavicon
face
On Thu, 18 Oct 2001, Roman Black wrote:

> Mike Harrison wrote:
> >
> > >
> > >Any other suggestions??
>
> > How about this :
> > 100K from sensor to pic pin A, with cap to ground.
> > 10K from pic pin B to pin A.
> >
> > Adjust PWM ratio on pin B until pin A switches.
> > To cope with full range, do it from both directions - i.e. start with
> > cap at 5V, PWM decreasing, look for high-low transition, then start at
> > 0V, PWM increasing, look for low-to-high transition.
> > You are effectively finding how much PWM drive is required to push the
> > output past the pin threshold against the current from the sensor -
> > this should bear some reasonable resmblence to the sensor voltage, and
> > I would think would be good enough to discriminate 10 levels.

See the a2d.asm link here:
http://www.dattalo.com/technical/software/software.html

That exactly implements this.

Scott

--
http://www.piclist.com hint: To leave the PICList
spamBeGonepiclist-unsubscribe-requestspamBeGonespammitvma.mit.edu


2001\10\18@100132 by Thomas McGahee

flavicon
face
part 1 1323 bytes content-type:text/plain; (decoded 7bit)

Can you afford to use one single supply opamp?

Attached is a GIF showing how to wire it up.
This will work only with positive inputs, which in
your case is OK.

In software you configure one of the 4 control lines
as an output and send out a LOW. Others are configured
as inputs, so they float and contribute nothing to the
circuit at that time. The gain of each section should be
configured so that the matching desired input level
is amplified to a voltage level that PIC I/O line (5)
detects as a HIGH.

If you send a LOW out on only one line at a time you
will get 4 discrete trip levels, so you can distinguish
5 states:
 less than A
 greater than A and less than B
 greater than B and less than C
 greater than C and less than D
 greater than D

By carefully choosing the values of the four reference
resistors and connecting them to LOW in a binary count
sequence, you should be able to differentiate 16
different states.

The potentiometer allows the gain to be trimmed to account
for variations in threshold for different PICs, but
recall that GAIN=(Rfeedback+Rx)/Rx, so be aware of the
non-linear nature of the gain adjustment.

I have a better method that I will try to post later today...
right now I have an electronics class that I have to teach.

Fr. Thomas McGahee


part 2 10399 bytes content-type:image/gif; (decode)


part 3 105 bytes
--
http://www.piclist.com hint: To leave the PICList
TakeThisOuTpiclist-unsubscribe-requestEraseMEspamspam_OUTmitvma.mit.edu


2001\10\18@112119 by Mike Blakey

flavicon
face
If you can afford a comparator (I believe National do a very nice simple small one
LM111).

Use one output pin to output a PWM waveform varying from 1/255 to 255/255, fed to a
simple cap this will give you a 0 to 5v varying analogue voltage to one pin of the
comparator. your sensor goes to the other comparator input. the comparator output
goes to a PIC input pin, you now have a 0 to 5v AtoD. by checking the input after
changing the PWM frequency (plus a little settling time) you will now have a 8 bit
value. You may also need some digital filtering/averaging to reduce your component
count too. you only need 2 pins, one cap, one resistor and one LM111.

Hope that helps.



********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestspamTakeThisOuTmitvma.mit.edu


2001\10\18@174055 by Thomas McGahee

flavicon
face
part 1 1119 bytes content-type:text/plain; (decoded 7bit)

Refer to the attached GIF.

For any given Sensor voltage from 0 to +5 you want
a corresponding PWM from the PIC output that when
"mixed" via R1 and R2 will result in an input to
the PIC that just drives over the "HIGH" threshold.
Note that the value for R2 may have to be adjusted
somewhat from the value shown, depending on the
actual threshold value. R2 may have to be smaller than R1.

R3 and C1 are not critical in value, but must be chosen so
that the voltage appearing at their junction for a given
PWM frequency results in a voltage with little ripple.
The minimum C1 is a function of the PWM frequency and
R3.

In this case we are using the input high threshold of the
PIC as a sort of comparator trip point. While this is
not the best way to do things, it does have the advantage
of using very few parts.

The PWM is "swept", and the PWM value at the point where
the input switches from low to high can then be used
to determine the actual sensor voltage. This can be done
using a look up table or a mathematical formula.

Fr. Thomas McGahee




part 2 6249 bytes content-type:image/gif; (decode)


part 3 105 bytes
--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestEraseMEspam.....mitvma.mit.edu


2001\10\18@181311 by Scott Dattalo

face
flavicon
face
On Thu, 18 Oct 2001, Thomas McGahee wrote:

> Refer to the attached GIF.

Hmm, this version is even simpler and lets you measure voltages far above
the rails

                   +-----------> PIC (not used in 1-pin version)
                   |
Vin  o---/\/\/\---+-+-/\/\/\----< PIC
          R1     |    R2
                ===
                 |
                ---
                ///

To measure 20V for example, you'd want R2 to be about 1/20 the size of R1.
For example, 47k for R1 and 1Meg for R2. In the limits with the output at
5V and ground, the voltage at the cap is about 6V and 1V. Of course, the
6V will actually be clamped by the internal protection diode (and the 1meg
severly limits the current).

The algorithm is extremely simple:

high_count = 0;

for(i=0; i<2^N; i++) {
  if input is high
    make output low
    high_count++

  else
    make output high
}


After the loop, high_count will be the digitized voltage on an N-bit
scale. In my experiments, I could get 12 bits of dynamic range. However,
I never tested this over a full temperature range, etc. Also, my voltage
range was smaller than the rails. In other words, I did not make the input
resistor 1Meg and the other resistor 47k; mine were both 10k.

The only other issue is that you have to be careful about pre-charging the
capacitor before starting the algorithm. Also, the loop must be
isochronous. The poorly comment code that does this is here:

http://www.dattalo.com/technical/software/pic/a2d.asm


Alice has also experimented with this and determined that it doesn't work
ell when the voltage source is a potentiometer. It's interesting to see
why this is the case. It basically boils down to the pot having a high
impedance AND changing impedance. The resistance of a pot as viewed from
the wiper is Rh*Rl/Rt, i.e. the product of the high and low legs divided
by the total resistance. Weird things happen to this circuit when the
source impedance changes like this. Suffice it say that the PWM duty cycle
is not linearly proportional to the wiper position.

Scott

--
http://www.piclist.com hint: To leave the PICList
EraseMEpiclist-unsubscribe-requestspammitvma.mit.edu


2001\10\19@055129 by Roman Black

flavicon
face
Thank you Scott and Tom McGahee for your help,
but Mike Harrison posted this exact system
straight after I asked for help, and yes it is
perfect for what I need. :o)

One note, it is rather slow in response time,
and due to the on/off switching levels of a PIC
input the data needs to be interpreted, probably
with some lookup table values. BUT it is perfect
for my needs, a few simple voltage levels,
changing every couple of seconds.

Mike also suggested ramping the PWM first up,
then back down. This is important to trigger
the PIC input in the best fashion and also
it needs some allowance for Vih and Vil level
variation between PICs.
Thanks everyone! :o)
-Roman


Scott Dattalo wrote:
{Quote hidden}

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\10\19@072518 by Vasile Surducan

flavicon
face
On Thu, 18 Oct 2001, Mike Blakey wrote:

> If you can afford a comparator (I believe National do a very nice simple small one
> LM111).
>
> Use one output pin to output a PWM waveform varying from 1/255 to 255/255, fed to a
> simple cap this will give you a 0 to 5v varying analogue voltage to one pin of the
> comparator. your sensor goes to the other comparator input. the comparator output
> goes to a PIC input pin, you now have a 0 to 5v AtoD. by checking the input after
> changing the PWM frequency (plus a little settling time) you will now have a 8 bit
> value. You may also need some digital filtering/averaging to reduce your component
> count too. you only need 2 pins, one cap, one resistor and one LM111.
>
 Or if Roman likes more 16F627, he have everything you say inside at the
same price like his pic. But you see, software guys are loving complicated
tasks...[big grin]

 Vasile

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\10\19@081718 by Thomas McGahee

flavicon
face
You mentioned Alice's problem with the changing potentiometer
impedance as the wiper is moved over it's range. You can
easily eliminate this problem using a single NPN transistor
as a voltage follower. Connect the collector to +5 or higher
voltage. Connect pot wiper directly to the base. Connect
emitter resistor between emitter and ground. Something
between 1k and 10k should be adequate. The new output is taken
from the top of the emitter resistor. Eout=Ein-.6  so if you
want the output to go from 0 to some positive voltage, then
add a diode to the bottom of the potentiometer (cathode to
ground) to compensate for the NPN's diode drop. A good value for
the potentiometer is 10k.

While most PIC list members already know how to do this,
I offer it anyhow for the sake of those who don't.

Disgusting ascii art:

O +5
|        O +5 or more
\        |
/ 10k    |   collector
\ pot   |/
/<------|    any NPN
\       |\
/         V  emitter
|         |
|         *-----> Eout
|         |
V diode   \
-         /  1k
|         \
|         /
GND      GND


Fr. Thomas McGahee

{Original Message removed}

2001\10\19@113329 by Scott Dattalo

face
flavicon
face
On Fri, 19 Oct 2001, Thomas McGahee wrote:

> You mentioned Alice's problem with the changing potentiometer
> impedance as the wiper is moved over it's range. You can
> easily eliminate this problem using a single NPN transistor
> as a voltage follower. Connect the collector to +5 or higher

Now that's a good, simple idea! A simple $0.05 voltage buffer turns a
digital I/O into an analog I/O. I like it.

Scott

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\10\20@093226 by Roman Black

flavicon
face
Scott Dattalo wrote:
>
> On Fri, 19 Oct 2001, Thomas McGahee wrote:
>
> > You mentioned Alice's problem with the changing potentiometer
> > impedance as the wiper is moved over it's range. You can
> > easily eliminate this problem using a single NPN transistor
> > as a voltage follower. Connect the collector to +5 or higher
>
> Now that's a good, simple idea! A simple $0.05 voltage buffer turns a
> digital I/O into an analog I/O. I like it.


But remember this requires the additional 0.7v
drop between the input voltage and the sensed
voltage. :o)
-Roman

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\10\20@121322 by Scott Dattalo

face
flavicon
face
On Sat, 20 Oct 2001, Roman Black wrote:

> Scott Dattalo wrote:
> >
> > On Fri, 19 Oct 2001, Thomas McGahee wrote:
> >
> > > You mentioned Alice's problem with the changing potentiometer
> > > impedance as the wiper is moved over it's range. You can
> > > easily eliminate this problem using a single NPN transistor
> > > as a voltage follower. Connect the collector to +5 or higher
> >
> > Now that's a good, simple idea! A simple $0.05 voltage buffer turns a
> > digital I/O into an analog I/O. I like it.
>
>
> But remember this requires the additional 0.7v
> drop between the input voltage and the sensed
> voltage. :o)

True. Also, it prohibits you from sensing voltage below .7 + Vin
threshold. In other words, the eternal voltage not only has to drive the
transistor, but it also has to drive the base a diode drop above the input
threshold of the PIC I/O line. Both of these limit it's usefulness for
measuring potentiometers that are referenced to the same power supply as
the pic.

Perhaps a better variation is something like
                      +-----------------------> PIC
                      |
Vref  o---/\/\/\--/\/\/\/\/\/\/\-----/\/\/\----< PIC
            R1        |  Rpot        R2
                 C1  ===
                      |
                     ---
                     ///

But, I haven't given it too much thought. Intuitively I'd say that setting
Vref equal to the PIC input voltage threshold would be the optimum
setting. This could be achieved by tying the Vref line to another PIC I/O
and pulsing it with a ~1/5 duty cycle. Or perhaps Both sides of the pot
could be driven with a differential signal. In other words, if you drive
one end high, drive the other low. A quick scribble in the margin shows
that the differential technique has a transfer function with the form:

 K = A*DC + B*x

A,B, and K are constants that depend on the resistors and the PIC input
threshold. DC is the PWM duty cycle. "x" is the wiper position and varies
from 0 to 1 as the wiper moves from one end to the other. This is the
desired form.

Scott

PS. If you only need 6 to 8 bits of resolution, then only two I/O lines
would be needed.

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\10\20@214819 by Russell McMahon

picon face
If you don't mind losing a little "headroom" on the pot and want the
follower to more accurately track the pot voltage then connect a resistor
from +supply to a diode anode and diode cathode to pot wiper. Follower base
goes to resistor/diode-anode  junction. The resistor needs to be
significantly higher than the pt value. The diode anode is 1 diode drop
above the pot wiper voltage compensating for the Vbe drop in the follower.
If available an opamp follower has much better performance.



     Russell McMahon
_____________________________

{Quote hidden}

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\10\21@162433 by alice campbell

flavicon
face
Hello Fr Tom,

Thank you for the solution to my conundrum, and just in time for Halloween.  The offending project has been shelved a long time, you've put it back on the road again.  Can I use an LDR (cad-sulfide photoresitor)instead of a pot and run it to the base of the NPN above the diode?


Alice
envisioning eerie sounds already....

{Quote hidden}

--

_______________________________________________
Sign-up for your own FREE Personalized E-mail at Mail.com
http://www.mail.com/?sr=signup


Have you downloaded the latest calling software from Net2Phone? Click here to get it now!

http://www.net2phone.com/cgi-bin/link.cgi?157



--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\10\21@170644 by Thomas McGahee

flavicon
face
Alice,
Yes, the circuit below should work just fine. You need to
replace the potentiometer with an ldr and a resistor. As shown,
the value of Eout will RISE as it gets darker. The value
of Eout will DROP as it gets brighter. If you want to
reverse this, then exchange the positions of the resistor
(res) and the ldr.

The transistor needs to have a reasonable gain.

More disgusting ascii art:

O +5
|         O +5 or more
\         |
/ res     |   collector
\       |/
*-------|    any NPN
\       |\
/ ldr     V  emitter
|         |
|         *-----> BUFFERED Eout
|         |
V diode   \
-         /  1k
|         \
|         /
GND      GND

The value of (res) needs to be chosen to be about equal
to the value of ldr at "normal" ambient light. Eout
will vary between 0 and 4.4 volts, with "normal" ambient
light producing 2.2 volts out.

I hope that this helps you with your Halloween project.
Tell Winnie I said "hello", and give Sir Speedy a smile
for me. Pet snails need all the tender loving care they can
get.

Fr. Thomas McGahee


{Original Message removed}

More... (looser matching)
- Last day of these posts
- In 2001 , 2002 only
- Today
- New search...