Digital simulation

How to design a simple full adder in kicad nightly builds 5.I am not able to correctly get waveform for any digital circuit.Can anyone post a digital circuit which works in Kicad nightly builds

Have you thought about learning how to do it yourself? It would be much more useful in the long run, whether you are doing coursework, professional work, or DIY.

You wonā€™t be able to rely on otherā€™s doing your work for you for your whole life.

I have tried to do it myself I am not able to get the right results.


I tried simulating a half adder circuit but I am getting this error can you tell me how to fix this error

For digital simulation, KiCad is not the right tool.
I recommend Logisim http://www.cburch.com/logisim/

3 Likes

Yesterday it was a flip-flop, did you ever get that to work?

Iā€™m no expert in spice simulation, but my understanding is it is primarily an analog simulation. I know, one can argue that everything is analog but there are some tools for digital analysis that just donā€™t exist in analog simulation. That being said, the spice integration in KiCad is a very new addition and not many of us have any experience with using/playing with it. Also, I really donā€™t know how much of the library have spice models integrated. Our librarians are all volunteers.

At first brush, I think you have problems with your schematic. You appear to be wanting to use 3 gates of 2 chips, yet you have 4 chips referenced (U1, U2, U3, and U4). Your XOR on U1 looks good (first gate is U1A and the power block as U1E, all makes sense). But your NAND is split across 3 references. U2 and U4 arenā€™t being powered. U3 is being powered, but none of its gates are being used. Try consolidating all down to U2 by leaving U2A as is, change U4A to U2B, and change U3E to U2E.

Iā€™m looking at the fatal error ā€œvu4 is a shorted VSRCā€. I really donā€™t know what that means, but it seems to indicate a voltage for U4 is causing problems with Voltage Source. (Or I could be way wrongā€¦) Maybe fixing your refā€™ds would clear that issue.

Also, note all the warnings ā€œUnable to find definition of model - default assumedā€. This spice integration is new, maybe the default has problems? I think you really need to find a Spice Wizard. I think there are a couple here, but I donā€™t know if they are monitoring this thread.

Also, please remember that this forum is a community forum. We are all just users trying to help each other out.

1 Like

Iā€™m not inclined to someones coursework, but the question piques my interest and provides an opportunity to learn something useful. I am building a clock from relays, and in order to create and verify the design before committing to copper I used logisim. I am pleased that the 7 segment decoder worked first time. I also wrote my own simple digital simulator to simulate a 4 bit binary counter, which can read a KiCad schematic and simulate relays and logic gates. That was really useful, and I only needed a couple of wires to fix bugs in the design (parts I had not fully simulated).

Anyway, as mentioned pspice needs models before it can simulate, and AFAIK only parts in pspice.lib can be used out of the box, there are models for ā€œsimpleā€ parts such as resistors, transistors, switches. For the logic gates in 74xx.lib or cmos.lib you will need to find or create suitable models.

All gates can be created used pspice basic models, and these can be easily found on the we. E.g. from Wikipedia, a NOT gate:
image

That should be simple enough to create in KiCad pspice version. Exercise left to reader.

1 Like

A complete digital clock using only relays? (And 7-segment displays of course)

And a lot of diodesā€¦so not entirely purist. Iā€™m also lacking an ā€œauthenticā€ electro-mechanical oscillator and display section, so really itā€™s just digital counter/decoder so far. The circuit is inspired by Simon Winderā€™s flip flop design : http://simonwinder.com/projects/relay-calculating-engine/

So far I have prototyped a single 4 bit counter and display. The counter has a configurable reset from 1-15, so I will use the same board for 6 digits HHMMSS. It needs an external pulse per second clock, and some simple logic to reset at 11:59:59

Obviously using relays is daft, but I got a reel of 900 from a dumpster! Iā€™m calling it an ā€œart projectā€ :slight_smile:

3 Likes

Watch out for a repetition of the original computer bug. Maybe moth balls, or a cedar enclosure would help avoid bugs. :laughing:

1 Like

Interesting flip flop design, now I see why the diodes, and that square root calculator is fascinating. I could watch it calculate root 2 for hours. :nerd_face: And I like that old rotary phone dialer as an input device.

A relay version of an astable multivibrator?

I donā€™t know if I would call it daft, impractical maybe but then, as you say, itā€™s a form of art. I think there is sometimes more satisfaction from building such projects. Building a clock with a processor or even discrete logic doesnā€™t seem like such a big deal, itā€™s expected to work. But something like a clock or calculator from relays is just fascinating that it works at all. :slightly_smiling_face:

Edit: And your clock might even end up having a ā€œtic-tocā€ like sound. :wink:

Edit2: I think Ben Eaterā€™s microprocessor is just as daft and impractical but still an interesting project and quite educational. Not sure if it is as ā€œartisticā€ though. I was going to build a more capable version of it but on a PCB.(I just donā€™t have the patience anymore to wire something like that up on breadboard)

