Shop OBEX P1 Docs P2 Docs Learn Events
Help on getting the BS2 to measure pulse width — Parallax Forums

Help on getting the BS2 to measure pulse width

LuckyLucky Posts: 98
edited 2008-04-13 23:37 in BASIC Stamp
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!!!!!cry.gif· 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

  • phil kennyphil kenny Posts: 233
    edited 2008-04-13 05:38
    You have assigned the same name to both the pin where the signal
    is being measured (Pulse Pin 7) and to a Word variable. Also,
    you haven't defined 'time' as a variable.

    Delete

    Pulse  VAR   Word
    



    and add

    time    VAR   Word
    



    phil
  • LuckyLucky Posts: 98
    edited 2008-04-13 19:36
    oops sorry something happened when i copied and pasted, but yes the actual program has what you said.
  • LuckyLucky Posts: 98
    edited 2008-04-13 19:45
    I don't know whats happening; I used the formulas provided by the manufacturer for the timing period of t1, the time the pulse is high, and the measurement starts 1000 micro seconds above what i calculated and then it starts dropping till it stays in this range of time where the reading goes up and down 40 microseconds. its weird. Please help. Btw, frequency is 100Hz and timing period one is 5 microseconds, or thats what i calculated anyway.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-04-13 20:02
    luckyshooter,

    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
  • FranklinFranklin Posts: 4,747
    edited 2008-04-13 20:21
    Also, if you ATTACH your code rather than copying it into the body of the post we get what you aer actually running and not something else.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • LuckyLucky Posts: 98
    edited 2008-04-13 21:02
    Okay, now I've changed R1 to 6 kohms and R2 to 68 kohms, but i still have the same problem. The microseconds value starts at 6340 and then starts decreasing again, and the calculated time was 5128. I used the site you recommended and it is very helpful, thank you. And thank you franklin for the helpful note on attaching my program instead of copying and pasting.
  • LuckyLucky Posts: 98
    edited 2008-04-13 21:12
    do you guys have any suggestions, even a new program i could try. See, the 555 timer is just a test to see if i can get the Bs2 to read a pulse width. My overall project is hooking up a microphone and getting the bs2 to read the frequencies put out by the mic. and then take appropriate actions related to the frequency.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-04-13 21:52
    If you're using a "555" (not a 7555 or LMC555), then the output should be pulled-up to +V (4.7K or so).

    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.
    luckyshooter said...
    read the frequencies put out by the mic. and then take appropriate actions related to the frequency
    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
  • LuckyLucky Posts: 98
    edited 2008-04-13 22:55
    Well actually its a LM555, made by National Semiconductor, so i'm not sure if your mention of the outout being pulled up to +V still applies. So if you could please tell me that would be great.

    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.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-04-13 23:02
    COUNT could be used to determine frequency (but some signal conditioning may be necessary.)··Read all about·it in PBASIC Help.
  • LuckyLucky Posts: 98
    edited 2008-04-13 23:23
    Sorry. I went to a different website than you suggested and it said it would count transistions of a square wave assuming the duty cycle is 50%. And in my project the waves wouldn't always be 50%. Then when you posted the message again I went to parallax and found that it didn't say any thing about 50% duty cycle. So assuming that parallax didn't forget to mention anything, yeah COUNT could work and would be a BIG help in project. Thanks, but would i still need to pullup output to +V since its LM555, not 7555 or LMC555. Thanks that COUNT command is a big help.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-04-13 23:37
    COUNT counts transitions, asymmetrical, one-shot, whatever.

    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.)
Sign In or Register to comment.