D-Type flip flop for toggle. Slap-a-duck

Discussion in 'Digital Circuit Design' started by sirchuck, Jul 3, 2017.

  1. sirchuck

    Thread Starter Member

    Feb 14, 2016
    79
    2
    I have a vibration sensor switch and a LED circuit shoved inside a rubber duck. I want to slap the rubber duck and toggle it on, then slap it again to turn it off. This seems like it should be pretty simple, but when I started researching how to toggle I found D/T/JK flip flops.

    The T flip-flop seemed perfect, you send it a signal from the vibration sensor and it would toggle the led on or off. Unfortunately, I couldn't find any for sale on E-bay, so I bought a bunch of D-Type flip flips.

    Now I'm wondering how to wire up my D-Type flip-flop to turn my duck on and off based on jiggling my vibration sensor.

    The D Flip Flop has 5 connections.
    Vcc ( For incoming voltage ) check
    CLK ( For my vibration sensor ) check
    GND ( For ground ) check
    Q ( Output toggle to LED ) check
    D ( Data input ? ) --- What do i attach here so that Q will toggle? Do I wire directly to VCC ?

    Do I need to throw my D-Type's away and hunt harder for a T-type flip flop ic?

    Thanks !
     
  2. dl324

    AAC Fanatic!

    Mar 30, 2015
    6,946
    1,606
    If you connect Q# to D , Q will toggle on each clock pulse.
     
    sirchuck likes this.
  3. sirchuck

    Thread Starter Member

    Feb 14, 2016
    79
    2
    Perfect! Thanks. I don't have the part here yet to test, but I hoped it would be something simple like that.
     
  4. AnalogKid

    AAC Fanatic!

    Aug 1, 2013
    7,006
    1,985
    I know this is a huge favor to ask, but could you share the part number?

    ak
     
  5. crutschow

    Expert

    Mar 14, 2008
    19,523
    5,444
    No, the D-FF will readily work as a T FF..
    But you need to deal with multiple triggers from vibration sensor, which will cause it to rapidly switch back and forth, so you need a way for the FF to only trigger once when it receives a bunch of pulses.

    Here's an LTspice simulation of such a circuit.

    The Q output follows the D input whenever a CLK pulse is detected so if you connect the /Q output to the D input, it will alternate states for every clock pulse.
    R1C1 delsys this change at the D input so it only changes state once for a series of clock inputs until the D input reaches the logic level change value (about 1/2 the supply voltage.
    So you can see below that the output only changes state for the first in a series of clock pulses (green trace).
    If the series of pulses from the vibration sensor is too long and it triggers more than once, then just increase the value of C1 until it only changes state once.

    I used 4.5V for the supply (as from 3 AAA alkalines) and drove the LED directly from the FF output.
    If you want more than a couple mA through the LED to make it brighter, then you can add a transistor driver on the FF output, but a high brightness type LED may be bright enough with that current.

    The signal from the vibration sensor must be at least 4V.

    Power and ground for the CD4013 are not shown but must be connected, and all unused inputs for the other FF in the package must be grounded.

    upload_2017-7-3_16-48-37.png
     
    absf likes this.
  6. sirchuck

    Thread Starter Member

    Feb 14, 2016
    79
    2
  7. sirchuck

    Thread Starter Member

    Feb 14, 2016
    79
    2
    crutschow,

    Ok, yes that's a good catch about needed to trap consecutive vibrations from the sensor, and I think I get what you did with the resistor and capacitor, but I do not understand what to connect to D in my situation from your 4013 chip. I don't have a |Q only a Q.

    Do I need to invert Q and then attach that to D? What do I use to invert Q if so?
     
  8. crutschow

    Expert

    Mar 14, 2008
    19,523
    5,444
    That FF does not have a /Q output so can't be use as a toggle FF without added logic.
    You should have posted here before ordering parts. :rolleyes:
     
  9. AnalogKid

    AAC Fanatic!

    Aug 1, 2013
    7,006
    1,985
  10. sirchuck

    Thread Starter Member

    Feb 14, 2016
    79
    2
    [​IMG]

    I got the only flip that doesn't flop. :(
     
  11. sirchuck

    Thread Starter Member

    Feb 14, 2016
    79
    2
    crutschow, would this one work for me? If not, could you point me to one that would? I can't find anyone selling T-Type flip flops anywhere. I guess real electricians just alter D-types in the wild.

    Thinking about this one:
    http://www.fairchildsemi.com/datasheets/NC/NC7SZ175.pdf
     
  12. sirchuck

    Thread Starter Member

    Feb 14, 2016
    79
    2
    Nevermind, I just realized you did tell me a chip that would work already CD4013. :D
     
  13. crutschow

    Expert

    Mar 14, 2008
    19,523
    5,444
    That should work.
    But it's designed for glue-logic in microprocessor applications and comes in a tiny, surface-mount package.
    Those are somewhat tricky to solder if you don't have some experience with that.
    I recommended going with a CD4013 in a DIP package as it's a lot easier to work with.

    I don't think they build T-FFs since they are easy to make by connecting D to /Q.
    Printed circuit traces are cheap. :)
     
  14. MrChips

    Moderator

    Oct 2, 2009
    16,730
    5,130
    If you insist on using a single D-type flip-flop with no /Q output, you can create an inverter using a single transistor and a couple of resistors.
     
    sirchuck likes this.
  15. AnalogKid

    AAC Fanatic!

    Aug 1, 2013
    7,006
    1,985
    One 2N7000, one 10K resistor.

    ak
     
  16. crutschow

    Expert

    Mar 14, 2008
    19,523
    5,444
    Okay, I've got it down to one CD4049 inverter.
    Anyone reduce the parts count any further? :D
     
  17. KeepItSimpleStupid

    Distinguished Member

    Mar 4, 2014
    2,774
    492
    J-K flip flops can easily be turned into toggle. I BELIEVE it's J=K=1 and use the Clock as input.
     
  18. crutschow

    Expert

    Mar 14, 2008
    19,523
    5,444
    True.
    But a JK wouldn't work in my circuit with the debounce delay to the D input.
     
  19. AnalogKid

    AAC Fanatic!

    Aug 1, 2013
    7,006
    1,985
    Is that just to salvage the non-Q- ff or for the whole circuit (toggle ff and debounce)?

    ak
     
  20. crutschow

    Expert

    Mar 14, 2008
    19,523
    5,444
    Salvage the Q-FF.
    Without an inversion you can't turn the D-FF into a T-FF.
     
Loading...