proximity sensor problem
AHMET AKSU
Posts: 62
·
··· I use proximity sensor for producing count pulses topropeller.I use· resistance and diode for· interface proximity to the propeller
·the problem is that same times sensor produce 2 or 3 pulse for one thing.I using for counting that code
CON
········ Sensor = 4····· 'Sensor pin number
······· _clkmode······· = xtal1 + pll16x
······· _xinfreq······· = 5_000_000
VAR
······· long· count
·······
OBJ
······· term··· : "vga_text"
·······
PUB start | i
· 'start the tv terminal
· term.start(16)
·
· 'setup Counter A for positive edge counting on Sensor pin
· phsa := 0
· frqa := 1
· ctra := %01010 << 26 + Sensor
·
·repeat······················
··· term.str(string($A,12,$B,1))
··· term.dec (phsa)
··· I use proximity sensor for producing count pulses topropeller.I use· resistance and diode for· interface proximity to the propeller
·the problem is that same times sensor produce 2 or 3 pulse for one thing.I using for counting that code
CON
········ Sensor = 4····· 'Sensor pin number
······· _clkmode······· = xtal1 + pll16x
······· _xinfreq······· = 5_000_000
VAR
······· long· count
·······
OBJ
······· term··· : "vga_text"
·······
PUB start | i
· 'start the tv terminal
· term.start(16)
·
· 'setup Counter A for positive edge counting on Sensor pin
· phsa := 0
· frqa := 1
· ctra := %01010 << 26 + Sensor
·
·repeat······················
··· term.str(string($A,12,$B,1))
··· term.dec (phsa)
Comments
Those sensors usually have rather long transition times when going from low to high or vice versa. Times like several microseconds are not unusual. Considering that the Prop counter can increment 80 times in a microsecond and that there's always noise on the signal, it is probable that you count noise during the transition through the threshold voltage, which I only a few minutes ago found to be around 47 % of Vdd - i.e. 1.55 V, At least on my board. There doesn't seem to be any hysterisis on the inputs.
Two solutions: 1 A hardware Schmitt trigger 2 A software solution. Do the counting in Spin instead of using the very fast counter. Spin code takes something like nx10 microseconds to execute one instruction so a loop counting your input will never see more than one transition.
Your question, as you put it now, makes me wonder if you are running without any load resistor between sensor outout and Vss. A simple solution, that I think you should try first is to load the sensor output with a resistor to ground. Make it pull as much current as it can take - if 12 V supply voltage, a 400 mW resistor can handle 33 mA. So, if you make the resistor 390 ohms, you will be safe. If you have 24 V you will need to make the resistor 1500 ohms.
Try that first. I assume that you have the necessary series resistor (around 10 kohms) to protect the Prop input.
If that doesn't help, put the schmitt between sensor signal and Prop. Remember that the schmitt also needs a series resistor. But the Prop doesn't need it if you are using a TTL/5V CMOS schmitt. Also, the schmitt usually inverts your signal. You may need to count the other edge.