KiCad simulator/ emulator for PIC and other microcontrollers

Good day! I hope this is the correct place to post my suggestion, if not please move it. This is a very good idea that will help both us developers and KiCad.

Currently KiCad is one of the leaders on the market, because its quality is high and its free. Also it supports all operating systems.

I had to setup a few development environments lately and it was necessary to find a good simulator for Microchip devices(PIC16, PIC18 and etc), this prooved to be very hard. It seems the only ones are GPSIM, PicSimLab and Proteus. GPSIM and PicSimLab are not so good, because they are hard to setup or do not provide the functions we need, making Proteus the only real simulator for such devices, but its prices are extremely high.


Don’t be fooled by the 200 Euro option, there is no such option really.
If KiCad makes a sofware with wich we can easily view our device and debug it, this will make you even more popular.

I know that currently NGSPICE is under development, so please consider my idea. To be able to build a virtual board on which to just load the hex file and observe will my device work, including the LCD and others is what we need.

1 Like

I used Proteus in past (my university had the license), it use some kind of .dll files to this kind of models. The last updates (when I used) on MPLab (Microchip) allowed use the PIC simulator within the schematic. But only allow this in schematic environment (do not allow interact with the PCB).

I remember that some models of Proteus allowed interact with the physical COM / LPT or get waveform from a microphone.

I think its depends of https://gitlab.com/kicad/code/kicad/-/issues/2119 and a full definition of how interact with this model files. For example, PSIM (a power electronic simulator) defines that the DLL linked to a symbol must have standard functions names called on: simulation start, simulation step and simulation end.

MultiSIM have a interactive simulation and may have this kind of model.

I am not a developer (just help with reports and tests) but this appear a long shot. It needs more than NGSpice and also more definitions on the symbols (to allow the users to interact in the Eeschema canvas).

@Arak_Rachael, even if take long to emerge, it good to report the idea on https://gitlab.com/kicad/code/kicad/-/issues describing the idea (checking if it’s already there) and list other issues that is need.

2 Likes

In the past I played a bit around with the Proteus demo, and implementing the simulation capabilities into KiCad would be a real game changer. For example, you can simulate a PIC connected to a touchscreen (and a loudspeaker) running chess on it.

I suspect KTechlab is capabilitywise one of the closest OSS solutions at the moment.

At FOSDEM19 I talked with one of the Gnucap devs about adding microcontroller support, and it was considered feasible.

Ngspice has XSPICE support which allows the addition of digital circuits in an event driven manner. Perhaps this is the most feasable approach. Dunno if ngspice can do “realtime” simulation as this would be required to interact with the circuit. The ideal solution would be to support XSPICE devices via python bindings. Things like AVR/PIC simulation could be integrated into the KiCad core via AVRSim/GPSim binding and users can add their own models using Python. Interaction between GUI and XSPICE model could also be coded in Python which would allow interactive schematic symbols.

EDIT: There seems to be a XSPICE library for 8-Bit AVR: https://github.com/mcusim/MCUSim

There is also https://github.com/FabriceSalvaire/PySpice

You might also have a look at https://www.isotel.eu/mixedsim/index.html.

The mayor challenge is to find somebody who is interested in persuing this job.

1 Like

Found in this forum post: https://librepcb.discourse.group/t/simulation-in-librepcb/224

UPDATE:

I tried this project, and it is really nice. I think this is the most comparable OSS solution to Proteus. It uses AVRSim and GPSim in the backend, with apparently some custom written circuit simulation.

Now to the bad things. This is the weirdest Open Source Software I have ever seen. The sources are GPL licensed, but only old ones are available from the website. At least, there is a precompiled AppImages of an old version available. Newer version need to be acquired via Patreon (where you need to pay). The SourceForge Repo seems to be outdated as well. So, It looks like as there is only one dev in the background. No wonder there is a fork on GitHub available: https://github.com/lemonpaul/simulide

1 Like

