ensuring inputs are triggered to High & Low

Bryang

Member
Hi,
I an using an infrared photo interrupter (Jaycar ZD1901) with a rotating plastic disc with slots to provide a hi/low trigger. I'm OK with the PICAXE coding, but how can I make sure I'm going to capture eash trigger point?
With about a 4.5v Vcc, it measures a High voltage out of about 2.8v, and a low at about 1.6v.
I thought a Schmitt trigger would be the way to go, and happen to have a 74HC14, although never played with one before, but from what I can gather from the datasheet (I'm pretty new to trying to decifer such things) what this would prefer to see is more like <1.4v for the low trigger voltage and >3.6v for the high trigger voltage. The more I have been looking/reading, the more confused I'm getting!
Any suggestions on what components I can use between the photo interrupter & the Picaxe pin to ensure I get clean high & low inputs when I expect them?

Bryan
 

Dippy

Moderator
How about a transistor and a couple of resistors? I'd have a quick 20 minute playaround with a simple transistor circuit before plunging into things with lots of legs. It may work and it would keep things simple.
How's your electronics?
 

moxhamj

New Member
There is a simple op amp solution - set a 2V reference with two resistors (eg 27k/18k) to the - input, and send the sensor input to the +input. The output will go high if the +input goes above 2V. 741 will work though I prefer the 324 quad op amp.
 

Jeremy Leach

Senior Member
I guess it depends exactly what you are doing.

I timed the ReadADC command to take 0.812ms at 8MHz clock the other day, regardless of voltage being read. So might be a code-only solution to your problems as long as you're not doing anything too fast.
 

Bryang

Member
I'm still struggling with some of the electronics basics, but slowly learning! If you would like to offer some suggestions where to start I'll give it a go. I've got a few transistors & resistors to play with.
I think Dr_Acula's suggestion is sort of along the lines I was thinking but I don't have any op-amps (yet!). I gather this means the resistors are per a voltage divider for the 2v reference. I'll hunt down the datasheets on these & may be able to get some later in the week as an alternative to Dippy's suggestion, & try both.

Thanks.
Bryan.
 

alastair_baker

New Member
This link does some of the sums for you, does this help ?

http://hyperphysics.phy-astr.gsu.edu/hbase/electronic/schmitt.html

I’m assuming that you understand the concept of Schmitt triggering otherwise this link's good http://ourworld.compuserve.com/homepages/g_knott/elect344.htm

-otherwise the previous suggestion of a simple level trigger as suggested above might be simpler to start with, but certainly go with Schmitt triggering if you can to prevent multiple event triggering ( think equivalent to switch bounce - sorry dont know your level of knowledge if im teaching you to suck eggs)



 

slurp

Senior Member
Hold on guys... you coming at this from the wrong angle.

The tweaking the resistors in the existing circuit will give the either "active" (varying responce to light) or "switch" (on/off)output, there's real no need for additional circuits.

There's two sides to this make sure you're driving the LED, then there's the configuration of the Common-Emitter or Common-collector Amplifier for your output.

I hope this page helps explain (comments welcome!)

www.minisumo.org.uk/EdgeDetection.php

while I was working on reflected light the principal is the same. I think it's Fairchild that have some application sheets that go into more detail on this.

For Active Mode Vcc < R x Icc

For Switch Mode Vcc > R x Icc

I think switch mode need Vcc to be much greater than R x Icc


Best regards,
Colin
 

Dippy

Moderator
The forum has shown various options.
I'd start simple (esp if components to hand) and work up. But like Slurp implies, I'm surprised you have to got all tis effort.

That device is a standard photo-tr optocoupler in a geomtery suited for slotted disks etc. It is not very fast and has a simple transistor output.

If the transistor method doesn't work then try the op-amp method. In fact, with a dual op-amp and a bit of skill you could introduce hysteresis - et voila! a SChmitt trigger.


Edited by - Dippy on 16/01/2007 12:56:31
 

Jeremy Leach

Senior Member
Just another couple of thoughts...

Is it shielded from ambient light? If 'Dark' isn't really dark then maybe you're not getting the full range of voltage.

Also, as it's a phototransistor then I guess you've got a series resistor from the collector of the transistor? Maybe your value of resistor is too high, so when the transistor is off it doesn't raise the voltage as high as it could? Could try lowering the value of the resistor a bit and see what difference that makes to the voltage range.


Edited by - jeremy leach on 16/01/2007 13:33:03
 

Bryang

Member
don't worry about me sucking eggs - I think they are more like scrambled aggs at the moment!
i Still struggle with figuring when to put resistors & caps in circuits and how big/small they should be, though can usually follow coding OK. I wondered originally if I was making all this more complicated that it needed to be - I'll try a few things tonight starting with the transistor route (?) & see how I go.

FYI, it's basically the same application on 2 projects - checking speeds of bicycle wheel & pedal (& inclinometer) to measure work done in cycling, and a LCD bar graph for an old motorbike tacho which I don't want any electrical conections to. LCD & code stuff all works fine (testing with variable voltage input in place of trigger) so now just the trigger stuff to get right :)
Thanks guys.
Bryan
 

