Help on getting the BS2 to measure pulse width
Lucky
Posts: 98
Hi, guys. I'm trying to get my basic stamp 2 to use the pulsin command to measure the width of a high pulse in microseconds sent from a LM555 timer.
The problem is when the time is displayed on the debug terminal, it starts decreasing for a long time till a certain range and goes up and down··· forever. I'm almost certain that its the basic stamp program and not the 555 timer. The 555 is hooked up·in astable mode and Resistor1 is 100 ohms, Resistor2 is 72 kohms, and C1 is·0.1 microFarads. So the question is how to get my stamp to accurately read the pulse width of the high portion of the signal? Please help!!!!!· Here is the·program I used!
·' {$STAMP BS2}
' {$PBASIC 2.5}
Pulse PIN 7
Scale CON $200···· ' 2.0 microseconds per unit
Pulse VAR Word
Main:
·PULSIN Pulse, 1, time··········· ' measure positive pulse
·IF (time > 0) THEN
· DEBUG HOME,
····· DEC time, " units ", CLREOL······ ' display raw value
· time = time */ Scale················· ' adjust for stamp
·DEBUG CR,
·· DEC time, " us "················ 'display microseconds
·ELSE
· DEBUG CLS, "Out of range"
·ENDIF
· PAUSE 200
· GOTO Main
END·············
The problem is when the time is displayed on the debug terminal, it starts decreasing for a long time till a certain range and goes up and down··· forever. I'm almost certain that its the basic stamp program and not the 555 timer. The 555 is hooked up·in astable mode and Resistor1 is 100 ohms, Resistor2 is 72 kohms, and C1 is·0.1 microFarads. So the question is how to get my stamp to accurately read the pulse width of the high portion of the signal? Please help!!!!!· Here is the·program I used!
·' {$STAMP BS2}
' {$PBASIC 2.5}
Pulse PIN 7
Scale CON $200···· ' 2.0 microseconds per unit
Pulse VAR Word
Main:
·PULSIN Pulse, 1, time··········· ' measure positive pulse
·IF (time > 0) THEN
· DEBUG HOME,
····· DEC time, " units ", CLREOL······ ' display raw value
· time = time */ Scale················· ' adjust for stamp
·DEBUG CR,
·· DEC time, " us "················ 'display microseconds
·ELSE
· DEBUG CLS, "Out of range"
·ENDIF
· PAUSE 200
· GOTO Main
END·············
Comments
is being measured (Pulse Pin 7) and to a Word variable. Also,
you haven't defined 'time' as a variable.
Delete
and add
phil
Values less than 2K aren't "good" resistor values for 555 circuits.
Here's a good site with a 555 astable calculator where, if working the maths are·impeding your progress,·you can plug in values till you get it right.
http://www.royalrife.com/555_calculator.html
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
Also, R1 (RA)·is the resistor from +V to pin 7, and it should be > R2 (RB).
I'm not ripping you here, but your results·cannot be better than·your test·set-up.
How can you figure a frequency based on PULSIN?· f = 1 / (t1 + t2)· On-time is one thing, off-time is another, and to figure frequency you will need to know both; PULSIN is not FREQIN (there is no FREQIN.)
Post Edit -- Some sounds are sine waves (natural sounds), but electronic sounds can be some form of square wave or triangle wave.· If it's a true square wave, t1 = t2, then basing freq on 1/t1 is valid, but only then.· If it's a sine wave, what part of the period will you measure?· A triangle wave?· It's a complicated business.
COUNT could be used to determine frequency (but some signal conditioning may be necessary.)
Post Edited (PJ Allen) : 4/13/2008 10:36:50 PM GMT
Also your mention of pulsin raised a valid point that i had not thought about. So i guess i can just use Pulsin to measure both parts of the square wave. For my project I'd have a mic. hooked up to an op amp then to a comparator to square the sine wave coming from the mic. Would this plan work? Thanks agian, you've been very helpful thus far.
Keep a resistor between your 555 out and your Stamp input and you can pull-up, pull-down, or go without, and not get burned.
(What other website?· Use PBASIC Help, it came with the Stamp IDE.)