Wednesday, September 27, 2017

Die-Ode !!!

Tuesdays are definitely more optimistic than Mondays, welcome to the 2/7th week.

With simulation of linear circuits going strong, the challenge was to tackle non-linear circuits. I started off with the diode since my intention was to use the Ebers-Moll model for the transistor which incorporates two diodes. The simplest circuit to understand the approach is as follows
                                         Image result for diode resistor circuit      

In the above figure, we have a voltage source Vs, a load R and a diode with a certain knee voltage Vd. The diode current is modelled by Shockley equation as shown below.
Image result for shockley equation
                                               

With Diodes, we have two types of possible approaches. The first is the small signal AC analysis where the AC fluctuations about the DC offset is small enough to warrant the assumption that the diode conductance does not vary. This implies that the diode can pretty much be treated as a resistor in small signal AC analysis with the resistance value being calculated from the slope at the DC bias point. The second being large signal wherein the DC operating point of the diode changes significantly and hence the diode conductance varies non-linearly. The second case subsumes the first and the first case is used only to improve the efficiency of the simulation. I proceeded with using the second case(works for all configurations) since I wasn't too bogged up about efficiency at the initial stages.

If one were to compute the diode drop and hence the diode current by hand. We would have proceeded with load line analysis, where the intersection of the load line and the diode I-V curve gives the DC bias point. However, the computer cannot figure it out graphically hence there is a need to express this method in mathematical form and that's where Newton-Raphson comes into the picture. The essence of the program is to first assume a diode drop(the knee voltage is a good assumption since if the diode is forward biased, the voltage across it hardly changes beyond the knee) using this drop the diode current is computed from the Shockley equation. This gives us a point on the diode I-V curve which we name (v1,i1). The tangent to the curve at this point meets the load line at another point which we name (v2,i2).

Image result for load line
Courtesy of Wikipedia
                                           

If we have found the DC bias point then the two points should coincide otherwise the distance between them tells us how far off we are from the true diode drop. We are essentially finding the zero point of this function that accounts for the distance between the points by using Newton-Raphson. Newton-Raphson gives us a way to update our assumed diode drop to proceed with the next iteration until the distance is less than a certain acceptable value. So, at the end of the day I had the diode working for a DC source


For the purpose of verifying, I have taken Vs=10V, R=500Ohms and n*vT=0.039V. The simulation converges to the diode drop being 0.831V and the diode current being 18.34mA. This can be verified from Boylestad which uses the same example. So, at the end of day two we have diodes working with DC sources

I'll have one cup of Java and three full course meals please

Welcome again, to another fantabulous 1/7th of a week.

                                           Image result for drinking tea

"As the day awakens with the crowing of the rooster,
And the simple minded folk begin to till their land,
I'm starting to ponder which language is chaster,
Java, C++ or C Borland "

With that out of the way lets begin. My primary choices were Java and C++ to exploit OOPS since a lot of components in electronics share common traits. Between Java and C++, I opted for Java since I am more comfortable with handling GUI in Java than in C++. I was apprehensive about Java's performance since these design environments usually involve thousands of iterations with matrices in the order of hundreds. My first intention was to implement the basic graphing requirements and GUI in Java and then the computationally expensive portions in C++ or Julia but decided against it for two reasons. Firstly, Julia's benchmarking page shows that Java is comparable to Julia. Secondly, most importantly, any JNI pipes to C++ would create a bottleneck since enormous amounts of data will have to be passed in and out of this pipe with each iteration. Its better to profile and optimize the Java code than transfer the complexity to other languages for arguably minor improvements.

The first problem to tackle was that of assigning ID to each node. With large circuits this could take quite sometime if done at the end of connecting the components which is why I decided to do it on the go. Every time a connection is made to a node, its assigned the same ID if any of its neighbors
have already been assigned an ID and a new ID if none have been assigned. The GND node can be arbitrarily chosen just before the simulation begins. With the mapping done, the next issue was to tackle MNA. For this purpose there was a need to construct a Hashmap, mapping every node assigned a certain ID as it becomes a lot easier to implement the simulation.  I had initially used images from flaticon for the various components, however they don't take well to scaling which is direly required as the circuits get bigger. This was subsequently replaced by manual painting. At the end of the day, simple linear circuits could be solved with DC and AC sources.



The Why, the What and the How?

Hello World! Great to see you again. My recent challenge was to build a circuit design environment in a week and this blog documents how I went about doing it. I first thought about it when I started my undergrad and had no idea I would have the honor of attempting to build one soon enough. Firstly, there are tools that would definitely make your life easier but unless you understand them there is no point in using them, which is why I have written this library(if you can call it that) stand-alone, free from any other projects(Licensing is a pain, we are coders right not patent freaks!).Lets begin.


The Why


Frankly speaking, other than the sheer curiosity to see whether I can do it, I have really have none. This project encompasses literally everything I have read so far in my undergrad. Right from Network Analysis, Graphs, Signal Processing, Electronic System Design, Analog Circuits, Algorithms and many more.... Its a project that gives you the satisfaction of climbing a peak and looking back as a tribute to your undergrad days. As you look down you see where the each piece in the puzzle fits and the Ah! moment at that instant is definitely worth grueling for.

                                 



The What


The need for circuit design software/simulation arises when the complexity of the circuits becomes too large for most! human beings to solve by hand. It greatly reduces the time needed for designing products, which is why a lot of companies have invested in it. Circuit simulation can broadly be divided into time domain and frequency domain simulations. The time domain simulation is easier when non-linear circuits are considered since non-linearities are easier to model in time domain than in frequency domain. However, if high-Q circuits typically having responses limited to very narrow frequencies are to be analyzed, a frequency domain simulation greatly improves the efficiency and time taken to complete the analysis. Typically, for microwave circuits where the relative permittivity of the substrate is modelled as a function of frequency(dispersion models), frequency domain simulation is  the only option for the most part. For all these reasons, I decided to implement both the time and frequency domain analysis. 

The How?


Well, hence the Blog, sit back and buckle up.

                                    Image result for cipher matrix sit back and buckle up