Shop OBEX P1 Docs P2 Docs Learn Events
Need to Decode pulses from two input pins — Parallax Forums

Need to Decode pulses from two input pins

ForrestCForrestC Posts: 8
edited 2005-07-06 16:57 in BASIC Stamp
Greetings:
·I am trying to count pulses from two·input pins and then shift them out
using latch , data, and clock output·pins.

·The input pin 3 will be the count pin with a pre-ambe of two pulses (using Button).
·Pin 4 will be a enable pin , when high the pulses are counted, when falling the counted pulses will be sent out
of the (latch,Dpin,and clock)·pins.

The catch 22 problem is that·pin 4 will·have pulses on it and i do not want to send a 0(zero) counts out of the
the (Latch,Dpin and Clock).

·I have come up with an solution of sending two pulses into Pin 3 as a preamble·so that when pin 4 goes high
it's in a valid counting mode.

The coding seems a little complicated because i have to wait until the count of pin 3· gets to two than
switch to watching for pin 4 to go high.

Pin 4 will be going high and low for other reasons.

The·pulse times will be in millsec to seconds.
I have a Basic Stamp 2·, using Basic 2.5

·Any suggestions ???

I need be i can send a drawing attached word that explains my problem a little better.

Thanks
ForrestC

Comments

  • Beau SchwabeBeau Schwabe Posts: 6,557
    edited 2005-07-05 23:09
    More information is always better. Please send a drawing if you can.

    I'm a little lost on pin 4..... will the Stamp be enabling itself to count or is there an external
    event on pin 4 that tells the stamp to count? You indicate pin4 has some sort of traffic on it,
    but you do not go much into detail. This might help me and others understand more if we knew
    what was happening on pin 4 as well as the other pins.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • ForrestCForrestC Posts: 8
    edited 2005-07-06 14:27
    This the Program i am working on and i am trying to send a timing diagram or the

    pulses that i want to decode.

    (what is the best way to send the drawing ???)

    Thanks ForrestC



    'Pin 4 will have the preamble of two pulses· that says that Pin 3 will be
    ' Be enable to read the "load and send pulse".
    ' at other times Pin 3 will have other pulses sent to it, these must be discarded
    ' only when pin 4 sees two distinct pulses that pin 3 is enabled to do its thing
    ' I hope this helps.





    ' BUTTON-mod.BS2
    '· From Example Button.bs2
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    '**** Pin Assignments to send to UCN5814A *************
    Latch········· PIN···· 0······················ ' latch UCN5841A on interface Board
    Dpin··········· PIN···· 1······················ ' data pin to UCN5841A
    Clk············· PIN···· 2······················ ' shift clock to UCN5841A
    '****** Pins For input data to basic stamp 2 *********************
    pin3············ PIN···· 3····················· ' Load and Send
    Pin4············ PIN···· 4····················· ' Preamble and then Count


    '============= Variable list =======================
    btnWrk0········· VAR···· Byte······· '0-15
    btnWrk1········· VAR···· Byte······· '0-15
    btnWrk2········· VAR···· Byte······· '0-15
    btnWrk3········· VAR···· Byte······· '0-15
    added··········· ·VAR···· Byte······· '0-15
    Pulse_count····· VAR···· Byte······· '0-15
    btnWrk1 = 0
    btnWrk2 = 0
    btnWrk3 = 0
    Pulse_count = 0
    ·READ 0, Pulse_count······························ ' Read long term storage number then send
    ·GOTO sendout:···································· ' to UCN5841A

    Main:
    ·· Pulse_count = 0··· 'rezero pulses
    ·· PAUSE 5··········· ' wait 5 millisec
    ·· BUTTON pin4, 1,255,20,btnWrk0,1,dwn1··········· ' first rise of pin4
    ·· dwn1:
    ·· BUTTON pin4, 1,255,20,btnWrk1,0,dwn2··········· ' first fall of pin4
    ·· dwn2:
    ·· BUTTON pin4, 1,255,20,btnWrk2,1,dwn3··········· ' second rise of pin4
    ·· dwn3:
    ·· BUTTON pin4, 1,255,20,btnWrk2,0,dwn4··········· ' second fall of pin 4
    ·· dwn4:

    ·· BUTTON Pin3, 1, 255, 20, btnWrk1, 0, Main····· 'wait for pin 3 to go High (and stay High)than
    ·· DEBUG "*"


    Down:
    ·· BUTTON Pin3, 0, 255, 20, btnWrk3, 1, sendout·· 'if button is let go than send out serial stream
    ·· BUTTON Pin4, 1, 255, 20, btnWrk2, 0, Down····· ' count button pushes
    ·· Pulse_count· = Pulse_count + 1····················· ·' Count pulses from Labview program
    ·· DEBUG DEC Pulse_count······························ · ' Show on debug Screen
    ·· GOTO down
    ·Sendout:
    ····· ' This loop moves the 8-bit value 'counter' onto the output lines of the
    ····· ' UNC5841A, pauses, then increments counter and repeats.· The data is shifted
    ····· ' msb first so that the msb appears on pin QH and the lsb on QA. Changing
    ····· ' MSBFIRST to LSBFIRST causes the data to appear backwards on the outputs.

    ·· · HIGH Latch······················ ··························· ' initialize latch output to UCN5841A
    ···· SHIFTOUT Dpin, Clk, MSBFIRST, [noparse][[/noparse]Pulse_count]· ' send the bits···· to UCN5841A
    ···· PULSOUT Latch, 1····················· ················ ' transfer to outputs···· to UCN5841A
    ···· WRITE 0, Pulse_count·························· ······· ' Write Value to EEPROM for long term Storage
    · GOTO main··················································· ' Start all over again waiting for Pin 4
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-07-06 14:59
    I don't know that I'd use BUTTON in this case ... if the pulses are narrow you could do something like this:

    · DO
    ··· PULSIN Preamble, 1, pWidth
    · LOOP UNTIL (pWidth > 0)

    BUTTON will be looping constantly and you may miss a pulse -- PULSIN will wait (until its timeout) and the loop above will restart it if it does indeed timeout.· By using this code you don't need to have work variables for the BUTTON instructions.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • ForrestCForrestC Posts: 8
    edited 2005-07-06 15:55
    The pulses will be slow .01 to 1 sec , right now i am using microswitches to debug. Later on i will be using
    TTL level pulses but still .01 to 1 sec
    ForrestC
  • ForrestCForrestC Posts: 8
    edited 2005-07-06 16:01
    Also I am worried about the Maximum pulse width of 131 millsec Max for

    the BS2 using PULSEIN. If the pulse is greater than 131 millsec it will time out.

    ·ForrestC
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-07-06 16:23
    That's why I put PULSIN in a loop: if it times out it will be restarted and the loop will run until it gets a value.· Or you could really simplify and do this:

    · DO : LOOP WHILE (MyPin = 1)·· ' wait for high
    · DO : LOOP WHIEL (MyPin = 0)·· ' wait for low

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • ForrestCForrestC Posts: 8
    edited 2005-07-06 16:57
    oh, ok i'll try that.

    ForrestC
Sign In or Register to comment.