Shop OBEX P1 Docs P2 Docs Learn Events
TRYING TO CREATE A 4-BIT BINARY COUNTER FROM A CLOCK PULSE. — Parallax Forums

TRYING TO CREATE A 4-BIT BINARY COUNTER FROM A CLOCK PULSE.

shopshop Posts: 3
edited 2015-01-02 12:30 in BASIC Stamp
I created a TTL circuit using a 74193 (up/down counter) using a external clock pulse. The binary output of the 74193 is wired to a 74154 (one of sixteen decoder). The output of the 74154 is connected to 16 LEDs.

It works fine using these TTL logic IC's to control the count out of the 74154. My external clock pulse is derived from audio that is from a Schmitt trigger circuit to make it a clock pulse into the 74193.

I now want to use the Basic Stamp 2 to perform the same function, and I have run into problems programming the Basic Stamp to do this. I want the Basic Stamp to "simulate" the 74193.
I am new to the Basic Stamp, and it is not working exactly like the TTL circuit, meaning the output of the Basic Stamp binary count is to only change with the transition (low to high) of the external clock pulse.
any solutions anyone?

Comments

  • Hal AlbachHal Albach Posts: 747
    edited 2014-12-23 13:16
    Can you post what you have so far?
  • tomcrawfordtomcrawford Posts: 1,126
    edited 2014-12-23 13:28
    shop wrote: »
    I created a TTL circuit using a 74193 (up/down counter) using a external clock pulse. The binary output of the 74193 is wired to a 74154 (one of sixteen decoder). The output of the 74154 is connected to 16 LEDs.

    I
    I am new to the Basic Stamp, and it is not working exactly like the TTL circuit, meaning the output of the Basic Stamp binary count is to only change with the transition (low to high) of the external clock pulse.
    any solutions anyone?

    So you have to keep track of whether you have counted "this" positive transition. An easy way to do that is to, after you have incremented your counter, wait until you see the negative transition. For extra credit, implement the up/down function.
  • Mike GreenMike Green Posts: 23,101
    edited 2014-12-23 13:35
    First of all ... How fast is the external clock? Remember that the Basic Stamp is relatively slow. Execution times for simple statements are on the order of hundreds of microseconds to milliseconds.

    To react to the transition of the external clock from low to high your program will need some way to remember the previous state of the clock. It can do that with a 1-bit variable or by being in one of two loops ... one when the previous clock state is low and the other when the previous clock state is high.

    clockPin PIN 0 ' Use pin 0 for this example ... input by default

    loopLow:
    IF clockPin = 0 THEN GOTO loopLow
    ' Here the clock pin has gone from low to high
    loopHigh:
    IF clockPin = 1 THEN GOTO loopHigh
    ' Here the clock pin has gone from high to low
    GOTO loopLow
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2014-12-24 09:30
    Here is a state machine based on two bits that hold the new and old state of the pin. The program logic in the IF statement looks for new to be high and old to be low. That only happens at the desired transition, and additional code can be written into the DO loop. As mentioned, the trigger pulse has to be long enough for the Stamp to recognize it, a few milliseconds at least, the execution time of the DO loop. The TTL chips in contrast respond in nanoseconds.
    ' {$STAMP BS2pe}
    ' {$PBASIC 2.5}
    
    new VAR BIT
    old VAR BIT
    trigger PIN 0
    
    new = trigger
    old = new
    
    DO
      new = trigger
      IF old ^ new & new THEN   ' detect transition with logical XOR AND
        DEBUG CR, "triggered!"
        old = new
      ENDIF
    LOOP
    
  • shopshop Posts: 3
    edited 2014-12-30 15:36
    Hi Mike Green,

    First, thank you for responding to my request for assistance with my Basic Stamp problem.
    I believe I applied your solution to create a 4-bit binary counter, as I made a simple test program based on your reply. (see below)

    What I notice from this program I made, is the " CLOCKPIN" goes high, the output on pin #11 is a changing a clock pulse when I check it on
    my scope. I apply a steady "High" input to Pin 0, I thought the output on Pin 11 would be a steady high until i remove it.
    I don't understand why the output is a clock pulse, and not a steady output. Any suggestions for me?

    Shop.

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}


    clockPin PIN 0 ' Use pin 0 for this example ... input by default


    DO
    IF clockPin = 0 THEN GOTO loopLow
    ' Here the clock pin has gone from low to high

    loopLow:
    LOW 8
    LOW 9
    LOW 10
    LOW 11


    IF clockPin = 1 THEN GOTO loopHigh ' Here the clock pin has gone from low to high


    loophigh:
    HIGH 11


    LOOP
  • Mike GreenMike Green Posts: 23,101
    edited 2014-12-30 15:51
    Please look again at what I wrote in Post #4. In what you posted, the first IF statement goes to loopLow no matter what the value of clockPin is. The second IF statement goes to loophigh no matter what the value of clockPin is. You could remove both IF statements and the following labels and the program would essentially be the same.
  • shopshop Posts: 3
    edited 2015-01-02 12:28
    After much trial and error, I followed your instructions, and it is counting the way I can use.

    Thanks a bunch !! :)
  • PublisonPublison Posts: 12,366
    edited 2015-01-02 12:30
    Good news!

    You can go the your first post and "edit advanced" to marked this "Solved".

    If you can not find it, I will do it for you.
Sign In or Register to comment.