steirny

Member
You can achieve hystereis with a single op amp solution. Just use a large value resistor from the output back to the +ve input. As the op amp changes state it drags the input partially in that direction. The value will determine the size of the hysteresis. Do a search on comparator with hysteresis.
 

Dippy

Moderator
True, but lets get bryang up-and-running with the basics before confusing him with detail, yeah? (As it sounds like his electronic level is just starting to bounce above zero on the experience gauge). Applies to me too btw.
 

Jeremy Leach

Senior Member
I agree with Dippy ....lets look at the basics. Some component values and a circuit diagram would be great if you're up to it bryang.

Perhaps I could tempt you with a free ASCII art program to paste your circuit into this thread ??/ ...<A href='http://www.tech-chat.de/download.html' Target=_Blank>External Web Link</a>
 

moxhamj

New Member
I have a drawer full of hundreds of different ICs, virtually all of which have been made redundant by the picaxe. I even got lazy the other day and used a picaxe to make a 1ms pulse for an electric fence when a 555 could have done the job.
But time and again, I do seem to keep reaching for op amps. These seem to be needed for amplifying signals and for threshold detection and for filtering. The humble LM324 is $1.50 at Jaycar, and I'd suggest getting a few. Power to pin 11, ground to pin 4, photo interrupter to pin 3, 27k from 5V to pin 3, and 18k from pin 3 to ground. Output is pin 1 and goes to the picaxe.
Then again, as Jeremy Leach suggests, why not just feed the signal straight into readadc and set a threshold in software of 128? If the signal is slow it will be fine, and if it is faster than 0.8ms, then you are going to need a bit more pre conditioning anyway, such as a counter or divider.
 

Dippy

Moderator
Well then, it's time for Bryang to dig out his/her calculator to predict the 'worst-case' speeds based on slot size, radius, expected max rpm etc. Over to you bryang....

Calculator + pencil + data = zero-in-on-solution.
 

moxhamj

New Member
The timing might be a bit tricky. If a bike wheel has a 1.8m circumference and is going 10 revs a second and the flag going through the photosensor slot is 1cm wide the pulse will only be 1/2 a millisecond. The picaxe might miss it if it is using readadc, though this will probably work at low speeds.
If speeds are being measured then I presume Pulsin would be the best method, and that will need the signal to be a clean 0/5V.
Of course, Pulsin times out after 0.65 seconds, so there might need to be a few Do loops to measure slow speeds.
 

Bryang

Member
Neat little program Jeremy :)

Here is what I had on my breadboard by memory...

Vcc 5v
-----------o-------o
| |
| |
| |
ZD1901 | |/ other half of
IR-Photo-interupt V -&gt; -| IR-Photo-int
LED - |&gt; Transistor
| |
| |
o o-------- PIC pin
| |
.-. .-.
| | | |
330R | | | | 330R
'-' '-'
| |
| o
| |
| V -&gt; LED
| -
GND | |
----------o-------o
(created by AACircuit v1.28.6 beta 04/19/05 www.tech-chat.de)

When I get home I'll get into it, but a few things I can tell you are:-

