Is binary counter Spice model available?

Hello everyone!
I got a project on the university to make a electronic simulation on Raspberry pi with a specific circuit. I’m using Kicad. In my opinion this is a very nice software, but i need some digital components in the simulation.
I can’t find any binary counter IC on the internet, which is working with the simulation.
I found D flip flop and i decided to make one myself, but i failed and it is really unstable.
My question is: Do anyone know where can i find spice model for a binary counter that’s working with the Kicad Spice simulation?
I really appreciate any little piece of advice. Thank you very much!
Best regards!

Does the simulator have to be connected to Kicad or are you willing to enter the schematic in another program? Is your circuit digital or mixed? There are digital simulators like logisim, they don’t look at the circuit in an analog way but assume gate logic. And they will run faster too.

1 Like

Thank you for your fast answer!
It does not need to connected to Kicad simulation if it is possible to simulate with other software and get the raw output from that simulation. It is just need to be simulated and later i have to work with the simulated output raw data ( for example voltage values). It is mixed :frowning: . My circuit has resistors,MOSFET, and i need a binary counter. I have read about Logisim, but it looks like it is not suitable for this project.

Logisim is pure digital. If your mosfet is just used as a switch then there should not be a problem using it (for example if your counter is just used as the basis of a state machine and the mosfet is just the activation of some output).

If you however have a mixed signal system (example if your counter is the basis of an ADC) then you will need a true simulator. However you might want to ask yourself if you really want the model of your counter or if it might be better to define a different interface and have the simulator activate whatever the counter activates (we can not give more advice here without further details about your project).

1 Like

Thank you for the reply!
I’m going to try explain my project. So i have to run a electronic circuit simulation on Raspberry Pi with a specific circuit ( see the shematic picture!). But i have to build this circuit in the real life as well, and meanwhile i’m reading out the measured voltage from the simulation, i’m reading the real life voltage on the circuit i have built with the Raspberry Pi GPIO. And i’m comparing the measure voltage. If it is close to each other then it is good, if it is not, then the raspberry pi make some alert to the user. I have searched a lot on the internet and i have found Kicad. It is a mixed Simulator. I think it’s perfect for me. It can run on linux and CAN run on Raspberry Pi. I know it is not primarily for the simulation, but it has very good interface with the ngspice. I tought it’ll be a piece of cake! But then i realized i need Spice models for the simulation and i dont find any digital counter. Then i found Spice models for D flip-flop and NAND gates, and i tought i’ll be make a counter for myself with D flip-flops but i failed (See the Simulation picture) and it is very unstable and i don’t know what could be the problem, so i tought the model is not perfect, but maybe I’m wrong and i made a mistake. (Hope this is the case!!) .
Anyway i’m stucked and i don’t know what to do. I need to simulate a Stair-Step generator with binary counter and i dont find any counter for Spice model. I need only the Simulation part from the Kicad i don’t need any PCB design or something like that.
Sorry for mispelling or misunderstanding. Ask what you can’t understand and i’ll try to explain.
English is not my main langauge.
Best Regards!

Schematic

Sorry i could only upload one image per message.
This is the measured voltages. The CLK will be in the real life from the Raspberry Pi and I’ll measure the voltage at the voltage divider resistor.
Hope it is understandable.


Simulation

Are you able to upload a ZIP of the project files so we can take a look? Or does it not let you because you’re a new user to the forum?

1 Like

Should be able too now.

2 Likes

With 3 bits there are 8 combinations of input voltage at the outputs of the counter. Can you not run the simulation with those 8 combinations in sequence?

1 Like

That’s what he’s trying to do. The stairstep is the “DAC-ed” output of those 3-bits, but he’s getting inconsistencies and at least one step is missing in each cycle through the counter. There’s so much that can go wrong here, I think it’s safer if we looked at the project in its entirety.

1 Like

Attached you will find a 3-bit up/down counter as a subcircuit. The counter is made by an XSPICE state machine (ngspice manual chpt. 12.4.18). The internal event nodes are translated to analog inputs and outputs.The circuit in the *.cir file will run with standard ngspice. The subcircuit may be attached to an appropriate KiCAD symbol which has clock and up/down inputs and three outputs.

state-machine-3b-count.cir (1.2 KB) state-3bit-count.in (537 Bytes)

2 Likes

OP, is it a requirement of the course or something that you show a simulation run with a graph or do you just need the 8 resulting values at the node indicated? Seems like something you could work out by hand for the 8 combinations, or use a spreadsheet.

1 Like

You should search for a circuit diagram of a synchronous counter.

You are running your counter asynchronously, which heavily depends on internal delay times and may deliver unexpected results, if not done very carefully.

1 Like

The 8 combinations would also be easily simulated just with 3 rectangle sources of differing period (1,2,4). No need to use counters as the input for that.

And then one can check the digitial side separately if it gives the expected output sequence on a given input. That is kind of what i hinted at above. If one divides systems into multiple subsystems with defined interfaces then one can look at each subsystem in isolation. This makes an iterative development process a lot more viable.

1 Like

Hello!
Thank you for your answer. Yes i attached the whole project what i can managed to do until this. I’m beginner at Kicad but you are very helpful thank you for thatPresentation.zip|attachment (5.3 KB)
Best regards!

Hello!
Thank you very much! I’ll look into that and try to run it with ngspice!

Hello!
No it is not requirement to see it graphically but it would be plus.
I choosed Kicad because it has a very nice GUI for ngspice and i can easily build the circuit and later if i want to change something i can easily change it as well.
Best Regards!

Hello!
Okay i’ll try it with Synchronous counter!
Best regards!

Well if you analyse the circuit with the help of Messrs. Kirchoff, Thévenin and Norton, you can derive a formula for the resulting voltage, using only pencil and paper. Here I cut to the chase and show you the spreadsheet result since you want to see a nice graph.

Edit: fixed an error in formula.

1 Like

WoW!
It looks very nice!
Thank you!