PDA

View Full Version : How do I select the proper photo resistor for using the pot command



jessey
- 1st March 2006, 02:27
Hello,

I'm trying to find a photo resistor that would be suitable for detecting light levels using the POT command with PBP. The manual says I should be using one in the range of 5K to 50K. Would the 5K to 50K be the maximum resistance that my resistance meter would show me while checking the photo resistor under maximum or minimum light, when trying to decide on which one to use? I have a few here but can't find a suitable one especially when I don't understand what the manual is trying to tell me. If I was to go to my local electronics store and ask for a suitable photo resistor then what would I specifically ask for? Does anyone have a part number for one that would be suitable, I want to be able to differentiate light levels between day time and night time and the varying degrees of light in-between with some sort of accuracy.

Also, I don't understand the manual when it says:
Set the device under measure to maximum resistance and read it with Scale set to 255. Under these conditions, Var will produce an appropriate value for Scale.

So according to the above statement I would write:

POT PORTB.4,255,Light_Level

Then I set the device under measure to maximum resistance and this is the confusing part as to how to simulate what the maximum resistance is. Ok say I figured out what the maximum resistance is and if the number produced is 16 on my Lcd then I would write:

POT PORTB.4,16,Light_Level

To set the device to maximum resistance, would that be the maximum dark or light resistance? Would I shine a light on the resistor or cover it up with black tape?

This is very frustrating and confusing for me, any help would be appreciated.

Thanks
jessey

sougata
- 1st March 2006, 06:36
Hi,

As the manual states :



POT Pin,Scale,Var
Reads a potentiometer (or some other resistive device) on Pin. Pin
may be a constant, 0 - 15, or a variable that contains a number 0 - 15
(e.g. B0) or a pin name (e.g. PORTA.0).
The resistance is measured by timing the discharge of a capacitor
through the resistor (typically 5K to 50K). Scale is used to adjust for
varying RC constants. For larger RC constants, Scale should be set
low (a minimum value of one). For smaller RC constants, Scale should
be set to its maximum value (255). If Scale is set correctly, Var should
be zero near minimum resistance and 255 near maximum resistance.
Unfortunately, Scale must be determined experimentally. To do so, set
the device under measure to maximum resistance and read it with
Scale set to 127. Adjust Scale until the Pot command returns 254. If
255, decrease the scale. If 253 or lower, increase the scale. (Note:
This is similar to the process performed by the Alt-P option of the BS1
environment).
Use the following code to automate the process. Make sure that you set
the pot to maximum resistance.
B0 Var Byte
scale Var Byte
For scale = 1 To 255
POT 0,scale,B0
If (B0 > 253) Then calibrated
Next scale
Serout 2,0,["Increase R or C.",10,13]
Stop
calibrated:
Serout 2,0,["Scale= ",#scale,10,13]


PBP allows you to use a POT within a range of 5K and 50K. This versatility requires that you adjust the scale according to your pot. Select a LDR that has a maximum (dark) resistance between 5K-50K. Now use the above code with maximum light falling on it. You can replace the serout with LCDOUT. Once you know the right scale value you can hardcode it in your code.
Hope this helps.

Regards

Sougata

jessey
- 1st March 2006, 09:16
Hello Sougata,

Thanks for your reply. How do I set up the code you gave me to work using the lcdout command? I managed to find an LDR that has dark resistance of 5K to 5.5K and it shows approximately 30 ohms with a very bright light shinning on it, that's an acceptable range?

When I run the code you sent as modified below, I get weird charters on the Lcd for the 10,13 and it never makes it to the calibrated subroutine. I tried it initially using a 0.1 microfarad then tried a 0.01, 0.022, 0.047, 0.47 and even a 1 microfarad but no go, what other values would you suggest using? Or could it be the code is locking up due to 10,13 screwing it up? I don't understand what the 10,13 is all about, can you explain what it's for? I'm using a 2 X 16 character Lcd, can you tell me what I need to add to get it working with the Lcdout commands?

For scale = 1 To 255
POT PORTD.0,scale,B0
If (B0 > 253) Then calibrated
Next scale
LCDOut $fe, 1,"Inc R or C.",10,13
Stop
calibrated:
LCDOut $fe, $c0,"Scale= ",DEC scale,10,13

Thanks
jessey

jessey
- 1st March 2006, 10:29
Hello Again Sougata,

I got it to work with the code below. Using a 10 microfarad capacitor I get a value for scale of 204 and the B0 variable shows 255. I haven't tried in my program yet and I'm not familiar with the usual values used for the POT command but 10 microfarads seems a little high and I would think it would really slow down the read. Maybe if I get a different LDR closer to the 50K maximum value I might be able to get away with using a smaller value capacitor? Anyways I'll try it in my program to see how it works, in the meantime what do you think about having to use a 10 microfarad cap for the LDR?

For scale = 1 To 255
POT PORTD.0,scale,B0
If (B0 > 253) Then calibrated
Next scale
LCDOut $fe, 1,"S = ",DEC scale," B0 = ",DEC B0
Stop
calibrated:
LCDOut $fe, $c0,"S = ",DEC scale , " B0 = ", DEC B0
Stop

Thanks
jessey

sougata
- 1st March 2006, 16:33
Hi,

I am sorry you got confused with the 10 and 13. They just instruct your hyperterminal to make a new line so that you get the next reading on a next line. Good that you found out the solution to your LCDOUT and your code is okay. Now the calibration part :

Well try it out with a 0.22uF. And run the program. Your B0=255 means that the program has calibrated the scale value for your circuit. Notedown the scale value and use it in your program without using anymore calibration. It is a one time process to get the full range out of the pot command. Actually the pot command charges and discharges your capacitor through this resistor (in your case the LDR) and finds the time constant. It makes the Input/Output to get a tristated sort of logic. The PICs have an inbuilt schmiddt trigger which allows the software to sense the discharge slope.

Hope this helps

Regards

Sougata

jessey
- 2nd March 2006, 09:21
Thanks Sougata,

I managed to find a 0.22uF and it works great. Thanks for your much appreciated help.

jessey