Interface with logic gates

AllanBertelsen

Senior Member
Hi there
I've got a MC14011BCP (a quad 2-input NAND Gate). I want to invert the output from a output-pin on 08M. Can I just do that, or should other components be involved?
 

AllanBertelsen

Senior Member
I want to measure light with two LDR's. But I'will only use one input. So if out1 is high, one LDR is used and when out1 is low it's the other LDR.
 

premelec

Senior Member
sounds like you could invert the PICAXE output in the software - it will go from 0 to Vcc almost - the logic and PICAXE should have a common Vcc supply to assure compatibility - or regulated Vccs for each.
 

AllanBertelsen

Senior Member
What I need is really 4 LDR's. It's an idea for a weather vane. I want to read a binary black and white pattern. Two inputpins read two LDR's at one time. One output determine witch.
 

hippy

Technical Support
Staff member
I prersume you are trying to something like this ...<code><pre><font size=2 face='Courier'>.------------------------------------------------------.
| |
| .-------------. |
| |\ |\ ___ | | |
}---| &gt;O---| &gt;O----|___|---.----.---&gt;| ADC OUT |---'
| |/ |/ LDR | | | |
| | .|. `-------------'
| |\ ___ | | |
`----------| &gt;O----|___|---' |_|
|/ LDR |
--^-- 0V </font></pre></code> If you are just requiring two on/off, black/white detectors, could you not simply put the two LDR's in series and determine which of the four possible conditions the returned voltage falls into ?<code><pre><font size=2 face='Courier'>
--.-- +V .-------------.
| ___ ___ | |
`---|___|---|___|---.---&gt;| ADC |
LDR LDR | | |
.|. `-------------'
| |
|_|
|
--^-- 0V </font></pre></code>
 

AllanBertelsen

Senior Member
How would I know the differece between 01 and 10?
Thank you for the ascii-art. Now I can edit it. I was thinking of something like this:

.--------------------------------------------------.
| |
| .-------------. |
| |\ ___ | | |
}------| &gt;O----|___|---.----.---&gt;| ADC OUT |---'
| |/ LDR | | | |
| | .|. `-------------'
| ___ | | |
`--------------|___|---' |_|
LDR |
--^-- 0V

I'm done some reading. I now understand that I can make the inverter by a transistor and two resistors.

Another transistor can be used to make a switching circuit. Then I don&#8217;t need ADC but just a digital in.

The reading would be quite simple:

Out2=0
b1 = pin1
b1 = b1 * 2
b1 = b1 + pin1
Out2=1
b1 = b1 * 2
b1 = b1 + pin1
b1 = b1 * 2
b1 = b1 + pin1

 

AllanBertelsen

Senior Member
Ups, just another thing to learn!

<code><pre><font size=2 face='Courier'>
.--------------------------------------------------.
| |
| .-------------. |
| |\ ___ | | |
}------| &gt;O----|___|---.----.---&gt;| ADC OUT |---'
| |/ LDR | | | |
| | .|. `-------------'
| ___ | | |
`--------------|___|---' |_|
LDR |
--^-- 0V

</font></pre></code>
 

AllanBertelsen

Senior Member
It's early in the morning here. My brain could do with an upgrade. I'll take another cup of coffee. The code should be:
high 1
b1 = pin2
b1 = b1 * 2
b1 = b1 + pin3
low 1
b1 = b1 * 2
b1 = b1 + pin2
b1 = b1 * 2
b1 = b1 + pin3

'Or

high 1
bit0 = pin2
bit1 = pin3
low 1
b0 = b0 * 4
bit0 = pin2
bit1 = pin3
 

hippy

Technical Support
Staff member
<i>How would I know the difference between 01 and 10? </i>

Good point. It might need to be an R-2R type ladder perhaps, or maybe just parallel another R with one of the LDR's.

I used double-buffering rather than have one LDR straight off the output because if the direct LDR exhibits a low enough R it could prevent the inverter going high. No idea if that would ever happen in reality.

I've thought of another problem - When one of the LDR's is pulled to 0V it is paralleled with the bottom R of the divider. That too would change the voltage being read.

