Binary prime number counter

Thread Starter

franm

Joined May 19, 2018
3
Hello all of you,

I'm supposed to build a synchronous binary counter for all prime numbers between 0 and 20 using T or JK Flip-Flops for a university project.

The counter is supposed to count up from 2 to 19, then go to 0 (the start signal) and start counting up all over again.
Now I know I've got five outputs due to the fact that 19 as the highest required prime number has five digits in binary.
I need to present it in a schematic way, but so far I've only got the logical function, which is

y = (x4¬x3¬x2x0) v (¬x4x2¬x1x0) v (¬x4¬x3x1x0) v (¬x4x3¬x2x1x0) v (¬x4¬x3¬x2x1¬x0)
with x4 being the output for the first digit, x3 being the second and so on. (So that in 00011 resembling the 3, x4 to x2 are a 0 and x1 and x0 are a 1)

And now I'm stuck. I do know how a standard synchronous binary counter looks like, but I'm really unsure what to do, to make it skip numbers and make it come to an end after 19 to repeat the said numbers from 2 to 19.

If there's someone who could help me, I'd be very grateful.

F.
 

WBahn

Joined Mar 31, 2012
30,075
That's the logical function for what? Whether or not a five bit value (less than 20) is prime?

As you've already discovered, that won't help you very much with a counter.

What if I asked you to make a 3 bit counter that went 0-5-7-4-3 and repeated. How would you do it? If you are in state 7, what state do you go to next? What do the inputs to the three FF need to be if the lsb FF is a D-type, the middle one is a T-type, and the msb is a JK-type? What about when you are in state 4? Or 3?

Your book should tell you how to design an arbitrary finite state machine. A binary counter is just one particular example.
 

Thread Starter

franm

Joined May 19, 2018
3
What if I asked you to make a 3 bit counter that went 0-5-7-4-3 and repeated. How would you do it? If you are in state 7, what state do you go to next? What do the inputs to the three FF need to be if the lsb FF is a D-type, the middle one is a T-type, and the msb is a JK-type? What about when you are in state 4? Or 3?

Your book should tell you how to design an arbitrary finite state machine. A binary counter is just one particular example.
Well, I don't know how to do that. My university doesn't really seem to care to give us an advice or help or even lessons, instead we have to learn everything by ourselves. And for me, who hasn't done anything like this before, it's really hard to figure out where to start and what to do.
I know I need to check how I get from the one state to the next, but I don't know how.

And we've got no books either. The only thing recommended was a manual for the software we're supposed to use.
 

dl324

Joined Mar 30, 2015
16,943
Welcome to AAC!
Well, I don't know how to do that. My university doesn't really seem to care to give us an advice or help or even lessons, instead we have to learn everything by ourselves.
What university are you attending and what year are you in your studies? Could it be that they've taught you enough to do this problem and you just don't know enough to ask questions?

y = (x4¬x3¬x2x0) v (¬x4x2¬x1x0) v (¬x4¬x3x1x0) v (¬x4x3¬x2x1x0) v (¬x4¬x3¬x2x1¬x0)
with x4 being the output for the first digit, x3 being the second and so on. (So that in 00011 resembling the 3, x4 to x2 are a 0 and x1 and x0 are a 1)
To avoid ambiguity of first and second, I'd recommend using MSB and LSB. If I understand you correctly, X4 is the MSB.

Since this is homework and we don't know what you know, it would be helpful for you to post your work so we can see how you derived the expression for Y.

You also need to tell us what Y is. The problem said you could use T or JK flip flops, but you never told us which you decided to use. Either way, you're going to have 5 or 10 equations and you need to tell us what they are and which bit is most significant.
 
Last edited:

WBahn

Joined Mar 31, 2012
30,075
My university doesn't really seem to care to give us an advice or help or even lessons, instead we have to learn everything by ourselves.
If that's true, then why on Earth would you waste your time and money going there?

Since you seem okay with having to learn everything by yourself, try the e-book here:

https://www.allaboutcircuits.com/textbook/digital/chpt-11

Particularly Chapter 11 with an emphasis on Finite State Machines.
 

Thread Starter

franm

Joined May 19, 2018
3
To answer the both of you, I'm in my second semester and I'm going to a German university with actually quite high standards, maybe that's why they want us to learn everything by ourselves. And they of course do give us lessons, but so far they don't have to do too much with our current projects.

Also, thank you WBahn for that link, I indeed might find some useful information in it.
And to dl324, I really forgot to mention that y of course is supposed to be the logical state 1, whenever a prime number is detected. And I just realised that I also forgot to mention the like most imortant thing. I need to show the prime numbers on a 7-segment display.

Now, before anyone wastes their time anymore, I already found how to do it out by now. I'm using the usual synchronous bit counter for three digits, to make it count up from 0 to 7 and repeat and then used a decoder to convert (if that's the right word for it) the numbers into each of the eigth prime numbers I need.

Nevertheless, I thank the both of you for your time and have a nice day.
 

WBahn

Joined Mar 31, 2012
30,075
There are multiple ways to do most things. Using an 8-state binary counter and then using a decoder to map the binary values to arbitrary outputs is certainly one way and it has the advantage of being able to map directly to the fourteen outputs you need for your two 7-segment displays. I don't know whether this is an approach that will be acceptable to your instructor, which will likely depend on what material was being covered that this project is related to. But it's also possible that the limit of 20 on the primes was chosen specifically to result in 8 values, making this approach doable easily with a 3-bit binary counter.
 

dl324

Joined Mar 30, 2015
16,943
I really forgot to mention that y of course is supposed to be the logical state 1, whenever a prime number is detected.
Are you certain that you're supposed to just decode prime numbers, as opposed to designing a counter whose count sequence is the prime numbers less than or equal to 19?
And I just realised that I also forgot to mention the like most imortant thing. I need to show the prime numbers on a 7-segment display.
This would be easier to do if the counter output was only prime numbers of interest (and zero).
Now, before anyone wastes their time anymore, I already found how to do it out by now. I'm using the usual synchronous bit counter for three digits, to make it count up from 0 to 7 and repeat and then used a decoder to convert (if that's the right word for it) the numbers into each of the eigth prime numbers I need.
How can you use a 3 bit counter to generate prime numbers less than 20?
 

WBahn

Joined Mar 31, 2012
30,075
I forgot about the "and zero". There are
Are you certain that you're supposed to just decode prime numbers, as opposed to designing a counter whose count sequence is the prime numbers less than or equal to 19?
I wondered the same thing.

This would be easier to do if the counter output was only prime numbers of interest (and zero).
The decoder would possibly be easier since instead of decoding to a 5-bit prime number it could decode either to BCD (though a custom counter could do the same thing and it requires the same number of bits in this case) or to the display signals directly. Part of it depends on if they get to use a BCD-7SEG decoder.

How can you use a 3 bit counter to generate prime numbers less than 20?
I had forgotten about the need to include zero. So that means that there are nine states and thus a 3-bit counter won't work.
 
Top