The trigger disc I had in mind is simple - slots cut in a defunct CD (I've got plent of them I use as coasters!)so 120mm dia. I thought of actually using one of the clear extras that sometimes come in the stacks, and painting/putting on a sticker so I have clear/blocked segments maybe just one or two, say 60deg (this means no sharp edges to whack into sensor if it gets a wobble up!)
My thoughts this morning are that I should have the LED/Resistor and lead to PICAXE pin BEFORE photo-interruptor transistor so I'll try that first, so that I should then only see the LED voltage drop, and once I am confident with circuit I can remove the LED which I have got there just si I can see what's going on. I assume I should also bump up the resister to 1k then(?) for a bit more current protection for the pic. Does that sound right? bit of 1/2 guessing on my part here with my electronics skills!

The motorbike crank trigger would be the fastest, so, if max rpm is 9000rpm...
9000rpm --&gt; 150rps --&gt; 6.6ms
if i paint on 1 &quot;slot&quot; at 180 deg, that means I've got 3.3ms window to get/count a pulse.

Thanks for all the feedback so far :)
I'll check back in a couple of hrs :)

Thanks
Bryan

 

Bryang

Member
Damnit!! the spaces dissapeared on the schematic when I posted it!

OK.
I had Vcc going direct to the LED side of the ZD1901.
I had a 330R resistor to Gnd after the LED side of the ZD1901.
I had Vcc going direct to the Collector side of the ZD1901.
From the emitter, I went to the PICAXE pin &amp; also branched off to an LED, on to a 330R, then to Gnd.
What I was talking about was putting the LED, 330R &amp; picaxe pin on the collector side.

Bryan.
 

moxhamj

New Member
See http://www.rev-ed.co.uk/picaxe/policy.htm

Explains to put square bracket code squarebracket at the beginning of post and squarebracket slash code at the end. That makes no sense at all I know, but I can't actually write what you need to put as the forum doesn't display it! Have a look at the webpage above. Then circuit will display properly. You can go back and edit it now if you like.

The idea of using one of those blank disks that come with CD stacks is brilliant - a great use for something that normally is thrown away!

I don't know if the circuit you posted is exactly the same as the one that is giving the indeterminate voltage output, but if that was the circuit, I suspect it is the forward voltage drop of the LED in series with the phototransistor that is the problem. I would leave that LED out, just go for the phototranistor and the 330R and see what the volts are.
The other possible cause would be the slot not being totally black or white. IR light is very similar to red light, and red light can easily get through a piece of paper stuck on a piece of clear plastic, or black marker pen drawn on plastic, or even a thin piece of black plastic. Metal will give a much more definite on/off. I wonder about a piece of thin aluminium glued onto the plastic disc, or even a disc made of aluminium?

Edited by - Dr_Acula on 17/01/2007 05:09:36
 

Bryang

Member
<code><pre><font size=2 face='Courier'>
Vcc 5v
-----------o-------o
| |
| |
| |
ZD1901 | |/
IR-Photo-interupt V -&gt; -|
- |&gt;
| |
| |
o o-------- PIC pin
| |
.-. .-.
| | | |
330R | | | | 330R
'-' '-'
| |
| o
| |
| V -&gt; LED
| -
GND | |
----------o-------o
</font></pre></code>
 

Jeremy Leach

Senior Member
Well done ...it makes such a difference.

I'd say : Get rid of that LED straight away. The forward voltage drop across the LED will prevent your 'low' voltage to the PICAXE going low.

Also 330R seems low for the emitter resistor. Being so low, it won't allow the High' voltage to the PICAXE to be very high. Experiment with 1K or higher.

This might make all the difference and negative any extra circuitry.

PS: The 'readadc' solution is a last-ditch solution. It could work, but it's far better to have a digital signal coming in, so you can use count command, interrupts, etc etc.

Edited by - Jeremy Leach on 17/01/2007 09:04:22
 

Dippy

Moderator
Its good to see that you appreciate that you'll have to remove the LED.

When you say &quot;if i paint on 1 &quot;slot&quot; at 180 deg..&quot; , do you mean that your disk will be half black/opaque and half white/clear?

Otherwise if you're talking about just drawing a fat black line across a clear disk then the sensing period is going to be a whole lot less than 3.3mS. (i.e. depends on fatness of line and radius; angular velocity and all that..).

