Author Topic: HDL code for positive edge triggered J-K flip-flop with preset and clear  (Read 2129 times)

0 Members and 1 Guest are viewing this topic.

Offline caiusTopic starter

  • Regular Contributor
  • *
  • Posts: 150
  • Country: it
    • Caius Arcade Repairs & Engineering
Hi all,
I' new to HDL and I'm not yet able to write my own code so I'm using block diagram/schematics under Quartus II.I'm looking for Verilog code (I prefer this over VHDL) to implement TTL gates .I need code for a positive edge triggered J-K flip-flop with preset, clear and complementary outputs (like the 74LS109 for example).Can some one help me?Thanks in advance!
 

Offline cruff

  • Regular Contributor
  • *
  • Posts: 67
  • Country: us
Try searching for "verilog jk flip flop" and I expect you will have your pick of examples.
 

Offline caiusTopic starter

  • Regular Contributor
  • *
  • Posts: 150
  • Country: it
    • Caius Arcade Repairs & Engineering
I did many searches but found only example of JK flip flop with no preset.As aid, I need something like the 74LS019.
 

Offline AndyC_772

  • Super Contributor
  • ***
  • Posts: 4206
  • Country: gb
  • Professional design engineer
    • Cawte Engineering | Reliable Electronics
I speak VHDL, not Verilog, so I'm afraid I can't help with your example - but...

All too often I see people trying to learn a hardware description language by coding individual logic functions, then trying to build those up into a model of the circuit they actually want - like you'd have to do if you were restricted to building your circuit using off-the-shelf components.

I've seen examples that show ridiculously simple logic - like, say, a single OR gate - and wrap it up in a process or even a whole component, then instantiate it at a higher level in order to actually use it. This is kind of OK as a way to demonstrate the syntax of the language, but as a way to learn how to really use HDL, it's terribly misleading.

The beauty of an FPGA is that you can describe the behaviour you want without having to worry about how that behaviour might, possibly, be realised using off-the-shelf logic gates. If you're following a tutorial or worked example which does spend more than a trivial amount of time creating complex circuits this way, I'd advise you to look elsewhere. Don't ever get into the mind set of building real circuits directly from these traditional building blocks; that's the job of the synthesis tool, not you.
 
The following users thanked this post: WattsThat

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9885
  • Country: us
First you need the Truth Table for a JK flop with Preset
https://electronicsarea.com/jk-flip-flop-preset-clear-inputs-truth-table/
Pay very close attention to the effect of the asynchronous Preset and Clear inputs.

At page 6, there is a VHDL description for a JK flop with Preset
https://web.nmsu.edu/~tturner5/courses/et398/files/reports/TurnerET398Lab6.pdf

On page 7 there is code for the flop.  Note how the asynchronous Preset and Clear inputs are handled in the process before the clocking is even considered.  These asynchronous inputs mask out any transition change that might occur from the J and K inputs and the clock.

I don't use Verilog so transmorgifying from VHDL to Verilog is on you.
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9885
  • Country: us
Here's a video of a Xilinx ISE Verilog project including simulation for a J-K flop with asynchronous Clear.  Adding asynchronous Preset is trivial.


 

Offline caiusTopic starter

  • Regular Contributor
  • *
  • Posts: 150
  • Country: it
    • Caius Arcade Repairs & Engineering
Thank for replies, guys.I wonder if there is some kind of library for 74 TTLs in Verilog (or VHDL, I don't dislike it).
 

Offline emece67

  • Frequent Contributor
  • **
  • !
  • Posts: 614
  • Country: 00
« Last Edit: August 19, 2022, 05:56:36 pm by emece67 »
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14230
  • Country: fr
Question of course is: why would you implement basic logic gates and flip-flops in HDL? Other than as an exercise? (Which I suppose it is...)

Except for very particular cases, implementing such low-level logic in HDL is a pretty inefficient way of using a HDL. Just saying.
 

Online BrianHG

  • Super Contributor
  • ***
  • Posts: 7638
  • Country: ca
The OP never specified that the preset and clear need to be asynchronous.

Keeping things synchronous in the FPGA keep the design timing very predictable unless you specifically know your fitter will be using hardware async preset and clear within the logic cells.
 

Offline langwadt

  • Super Contributor
  • ***
  • Posts: 4384
  • Country: dk
Question of course is: why would you implement basic logic gates and flip-flops in HDL? Other than as an exercise? (Which I suppose it is...)

Except for very particular cases, implementing such low-level logic in HDL is a pretty inefficient way of using a HDL. Just saying.

not only inefficient, that kind of async logic is also a bad match for an FPGA
 

Offline NorthGuy

  • Super Contributor
  • ***
  • Posts: 3136
  • Country: ca
You can build something from logic ICs and there are many of them that you can use.

FPGA is built the same way, it has blocks and interconnect. You connect the blocks pretty much the same way as you would connect logic ICs, except blocks are different - you won't fond JK flip-flops in FPGA, but you will find LUTs for example. There's some overlap - for example, D flip flops are present both in FPGA and logic IC series.

If you use logic ICs, it will never occur to you to build a LUT because you can use various ready-made gates instead.

Similarly, if you use FPGA, there's no point in building JK flip flops, because it's better to use resources which are already present in FPGA.

FPGA is actually much easier than logic ICs - the variety of blocks is not anywhere close to the variety of logic ICs and the blocks are more configurable. Not to mention the tools will build circuits for you.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf