Circuit Simulator
Total Page:16
File Type:pdf, Size:1020Kb
Circuit Simulator Aaron H. Graber, Computer Engineering Project Advisor: Dr. Anthony Richardson March 27, 2017 Evansville, Indiana Table of Contents I. Introduction II. Problem Statement III. Project Design A. Design – GUI B. Design – Controller Class C. Design – Circuit Class D. Design – FileUtility E. Design – Constraints F. Design – Costs G. Design – Standards IV. Results V. Conclusion List of Figures 1. GUI example 2. Starting the program 3. FXML Functional Methods 4. TreeItem example 5. Class Structure 6. Drawing example 7. Dialog example 8. Dialog Result Conversion 9. Class Differentiation 10. Parsing through the input file 11. Checking for intersections 12. Circuit with SPICE translation 13. Setting the Current Working Directory (CWD) 14. FileChooser Dialog 15. FileChooser Opening the Dialog 16. Text file format 17. LTSpice example circuit 18. LTSpice example circuit output 19. Program circuit output I. Introduction In the area of circuits and electronics, not every hardware design is going to work as first thought. Mistakes are possible and other unforeseeable results may arise, especially for those still learning the profession. For this reason, circuit simulators where created to get theoretical results and see how the circuit behaves. For the design of this project it was split into several user defined classes to create a working product. First off, the graphical user interface allows the user to create custom defined circuit, and also implements an open/save feature allowing the user to save their work. Another feature is that the program executes a SPICE interpreter to allow the user to view the theoretical results of the circuit they created. Overall, this project allows the user to simulate any circuit that is created with this program. II. Problem Statement Overall this project is meant to be a free, open source, cross platform, graphically focused, EDA tool suite. Basically, it is going to be a circuit simulator that lets you build the circuits with visual components. There are many quality circuit simulators available and the one that is favored by most of the professors at the University of Evansville is LTSpice [1]. Hopefully this project will produce a program that can compare to how smooth LTSpice operates and how well it performs circuit simulation. However, LTSpice isn’t completely user friendly and it is necessary to know the ins and outs of the program to preform even transient analysis, and there are many features that are hidden underneath the surface. This is one of the main reasons why there is a need to create an easy to use circuit simulator that also spans several operating systems. Listed below were some features that had been planned for the program. However, due to some time constraints some of them remain to be unimplemented. • “Workspace” or area where circuit components can be placed for the user • Toolbox, list of all the components that are currently implemented in the program • Interpreter for the SPICE language[4] so that circuit analysis can be completed and values can be calculated • Graphical charts for the data • Ability to port in spice netlists for the SPICE language[4] to add in more components • Port the program to Linux and Mac OS systems • Self-explanatory GUI III. Project Design The design of this project is split into a multitude of pieces to simplify the process of programming everything. The main pieces are split into several main groups; the GUI or graphical user interface, the circuit workspace, file input and output, the creation of SPICE files, and the execution of and results from the SPICE file. The project was created in Intellij Idea by Jet Brains, which is a Java IDE. Intellij allows JavaFX projects to be created which is software platform for creating desktop applications and is basically the standard GUI library for Java SE [2]. A. Design - GUI The GUI was created as a .fxml file in an extension to Intellij called JavaFX Scene Builder. This application allows GUI components to be dragged and dropped so the user can create their own custom GUI easily. Figure 1 shows what the GUI looks like in the Scene Builder designer. In Scene Builder, the different components of the GUI can be named, properties can be changed, events can be created, and the overall layout can be easily changed. So as Figure 1 GUI example figure 1 shows, the current GUI has a menu at the top, a toolbar beneath that, a tabbed pane under the toolbar, and on the right, is a blank rectangle that will later hold all the components. All of this occurs in the .fxml file and none of it must be programmed; however, all GUI events, like a button press, must be entered later as a function. These event functions are linked to the .fxml file. The GUI portion is broken down into two main classes; the main class and a controller class. The main class starts the program, initializes the controller and then the program begins. To get the program to run the .fxml file that was setup, a couple of steps must be taken first. From figure 2 several obvious things can be pointed out. First, the main function gets overridden by the JavaFX function called start. Then from the start function, the .fxml file can be loaded and imprinted onto the stage so that the correct scene can be shown. The controller is where all the .fxml objects are initialized and where all the methods are. The majority of the code in this project lies in the controller portion of the project. B. Design – Controller Class Next, the controller holds all the components and events that were created Figure 2 Starting the program in the scene builder application. So any button, label, text field, or any other GUI peice are all initialized here. As per the JavaFX standard, the controller class must have an overridden function called initialize, which gets launched once main is finished. It is in this initialize function where the current working directory is set, where the circuit grid is created, and where the component listening on the right side of the GUI is filled with current components. Also, all global data structures are initialized. The methods or events that are created in the scene builder must have special methods as figure 3 shows. These functions act as listening events and run for a certain case. Figure 3 FXML Function Methods For example, if the delete button was pressed on the GUI, then the program would interrupt and jump into the btnDelete_Pressed function shown in figure 3 and given a button click event as a parameter. The @FXML acts just like the @Override shown in figure 2 and is a standard for JavaFX to show that this function connects to the .fxml file. There are similar functions to handle all button clicks, any dragging and dropping, or other misc. user interface options that would normally be available. Next the list of components that would be available to the user would have to be created. To create that list a Java type called TreeItem was used, which acts a lot like a kind of tree data structure as an example is shown in figure 4. A root must be created which then creates subfolders like “Basic Figure 4 TreeItem example Components” or “Sources” where in these folders are other TreeItems that contain circuit components that can be selected and dragged by the mouse and dropped onto the circuit pane. To allow the dragging and dropping functionality five functions were created. Four of them are for detecting a mouse event and differentiating between a click event and a drag mouse event. The last function is for a mouse drag release over the circuit pane, which gets the x and y coordinates of the mouse, makes sure that the point gets translated to a certain point, in this case its every 10th pixel in both the x and y directions, and then adds the selected component to the circuit. The circuit is a whole class system and will be discussed in detail later. Moving on, there are a total of four button functions in the controller class. The first is the event listener for the analysis button. Pressing the analysis button brings up a sub controller class which loads another .fxml file containing the GUI for the analysis window. This window allows the user to select what type of analysis they want the circuit to have along with certain parameters, like start and stop time. Once the run button is pressed then it gets a series of commands from the file utility, creates a separate process, and then calls a system command called exec and runs the list of commands that it is given. After the system call ngspice is opened with a loaded user created circuit, this will be discussed in much more detail later. The next function concerns the delete button, which upon being pressed it listens until the primary mouse button is pressed, which at default is the right mouse button. Once the mouse is clicked it gets the target, differentiates it between a wire and an actual circuit component then attempts to remove the part from the pane and remove it from any data structure that it may also be in. Even after a component is clicked it will continue to delete parts that the mouse clicks on until the secondary mouse button is clicked. The last button event deals with the wire button. When the wire button is pressed the dragging, and dropping methods mentioned previously are recreated for the circuit pane so that wire can be custom made to how the user wants them.