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 . 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).
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!
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?
Should be able too now.
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?
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.
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)
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.
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.
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.
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 that (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.
WoW!
It looks very nice!
Thank you!
Hey, Daniel. I looked at your project and it seems like what @holger stated above is indeed the issue. Not only is this true, but the D-FlipFlop subciruit you found (link here) is using default-parameter BSIM3 MOSFETs to produce the logic gates inside. I can see a bunch of problems with those kinds of NAND gates connected in the criss-cross pattern required to produce a flip-flop. I can get it to run stable in a different simulator, but the edges are very messy so something is definitely wrong here.
I suggest using the behavioral model @holger posted above. Like he said, you need to create a symbol to utilize his .subckt
model within your project. Based on your initial project, it seems like you have a good handle on how to navigate the nuances of KiCad simulation so I think this will also be something you can figure out without too much hand-holding. HINT: the first step is to extract his .subckt
/ .ends
section into its own .LIB file to reference and use with your symbol.
Also, what physical IC are you planning on using for the counter and also what is the part# for the MOSFET you want to use? The way your MOSFET is connected is going to depend heavily on its threshold voltage. Therefore, the specific part is important and you would need to find an exact model for it so your simulation output matches closer to the real life output. Alternatively, may I suggest connecting the output like this instead?
The output will switch between 3.3V and 1.65V. If you need it to switch between 0V and 1.65V then you need to do something similar, but with a P-channel MOSFET. This configuration is less dependent on threshold voltage and you won’t get much of your output swing within the MOSFET’s linear region of operation. Please ignore these comments if I’m not correctly assuming what you’re trying to acheive on the output.
Finally, a couple general suggestions.
1.) Define the rise and fall times for your voltage pulse sources. Don’t leave them at 0.
2.) If you’re primarily doing simulation, use “meg” instead of M on your schematic so you don’t have to keep checking the box in the simulator to auto-fix it for you.
3.) Be careful with your voltages. You’re powering your counter with 3.3V, but your clock source is 5V. The simulator won’t show any errors or smoke coming out of your counter, but you will likely smell it in real life!