And as the Count says, be aware of IR passing through marker pen. Couple of coats of black paint may be OK or even insulating tape - with 'balance' care required for those RPMs of course. Old Cds; great idea. I knew those free-with-the-newspaper Max Bygraves CDs would come in handy one day.

PS Good point re: res value. You will have to experiment with values as they will depend on the LED applied current too (and opacity and clarity of your disk).
So first job is to just get a good logic high-low out the sensor. Then move onto the PICAXE logic in.
I would suggest reading the appropriate PIC data sheet to see what the logic-IN high/low values are. Get Microchip Data Sheet and look somewhere under the Electrical spec towards the end.


Edited by - Dippy on 17/01/2007 09:18:08
 

Bryang

Member
Hi:)
run out of time tonight to get fully there, but...
Dippy, yes, 1/2 the disc clear, and 1/2 the disk covered - not just a line:)

I put a 1k res in series to the PICAXE pin, but otherwise circuit still as above, &amp; I started again to baseline voltages to pin...
(background light - typical household globe)
Vcc = 5.10v High at Picaxe pin = 2.79v
Low with cardboard trigger = 1.52v... metal ruler for trigger = 1.43,... aluminum foil 1.49v.

Next I took out LED and (with foil trigger)it went 1.73v with sensor clear, and 3.03v with foil over trigger - ok! going backwards here!

next changed the 330R after the interupter transistor for a 1k... now 4.4v &amp; 4.3v - thought I was now either onto something or horribly lost, so...
I upped the resistor out of the interupter transister to GND to 10k , and :) :)

the high (at the PICAXE pin after the 1k) was <b>4.3v </b> , and the low was <b> 0.25v </b>

Thanks everyone for the suggestions. I'll have a play with the op-amps etc sometime as I know they will be handy another day, but for now, my problem (at the breadboard level at least)is solved, co I can confidently make up a PCB on the weekend, and I will look at gluing foil to a clear plastic CD disc :)
 

Bryang

Member
Not sure! I'll see how I go on the weekend &amp; go from there, as it looks like I will be close enough to Vcc &amp; Gnd to get a reliable High &amp; Low trigger. A bit of the suck it &amp; see method now!
I'm now wondering about the response time of the ZD1901 mentioned a couple of times in the thread - I don't think it will be an issue, particularly with the bicycle project, but possibly with higher RPM on the motorcycle project(?) but no doubt I will find out ;-)
 

wilf_nv

Senior Member
Here is a possible improvement using positive feedback for snappy output transitions. The circuit switches the LED current between 10mA and 2mA which is indicated by two brightness levels of the series red LED. This also reduces average current of the circuit. The output to the Picaxe switches between 50mV and 4.4V.

I used a photo interrupter salvaged from an old printer and a 2N3904 transistor. You may need to tweak resistor values a bit to make it work with your parts.

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

o---------o-----Vcc=5V
| |
| |
ZD1901 | |/
IR V -&gt; |
LED - |&gt;
| |
o o
| |
red V -&gt; o--- PIC pin
LED - |
| |
.-. .-.
| | | |
100R | | | | 10K
'-' '-'
| 2N3904 |
o---+ |
| \| |
.-. |---o
| | &lt; | |
1K | | | .-.
'-' | | |
| | | | 100K
| | '-'
| | |
o---o-----o---- GND

PHOTO INTERRUPTER WITH HYSTERESIS
</font></pre></code>

Edited by - wilf_nv on 18/01/2007 09:18:30
 

BeanieBots

Moderator
Indeed a good solution as the hysterisis is applied to the 'activity' (ie the light level) rather than the post event voltage level. Well done wilf_nv.
 

premelec

Senior Member
Hysteresis definitely is needed - the bike units I've seen have a magnet and reed switch giving a lot of hysteresis... otherwise any vibration might give you a lot of readings - however the PICAXE can certainly have hysteresis programed into its code... an approprite lowpass RC filter is also good to filter out fast useless edge effects...
 

Bryang

Member
an approprite lowpass RC filter is also good to filter out fast useless edge effects...

