Maker Pro
Maker Pro

math problem

B

Beowulf

Jan 1, 1970
0
I need help with a math puzzler related to an electronics project. I built
the BASIC Stamp microcontroller and have a project (photoresistor) that
measures light and reports the data values. The problem is in almost total
darkness the values range around 30000 to 40000 and with room light the
values drop to around 200. I want to use the gizmo to run in a dark room
and then monitor for light changes, so I would like high values to
indicate light not dark. So somehow I need to reverse the way the values
are reported. The problem is compounded by the simply math available to me
by way of the PBASIC command language of the Stamp: only +, -, /, *
available, no fancy operators like square root or anything. Ideas?
 
J

John Popelish

Jan 1, 1970
0
Beowulf said:
I need help with a math puzzler related to an electronics project. I built
the BASIC Stamp microcontroller and have a project (photoresistor) that
measures light and reports the data values. The problem is in almost total
darkness the values range around 30000 to 40000 and with room light the
values drop to around 200. I want to use the gizmo to run in a dark room
and then monitor for light changes, so I would like high values to
indicate light not dark. So somehow I need to reverse the way the values
are reported. The problem is compounded by the simply math available to me
by way of the PBASIC command language of the Stamp: only +, -, /, *
available, no fancy operators like square root or anything. Ideas?

Can you give us some idea of how the photo resistor is connected to
the Stamp? It may be easier to change the connection than to alter
the math. But if the math is floating point, then just divide a
constant by the measured value or subtract the measured value from a
constant.
 
B

Beowulf

Jan 1, 1970
0
Can you give us some idea of how the photoresistor is connected to
the Stamp? ...

P2 from Stamp sends current to a 220ohm resistor, that then sends
(splits) the current to a photoresistor and a 0.01uF capacitator, both of
which then go to the Vss (ground). I know little about the photoresistor
specs other than it is from Parallax and is part no. 350-00009


P2---------/\/\/---------*----------------
220 Ohm | |
| |
PHOTOR. _____ 0.01uF
| ---
| |
*-----------------
|
|
____
---- Vss
--







I also substituted a thermistor for the photoresistor to get temperature
data and that works great too.
 
J

John Popelish

Jan 1, 1970
0
Beowulf said:
On Sun, 08 Feb 2004 19:43:45 -0500, John Popelish wrote:
..

P2 from Stamp sends current to a 220ohm resistor, that then sends
(splits) the current to a photoresistor and a 0.01uF capacitator, both of
which then go to the Vss (ground). I know little about the photoresistor
specs other than it is from Parallax and is part no. 350-00009

P2---------/\/\/---------*----------------
220 Ohm | |
| |
PHOTOR. _____ 0.01uF
| ---
| |
*-----------------
|
|
____
---- Vss
--

I suspect that the program charges the cap up to about as positive as
it will go, then changes P2 to an input and times how long it takes
the input to read as a logic low, based on the time constant of the
photo resistor with the capacitor. Lower light level raises the
resistance of the photo resistor, making it take longer (more counts
of time) to make the transition. I think dividing something like
100,000 by the count would be a good way to roughly invert the sense
of the light measurement. If that math includes the fractional part
of that division, it will have a lot more resolution. If not, you may
have to divide a bigger number like 500,000 to get enough dim light
resolution.
 
C

CFoley1064

Jan 1, 1970
0
Subject: Re: math problem
From: Beowulf [email protected]
Date: 2/8/2004 6:56 PM Central Standard Time
Message-id: <[email protected]>
P2 from Stamp sends current to a 220ohm resistor, that then sends
(splits) the current to a photoresistor and a 0.01uF capacitator, both of
which then go to the Vss (ground). I know little about the photoresistor
specs other than it is from Parallax and is part no. 350-00009


P2---------/\/\/---------*----------------
220 Ohm | |
| |
PHOTOR. _____ 0.01uF
| ---
| |
*-----------------
|
|
____
---- Vss
-

I also substituted a thermistor for the photoresistor to get temperature
data and that works great too.

Hi again Beowulf. How's the ectoplasm treating you?

First, if you're using the Basic Stamp 2, you're going to want to use the
RCTIME statement, which means you'll want to have a layout like this (view in
fixed font or use M$ Notepad):


VCC
+
|
|
---
--- 0.1uF
220 ohm |
BS2 ___ |
Pin o-|___|----o
|
|
|
.-.
| | Photoresistor
| |
'-'
|
|
===
GND

Since the BS2 has naught but integer math, you have to be creative about
invering -- 1/X won't cut it. To start out with, figure out what the highest
tiime reading you'll get is going to be (total darkness). Add a few thousand,
then just subtract your reading from that number. That will give you a very
high number for light, and a very low number for dark. It's a hack, totally
non-linear, but it's quick&dirty, and it might get the job done.

If you want to explore the intricacies of the arcane art of ASCII scematics,
try Andy's ASCII circuit v.1.24 -- program available at:

http://www.tech-chat.de/

It's "state of the art" -- many people on these newsgroups use it. ;-)

Good luck
Chris
 
O

Olaf

Jan 1, 1970
0
The problem is in almost total
darkness the values range around 30000 to 40000 and with room light the
values drop to around 200. I want to use the gizmo to run in a dark
room and then monitor for light changes, so I would like high values to
indicate light not dark. So somehow I need to reverse the way the values
are reported. The problem is compounded by the simply math available to
me by way of the PBASIC command language of the Stamp: only +, -, /, *
available, no fancy operators like square root or anything. Ideas?

you gave the solution yourself: 'reverse' and '-'! Use -x instead of x. A
little tuning will give 'nice' values: when x is the amount of light, then
let y=40000-x. Now a dark room gives y=0 up to y=10000 and a lit room
gives y=39800. Or, if you use y=(40000-x)/1000 you end up with nice values
like y=0 up to y=10 for dark rooms and y=40 (more or less) for a lit room.

bye, Olaf
 
Top