JK Flip flop up/down counter help. - Page 1
Forum section: electronics / beginners

author: dazzlaa
author_rank: Newbie
timestamp: April 03, 2020, 07:51:51 am
content: Hello, thanks for reading.This is my first post so I will start by saying hi!I am currently studying a foundation electronics degree and currently have a basic digital intro module to complete. I am designing an up/down synchronous counter using JK flip flops. I have the next state tables and K-maps done which gave me the boolean algebra to design the circuit itself based on 3 JK flip flops. The circuit I have put together in multisim but I am struggling to understand how to connect the displays. I need a 7 segment display to count 1-5 and then display FULL when count = 5 and Y=1. Currently my display was a 4 input 7 seg display that only displayed the number 7. I think I need the 8 input common C 7 seg display but again, my understanding is limited and the course notes on displays are non existant!I think my head has become a little confused to be honest.Maybe someone could give me a little nudge in the right direction to set me off again? any advice will be really appreciated, like I said, I am very new to the subject and currently studying multiple subjects so I am a little saturated.. go easy on meBest RegardsFLIP FLOP COUNTERbydarren.clipson, on Flickr

author: tggzzz
author_rank: Super Contributor
timestamp: April 03, 2020, 08:24:56 am
content: Welcome, and that's a good, thoughtful first post. Better than many peoples' questions, in factI'll ignore whether or not the counter works, but you need an asynchronous block between the counter and the display. The block will have four inputs (count+y) and seven outputs (one for each segment).Then you need to define seven mappings, each of which relates one segment to the four inputs.Draw a two dimensional table with the count+y on one axis and each segment on the other axis, and fill each cell with whether the segment should be on or off.If using some form of programmable logic, you could then enter the relevant equation and let the tool sort out the logic.As you are doing this all manually (good!) then you can draw one karnaugh map for each segment, and work out the logic from that in the usual way.

author: dazzlaa
author_rank: Newbie
timestamp: April 03, 2020, 08:36:13 am
content: Thank you for the fast reply there.That was really helpful, sounds like a lot of work for a beginner like me but also sounds like a logical sequence of events. I do indeed want to do this all manually with K-maps! I was trying to figure out how to read the logic pattern based on what I already had but had not realised a per segment map had to be drawn, nor an asynchorous block. I will use this information and try to progress further. Best regards

author: Benta
author_rank: Super Contributor
timestamp: April 03, 2020, 02:51:45 pm
content: What tggzzz said.From a formal point of view, your circuit has the FFs (storage) and the "next state" encoder. What you now need is the "output decoder", which is pure combinatorial logic.

author: tggzzz
author_rank: Super Contributor
timestamp: April 03, 2020, 04:02:03 pm
content: Quote from: Benta on April 03, 2020, 02:51:45 pmYes, that is a good addition.The OP shouldeventuallyconsolidate his understanding of finite state machines (FSMs). There are variousimplementationstyles (e.g. "one hot"), each with advantages and disadvantages. Which you choose depends on the implementation technology and external constraints; just be aware of them and be flexible.

author: dazzlaa
author_rank: Newbie
timestamp: April 04, 2020, 11:47:11 am
content: Thank you for the suggestions. It is really confusing for me so I apologise if this is completely wrong based from what has been suggested but here goes...I added in a 7 seg common cathode display and added in a 5v VCC supply. I was hoping that it would trigger the display based from the decoder inputs. I was also hoping that when I flick the car entering or exiting switches it would incriment the memory logic through the FF's. Unfortunately the display seems to fire every LED and gives a constant 8 which flashes at clock frequency. Does this mean I have logic 1 on every output from my FFs?I also added in a secondary circuit to display the full sign when the car park reaches capacity. Using the grey code of 1011 (5 cars present and Y=1 for car approaching) gave me Q2=X Q1=0 Q0=X so my logic was: "As long as Q1 is 0 and Y=1 I should illuminate the full sign?" Hence the pretty basic circuit at the bottom of the design.Unfortunately my tutor is stuck in Egypt and has been hit with the virus so I am a little bit on my own here. However I have 4 weeks to figure this out so it's not panic stations just yet, although i'm 39 years old so the grey matter is not what it used to be!in prog1bydarren.clipson, on Flickr