Thanks for the suggestions! The good thing of Proteus is that you can see how the pins change and whether its what you expect. Its like an all pin osciloscope, also it gives the ability to test your circuit easily. A visual simulator is the future. I am trying with PicSimLab at the moment, which has good documentation. I can not work with GPSIM, its very hard to find out how to build my own circuits.

Another visual style simulator (though I don’t see a way short of screenshots to capture the simulated data) that might be interesting to play with is EveryCircuit. It runs in a browser (they advertise Chrome, I haven’t checked others), and they have apps for Android and iPhone. The working area is small so if you are trying to simulate something large you have to get creative with packing (though they do have a net label functionality that I haven’t played with that feature much). They do have some digital IC types built in (various flipflops, counters, BCD decoders, 7-segment displays, logic gates, etc). If you accidentally over-drive an LED it will show a flame icon over the LED when it blows out in simulation. There are other animations that help visualize how the circuit works, moving ant lines showing hole flow, capacitors indicating charge by + and - circles that get larger with more stored charge, FETs have an indicator for how much they are open or closed, etc.

A simple example of something I did, I wanted to simulate a 3-way light switch with 12VDC toggle switches for a kitchen under-cabinet light system at a previous residence. I kind-of understood the concept, but simulating it in EveryCircuit really helped me understand the current flow with multiple switches.

The free version is limited, but it only costs a 1-time charge of $15 to unlock everything. (I paid that so long ago that I don’t remember what the free limitations are.)

I don’t mean to offend you, but EveryCircuit is worthless, it gives false results, I have tried it before.

Best visual simulation program I play with is falstads circuit simulator, howerver for things like simulation a full blown microcontroller you need a very accurate model of its internals, Or is it closer to you want to cheat, just having a way to say script a sequence on the output / input pins and simulate /log it.,

No offence taken, it isn’t my project. Not having a lot of experience with simulations (and no references to compare against) I didn’t realize it gave false results. I’ve seen some odd results, especially with MOSFETs, but I chalked that up to me not understanding the some of the tuning parameters (for example the width and length), and never bothering to check a datasheet to see if these are parameters that are easy to look up.

Interfacing to https://sourceforge.net/projects/picsim/ perhaps?

PicSimLab is the best option. Its what I am using currently. The only downfall is I can’t create my own circuits or whatch how the pins change. But it works.

Sorry for the double post.

I will try falstad.

An emulator or a simulator is good too. If KiCad makes these sim dlls like Proteus it will be great.

Something tells me you don’t have a lot of experience with either circuit design or embedded development. Visual simulator is a pretty toy, not something needed desperately. Just follow normal software development best practices and you’ll be fine.

I don’t think so, because how many people do you know who write unit/system-test for embedded sofware (non-linux systems)? Having proper simulation of the MCU as well as their peripherie would allow this quite easily.

For now I only know https://platformio.org/ which would have unit-testing capabilities integrated (but no perepherie simulation).

I knew a programmer that got a job on large industrial machines. His code had a problem so he started to step through the code to debug it, all the while charging a very large capacitor. Shock and awe ensued. :smiley:

professionals doing embedded development do so. perhaps not the arduino jockeys.

There will never be accurate enough and widespread enough coverage for this to be more than a toy. Even if it worked, you would still need to do proper testing with your real hardware.

professionals doing embedded development do so. perhaps not the arduino jockeys.

I’m not an EE, but an Software guy with some EE experience. Could you elaborate how testing in embedded development typically looks like. I did an internship on a company developing embedded Linux systems, and the amount of automated testing was exactly zero.

How many companies really have a proper hardware-abstraction layer to allow software only verification, or regularly run Hardware-in-the-loop simulation?

I am the opposite: EE with some software experience.
Beyond the educational propose, I think that @halachal want to say is that is not common to create a elaborate unit/system test script/enviroment for project with small CPUs. At least, it was not common in the companies that I worked (doing message displays, score borad for games, and other projects based on PIC/8051 plus few ICs: memory, logic and so on).