1 Like

We have to look at the error messages of ngspice:

Error on line 7:
U1 ip1 ip2 ... 74hc86
Unable to find definition ...

The gate U1 is translated by Eeschema into the ngspice input line shown above. This is simply wrong. A ngspice line beginning with U is the definition of a ā€˜Uniform Distributed RC lineā€™, for shure something the author did not intend.

...
Error on line 11:
vu2 ip1 ip2 ... 7400
...

Here Eeschema has decided to tranlate the gate u2 into a voltage source beginning the line with v.

One reason might be that ngspice-27 does not allow ā€˜-ā€™ in node names. This has changed with the recent ngspice-28.

Gates, opamps, and other circuits added by including libraries have their contents as subcircuits. These require an x at the beginning of the instance line, e.g. XU1 ā€¦ in ngspice.

A first action might be to rename U::: into Xā€¦
Another might be to avoid the ā€˜-ā€™ in all net names.

In the examples coming with eeschema, e.g. laser_driver, the opamp is also named by U1. So there has to be another method for name translation inside of Eeschema.

Finally the KiCad maintainers should switch to ngspice-28 as soon as possible.

Unfortunately I am not firm using KiCad, so cannot be of much further help.

I had hoped to show a more complex example, but I struggled to get even a single MOSFET working. Anyway, here is a NOT gate:

and here is the simulation:

Some notes:

  1. Simple components (R, C) are handled ok.
  2. Diodes need to have pins swapped to work correctly.
  3. There are BJT and MOSFET devices in pspice.lib, but these donā€™t work out of the box (model not found).
  4. V1 shows as sine generator on the schematic, but in fact it generates a pulse. The settings in Edit Spice Model override, the value field.
  5. I downloaded the model for the MOSFET from http://www.st.com/en/power-transistors/stn2nf10.html. It is implemented as a subcircuit.
  6. There are lots of PSPICE and other variants of models around, but these may not be compatible with ngspice.
  7. Overall, there are many ā€œautomagicā€ stuff going which is really hard to guess, and there are some pitfalls I havenā€™t mentioned.

If you are familiar with ngspice or pspice, then the KiCad simulator is easy enough to guess how to use. If you are not familiar with simulations such as pspice, ngspice, then itā€™s a pretty steep learning curve.

1 Like

Simple direct CMOS NAND gate

Paul

If wondering if it loads in KiCADā€¦

yes, perfectly fine
COMBINATIONS are countless

Paul

Paul ,thank you very much for the nand gate.Could you send a picture of the schematic and the librariries you have used to design the nand gate.Also can you tell me how to design d flip flop in Kicad nightly builds .
Thank you

I dropped this in 3 minutes. just to post a ā€œdraftā€

DIGITAL LOGIC in spice is very tricky.

There are already ALL LIBS you need defined
The whole 74xxx logic indeed as well as CMOS counterparts

If you download LTSPICE you should have some good models
for TTL logic gates and a bit more stuff to start yoursā€¦

To use these models is FAR BEYOND a simple explanation here
once you have to mention ā€œBEHAVIORALā€ models in spice3

Mixed models are even more tricky
e.g you CAN NOT DEFINE an analog clock altogether a digital one

The digital clock is entirely BEHAVIORAL.

This simple draft is WITHOUT the BEHAVIORAL models
once KiCAD is not ready for such elaborated models

Analog gates can be defined just like this one
put that into a SUBCKT and you are almost ready

My simple draft looks just like soā€¦ just for fun

And BTW ALL FLIP-FLOPS are defined already
as BEHAVIORAL models in SPICE3F - CODMODEL ā€œdigitalā€

Nobody needs to reinvent the wheelā€¦
Have fun!
Paul

1 Like

ONE more bitā€¦

If you carefully inspect this 3 minute draft ā€¦

You will see that the ā€œsymbolsā€ donā€™t matter
As long as the proper spice directive is OK you may use other symbols

This is a much better implementation
I have fixed the symbols to match the models
(I have a script which roughly converts a spice into a 10mil grid kicad.sch )

This is far better and accurate start. :slight_smile:

This is more proper than the other 3 minute ā€¦
indeed in took 10 minutes to do all that
HAVE FUN
Paul

1 Like

The latest corrected draft was built using
a SPICE input with all gates defined

That draft RUN should look like soā€¦

You should be able to achieve that ā€¦ with some tweaking
Paul

FYI 10 minutes after thisā€¦

I decided to GLUE all gates into a GENERIC SPICE GATE LIB

The result is a simple GATE DRIVEN SPICE library and model
with just that very same MOSFET based CMOS gates.

3 gates are required to derive all others.

Library already done - called that dspice.lib

Paul

1 Like