I suspect this is a case of building a test jig and seeing how usable it is.
 

Jeremy Leach

Senior Member
I agree with Hippy's series suggestion. As you're using the ADC to read the input then there could be 4 distinct ADC readings for the 4 possible combinations.

You'd have to be cunning with the LDR resistances for &quot;0&quot; and &quot;1&quot; though.

For instance, just to explain:
If resistances for both LDR_A and LDR_B were the values 1 and 0:

<code><pre><font size=2 face='Courier'>
A B TOTAL
0 0 0
0 1 1
1 0 1
1 1 2

</font></pre></code>

This wouldn't work because the total has a duplicate result.

However if LDR_A had,say, &quot;0&quot; = 0 and &quot;1&quot; = 1, and LDR_B had &quot;0&quot; = 4 and &quot;1&quot; = 6 then

<code><pre><font size=2 face='Courier'>
A B TOTAL
0 4 4
0 6 6
1 4 5
1 6 7

</font></pre></code>

Which gives 4 distinct output resistances and therefore 4 distinct ADC values. You could shade one LDR, or adjust the holes in the rotating piece to get this difference in &quot;0&quot; and &quot;1&quot; values.


BUT ....this is just in theory! In practice I think the problems are:
1. The responsiveness of an LDR (they are relatively slow)
2. Getting consistent &quot;0&quot; and &quot;1&quot; values from the LDRs. You'd need a constant light source, and protect from external light interference (e.g sunlight).

My gut feeling is that it could work - but it might be difficult to get right.
 

AllanBertelsen

Senior Member
Tank you for the answer Hippy. The double-buffering could have other benefits. I'm thinking on the current. But this is really where I do need help.

Would this setup be a possibility?

<code><pre><font size=2 face='Courier'>
.------------------------------------------------------.
| |
| .-------------. |
| |\ ___ ___ | | |
}--| &gt;O--|_ _|---|_/_|---.------.---&gt;| IN OUT |---'
| |/ | LDR | pot1 | | | |
| | ___ | | | `-------------'
| `-|___|-T1--------| |
| R1 | .|.
| &#172;&#172;___ ___ | | |
`--------|_ _|---|_/_|---| |_|
| LDR | pot2 | |
| ___ | | --^-- 0V
`-|___|-T2--------&#180;
R2
</font></pre></code>
T1 and T2 are transistors. I don't know how to draw a transistor. Base up and emitter at right. R1 and R2 could be 330 and pot1 and pot2 at 10k.
Should I use double-buffering or can I do with a single transistor inverter gate.
/Allan
 

AllanBertelsen

Senior Member
Jeremy thanks. I did build a switching circuit on my breadboard. A LED sits beside the LDR. Then I used a sheet of paper with black and white patterns. The circuit was able to detect as I hoped for even thou, it wasn't protected from external light interference.
 

AllanBertelsen

Senior Member
I see I did an error. Sorry. Out from each switch circuit should be between the collector and the resistor. I'll not try to make ASCII-art on that.
/Allan
 

AllanBertelsen

Senior Member
I think I got it right this time.

<code><pre><font size=2 face='Courier'>
.------------------------------------------------------------.
| |
| .-------------. |
| |\ ___ ___ | | |
}--| &gt;O-.-|_ _|---.--|_/_|---. .-----.---&gt;| IN OUT |---'
| |/ | LDR | pot1 | | | | |
| | ___ | | | | `-------------'
| `-|___|-.-T1---------. | |
| R1 | | | |
| `------------)--{ .|.
| ___ ___ | | | |R3
`-------.-|_ _|---.--|_/_|---| | |_|
| LDR | pot2 | | |
| | | | |
| ___ | | | |
`-|___|-.-T2---------.--)-----{
R2 | | |
`---------------&#180; --^-- 0V

</font></pre></code>
 

AllanBertelsen

Senior Member
Yes Jeremy, I want one input for reading a reed switch. I want to send data by a serout. That&#8217;s 2 pins. Then I got 3 pins left on 08M to read 4 LDR's.
So to make it even more complex, the circuitry described above has do be doubled. But one output should be enough to switch both circuits. Then two input would be use to make the readings.

high 1 'the output pin that determine witch two LDR's to read
bit0 = pin2 'LDR1
bit1 = pin3 'LDR2
low 1
bit2 = pin2 'LDR3
bit3 = pin3 'LDR4

I read your page about 0-9KeyInput Idea. I might end up using a resistor ladder. But would it not be complex to the LDR's being variable.
 

Jeremy Leach

Senior Member
I'd forgotten that web page of mine ! No ... you've got to be careful, a resistor ladder is ok for keypress where one switch is being pressed at a time, but this situation is different as you can have 4 switches (LDRs) pressed at any time.

What I was describing above regarding series LDRs might work for 4 LDRs, at least in theory !:

<code><pre><font size=2 face='Courier'>

Supply ---------+-----
|
__|__
|LDR A|
|_____|
|
__|__
|LDR B|
|_____|
|
__|__
|LDR C|
|_____|
|
__|__
|LDR D|
|_____|
|
+----------&gt;ADC
___|____
|Resistor|
|________|
|
GND----------+-------

</font></pre></code>

The trick is choosing the on-off values of the LDRs correctly.

<b> First look at an ideal case ... </b>

Imagine a 4-bit binary number, where each bit represents one of the LDR values: Bit3:Bit2:Bit1:Bit0

So:
Bit0 (0 or 1) has an overall value of 0 or 1
Bit1 (0 or 1) has an overall value of 0 or 2
Bit2 (0 or 1) has an overall value of 0 or 4
Bit3 has an ovarall value of 0 or 8

So if the LDR resistances varied 0 to 1K, 0 to 2K, 0 to 4K, 0 to 8K, then the overall resistance would vary from 0 to 16K.



And with a sutiable series resistor to ground would give unique ADC values for each combination of LDR readings.

<b> In reality ... </b>
You would have to carefully adjust the light to each sensor to acheive the on-off resistances. Probably not easy.

The 'on' resistance of the LDR won't be 0. Would need to account for this in the maths. Haven't got my head round this bit.

As Beaniebots pointed out a while ago, the brightness from LEDs fades over time.


Despite these points, IF this could be made to work then the circuit is very easy.
 

Jeremy Leach

Senior Member
Another idea would be to just have a single LDR but gradually vary the light hitting it from 0 to 360 degrees rotation.

But two LDRs would work better. This is actually exactly the same principle as in my variable capacitor idea on another topic. Could have two LDRs and 'maybe' could get better than 4 bit resolution of direction.

Edited by - Jeremy Leach on 05/04/2006 12:01:17
 

AllanBertelsen

Senior Member
I must confess that it was the capacitor-talk that made me think of another solution. I only need 4 bit resolution. Then you got N, NNE, NE, ENE, E ..., A finer resolution would not provide much more information. The wind-speed and direction at 4 bit resolution would give fairly precise wind-vectors. I made a neural network as my master-thesis years ago. This network predicted tomorrow's weather by the data of today's weather. My idea is to gather data for redoing this project.
 

Jeremy Leach

Senior Member
Interesting. I'm not saying that more accuracy is worth it, or justified. I'm personally just interested in the approach and that it might have other uses.
 

AllanBertelsen

Senior Member
I based the idea of a transistor solution on the last two circuits on this page <A href='http:// http://www.kpsec.freeuk.com/trancirc.htm' Target=_Blank>External Web Link</a>. It's sort of a challenge for me. I want to learn how to use transistors. It's years ago I played with this kind of stuff. When I saw how easy an cheap picaxe is, I did not wait long to order.

Ahh &#8211; the turning light idea. I had another similar idea. You could make a paper strip with all grey tones from black to white. Mount it inside a turning tube and let a LED/LDR-pair read the grey tone. Then there will only need to be one LDR.
 

Jeremy Leach

Senior Member
Go for it ...be interested in the result. I've only recently got some breadboard and now wonder where it's been all my life !! Makes experimenting with these sort of solutions so much easier.

It's often been pointed out on this forum that you've just got to experiment to find out if a solution will work.
 
Top