author: gcewing
author_rank: Regular Contributor
timestamp: April 05, 2020, 12:15:51 pm
content: I think tgzzz has sent you off in the wrong direction a bit here. If you were building this out of real components you would need a decoder, but it looks like you're just trying to simulate it, so things are a bit different.The "7 segment display" component you've used looks like it has a built-in decoder, so it should work fine. I think what's happening is that your counter is not working for some reason, and all its outputs are high, which is why the display is showing "7" (which is 111 in binary).To confirm this, connect an "LED" or "probe" component (not sure what your simulator calls it) to each output of the counter to see what it's really doing.

author: gcewing
author_rank: Regular Contributor
timestamp: April 05, 2020, 01:12:45 pm
content: One problem I can see with your design is that by running it from a 100Hz clock, it will count multiple times if either of the switches is held down for more than 0.01 seconds.At the very least, this will make it rather hard to test. I would suggest connecting the clock input to a switch, so that you can make it count one step at a time while watching for proper behaviour.In real life, you would need to do something more to ensure that it counted exactly once each time one of the switches was pressed and then released. But if the purpose of the exercise is just to design an FSM, this probably isn't necessary.

author: jmelson
author_rank: Super Contributor
timestamp: April 05, 2020, 04:16:10 pm
content: Quote from: gcewing on April 05, 2020, 01:12:45 pmYes, for a real application, it would be much better to use a microcontroller for this, and build in debounce logic on the switch inputs.When either switch has been debounced and given one clean edge to work from, then cycle the counter for one count.But, to continue with your exercise, what you would want is a circuit that produces one debounced pulse from either switch, or that together and then use that instead of the 100 Hz clock to drive the counter to the next state.(Another complication is what if one car exits at the exact time one car enters?)Jon

author: dazzlaa
author_rank: Newbie
timestamp: April 06, 2020, 07:54:12 am
content: Quote from: gcewing on April 05, 2020, 01:12:45 pmQuote from: jmelson on April 05, 2020, 04:16:10 pmThanks for the replies. I'm trying to keep it a simple as possible to be honest so I can do my best at keeping track of the signal trail.. It is already getting quite complex for me! With that said, I don't need to worry about real world implications at this pointI have reduced the clock frequency to 2 Hz today. I have also rechecked my K-maps and found one incorrect connection. I hoped that might makes things react differently within the circuit but it is still the same.I have checked my JK connections against some University documentation for a 3 bit synchronous counter and the connections are the same as I have, so this gives me confidence somewhat.

author: dazzlaa
author_rank: Newbie
timestamp: April 06, 2020, 07:57:57 am
content: Quote from: gcewing on April 05, 2020, 12:15:51 pmThanks for the suggestion. So if I connect my 6 JK outputs to the 7 seg display, this should work? I have connected up the same 7 seg display at the lower portion of the circuit to display 'FULL' and each pin represented an individual segment so I am not sure if what I am using is what you refer to?Great suggestion about adding probes though, i'll do that right now.

author: dazzlaa
author_rank: Newbie
timestamp: April 06, 2020, 08:07:05 am
content: I added probes to track the logic throughout the circuit and all three JKs have logic 1 on the Q output at all times.... I am not sure why as the inputs to the Jks switch as expected.in prog 2bydarren.clipson, on Flickr

author: dazzlaa
author_rank: Newbie
timestamp: April 10, 2020, 06:29:25 am
content: Did some extra reading on JK's. So I figured out that the PRESET and CLEAR, if set both to one then the FFs are controlled by the J and K and clock inputs. Now I have working flip flops.. to an extent anyway! My 7 seg does not respond as I expect. It does cycle but seems to be suffering from a bit of lag and does not cycle in logical order.