Encoders

eclectic

Moderator
I didn't test it because I didn't know how to wire it. How should I? The main cpu requires a square wave.
Try something like this diagram
Download/power/capacitor not included.
Make sure they share a common Gnd.
Try say a 1k (1000 Ohm) resistor.


e
 

Attachments

D396

Senior Member
RISE, RISE FROM THE DEAD THREAD!! okay I have been working on this on and off and hav eonly been able to get the following code working but its not reliable.
Code:
;Schmitt trigger code
#PICAXE 08M
SYMBOL adcValue = b0
SYMBOL currentState = b1
SYMBOL lowThreshold = 100 ;or whatever
SYMBOL highThreshold = 156 ;or whatever

init:
currentState = 0 ;assume initial state of output is 0

main:
readadc 1, adcValue

;schmitt trigger cleverness
if adcValue >= highThreshold and currentState = 0 then
  high 2
  currentState = 1
endif

if adcValue <= lowThreshold and currentState = 1 then
  low 2
  currentState = 0
endif
goto main
for some reason E your code only outputs high on pin 1 all the time regardless of the position of the wheel. Anybody have any more ideas or maybe I am just doing something wrong?

Thanks for the help guys.
 
when I have it hooked up to my oscilloscope it only triggers sometimes not every time it changes from black to white or vise versa. other times it randomly triggers when it is only viewing on color.

Edit: just to let you guys know I am D396 I just changed my account
 

eclectic

Moderator
for some reason E your code only outputs high on pin 1 all the time regardless of the position of the wheel. Anybody have any more ideas or maybe I am just doing something wrong?

Thanks for the help guys.
How are you "seeing" the output?
Visually or with an oscilloscope?

e
 

eclectic

Moderator
If I remember, the program was fine
when "triggered" by the 64Hz signal from the 18M2.

Sorry but I can't help with the encoder part.
Is it "seeing" the light correctly?

e
 

zanger

New Member
Hello TMFKA-D396 (the member formerly known as...)

Maybe spikes spoil your adc-readings? You can try fixing a 100nf capacitor from pin 2 at sensor's JP1 to ground. The 10k resistor into your encoder combined with the capacitor will produce about 1ms RC-time. This will "soften"? the edges. The Schmitt-trigger program later on will produce square waves.
 
That cap doesn't do anything. The problem is that the sensor's output only changes by about .5 from light to dark at the distance I am using (about 1/4") and I need a full 0 to 5v output from the picaxe. I probably should have told you guys the voltage outputs earlier. I think that's why E's code didn't work, it was made for bigger waves. So I thinks its more complicated than we were thinking or maybe more simple?
 
Well , got it working. I used martins original code. The problems were twofold, A) I committed basic fail and didn't tie serin to ground, It only works grounded B) I had the encoders mounted too far from the wheel, mounted closer and instant success.
Thanks for all the help guys.
 

eclectic

Moderator
@EGj
Now that you've fixed your circuit,
could you try the code from post #35?

I'm interested to see if it works on your setup.

And thanks for admitting and fixing your errors.
It might help someone else in the future.

e
 

zanger

New Member
Well , got it working. I used martins original code. The problems were twofold, A) I committed basic fail and didn't tie serin to ground, It only works grounded B) I had the encoders mounted too far from the wheel, mounted closer and instant success.
Thanks for all the help guys.
Nice to hear. I once had some problems with this type of sensor/encoder and it appeard to be a false triggering by
indoor TL-light reflecting at the black/white surface. In a demanding environment it can be solved by modulation
of the LED (light) and decoded by a PLL at output. Kind of bandfilter.
 
Well, I cant get it to work, It could be me but the way I have it wired up pin1 is always high, this could have something to do with the sensor outputting 3V for light and 3.5 for dark so its not low and high.
 

erco

Senior Member
Old thread, but the best encoder sensors I've found are obsolete and until recently, nearly impossible to find. But just recently, a US seller has 10-packs on Ebay. I bought some, they are the real deal. Built-in amplifier & Schmitt trigger in a tiny package.

http://www.ebay.com/itm/10pcs-Hamamatsu-P5587-Photo-IC-output-digital-Photoreflector-reflective-Sensors-/221264829793?pt=LH_DefaultDomain_0&hash=item3384695d61

As a result, also newly back in stock (and datasheet) at http://www.junun.org/MarkIII/Info.jsp?item=48
 
Top