Drawing the Analog to Digital Line in LTSPICE, Part 1 - Printable Version +- Discussions (https://lawsonlabs.com/bboard) +-- Forum: Lawson Labs Products (https://lawsonlabs.com/bboard/forumdisplay.php?fid=1) +--- Forum: Start Here (https://lawsonlabs.com/bboard/forumdisplay.php?fid=2) +--- Thread: Drawing the Analog to Digital Line in LTSPICE, Part 1 (/showthread.php?tid=15) |
Drawing the Analog to Digital Line in LTSPICE, Part 1 - Tom - 02-22-2021 Having given some thought to the somewhat fuzzy distinction between the analog and digital realms, let's use SPICE to better visualize the transition. First, here in part 1, we will start from the digital side, and move toward increasingly analog. A simple sine function in a SPICE behavioral provides the point of departure. The idea is to split the waveform into an increasing number of discrete steps. The SPICE variable time provides the steadily increasing value. V = sin(time) in a behavioral produces the familiar sine waveform, +/- 1 volt, centered on zero volts. The number of discrete steps we will divide the waveform into must be an integer. The expression int(time) accomplishes that task via the truncation offered by the integer function. If the integer number of steps for a one volt sine wavel is 2, a digital representation of the sine function would be zero, plus 0.5, zero, minus .5, zero, etc. As the integer number of steps increases, the sine function smooths out, until eventually, it looks entirely analog. The whole expression would fit into a single SPICE behavioral except that time keeps advancing. We multiply by time, truncate and then divide by time. If time changes during the process, it would create artifact. So, we need two SPICE behaviorals, one for the time, t, and one for the waveform, aatodd, indicating an attenuated A to D conversion. [attachment=42] Fig. 1 The formula for t results in an integer, starting with one, and counting up a tick every ten seconds. The formula for aatodd multiplies the sine times that integer, truncates the result, and then divides by that same integer. The .tran statement below defines the SPICE run - transient analysis from 0 to 1500 seconds, with a maximum timestep of 200us. [attachment=41] Fig. 2 Above is the first 80 seconds of the output. The maximum truncated value goes from nothing, to 1/2, to 2/3, to 3/4, etc, as the number of steps increases. By 80 seconds elapsed, there are 7 steps on the positive side, and seven steps on the negative, and the maximum value is 7/8. That might be called a “3 bit plus sign” A/D converter. [attachment=43] Fig. 3 By 1000 seconds out, value t is 100, so there are 100 steps for each polarity. We are still short of 8 bits of A/D conversion, which would require 2 to the 8th, or 256 steps. Even so, the waveform is now distinctly analog to the eye. The peak values now are 99/100ths, or 0.99 volts. We have made it to 1%. [attachment=44] Fig. 4 A drastic expansion of the waveform shows that the individual steps are still discrete and digital. The cursors show that one step is now 9.9 mv. The actual number is 10 mv. 1 volt/ 100, but the pixelation of the screen limits the resolution. That is just another form of the same phenomena. In SPICE, we can run the resolution up to an extreme, arbitrary level, although analysis slows down when you calculate out all those decimal places. In practical circuits, noise becomes an increasing intrusion. Every time you add a bit the the digitization, you need the noise floor to be twice as quiet. We have here used SPICE as a visualization and teaching tool, not for circuit design. Does anyone have other examples to share of using SPICE for teaching abstract concepts? Next time, we will start from a pure sine wave and morph it into a square wave. Tom Lawson February 22, 2021 |