Sorry, I'm after help again now! - I was quite pleased with myself thinking that I had just worked out 95% of what wilf_nv had added!
OK, so we are talking a resistor &amp; capacitor(s) combo here (?) Looking thru some of my notes, would something like a 1k resistor &amp; a 0.01uF in parallel to GND be starter (?) and would this be between the ZD1901 output and the 1k resistor on the line to the PICAXE pin (?)
 

wilf_nv

Senior Member
Correction!

The positive feedback is fine and dandy and the red LED rapidly turns on and off but point where the output of the circuit is connected to the picaxe does not exhibit the same kind of snappy transition.

Two circuits are attached below that correct this.

Circuit v2 connects the base of a second NPN to the point where the LED is driven with a small but rapidly changing signal. The collector output signal connects to the picaxe input and switches rapidly rail to rail.

The v3 circuit is simpler but does not have LED indication and swings between 3.2V and 200mV which meets the logic requirement for the picaxe input. I have tested V3 also with 10x larger resistors which reduces overall power.

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

Vcc=5V---o--------o---------o
| | |
| | |
|ZD1901 | |/
| IR V -&gt; |
| LED - | &gt;
| | |
| o o
| | |
| red V -&gt; |
| LED - |
| | |
.-. .-. .-.
| | | | | |
10K | | 100R | | | | 10K
'-' '-' '-'
| | 2N3904 |
| o---+ |
| | \| |
picaxe&lt;--o .-. |---o
| | | &lt; |
| 1K | | |
| '-' |
\| | |
|------o |
&lt; | |
| |
GND------o------------o

PHOTO INTERRUPTER WITH HYSTERESIS v2


Vcc=5V-----------o---------o
| |
| |
ZD1901 | |/
IR V -&gt; |
LED - | &gt;
| |
o-------o o
| | |
.-. .-. .-.
| | | | | |
1K| | 100R| | 10K| |
'-' '-' '-'
| | 2N3904 |
PicAxe&lt;---|-------o |
| \| |
| |-------o
| &lt; |
| |
| |
GND------o-------o

PHOTO INTERRUPTER WITH HYSTERESIS v3
</font></pre></code>


Edited by - wilf_nv on 19/01/2007 05:08:09
 

ljg

New Member
SO, I saw this a bit late, I suppose, but I need to ask. On which Picaxe are you implimenting this?

Some Picaxes have Schmitt trigger imputs built in...
 

Bryang

Member
Sorry, I should have pointed out the PICAXE I'm using from the start! It's an 18X (and I'm running the 16x2 LCD directly (parallel) from the 18X).
Bryan.
 

Dippy

Moderator
Take a look at the Microchip PIC DataSheets.
You'll see a mix of straight logic and schmitt for PICs.
Though, I must admit, a comment in the PICAXE manuals would be handy for 'advanced' users.
 

Bryang

Member
so how do i go about making use of this newly discovered feature? I need it spelled out in detail, as this is all a bit above my plug-in-&amp;-turn-it-on skills! Mind you, I'm enjoying this learning curve:)
 

Dippy

Moderator
Before everyone goes into a long description, do you know what 'hysteresis' means? Just roughly?

You'd come across it in things like twilight (dusk/dawn) switches. As the ambient light droops a lamp might come on, but just at the threshold it may dither and be unsure so it may flash on and off becuase it can't make up its mind.

If you add 'hysteresis' then if the ambient light falls below a threshold the lamp comes on (as before) BUT the ambient would have to rise above a higher threshold for the lamp to switch off. This prevents ditheringat the hreshold, so the result is a definite ON-OFF and not mightbe.

Oh dear, its easier to do this with numbers...

Anyway a Scmitt input effectively has hysteresis which is better for sensors which may dither at the threshold. I'm sure someone can explain it better, but whoever does please don't go on about op-amps at this stage.
 

Jeremy Leach

Senior Member
Well, I think that's a good description Dippy.

Bryang, I think for your purposes it means that you don't really need Wilf's circuit that has hysterisis built in. You just need to feed the output of your existing circuit (the one you tuned to get a good voltage swing) into one of these Schmitt inputs.


Well, that's my opinion.
 
Top