Analysis and Simulation of a CIC-Filter-Based MultiplexedInput Sigma-Delta Analog-to-Digital Converter by Seungmyon Park SUBMITTED TO THE DEPARTMENT OF ELECTRICAL ENGINEERING AND COMPUTER SCIENCE IN PARTIAL FULFILLMENT OF THE REQUIREMENTS FOR THE DEGREE OF MASTER OF ENGINEERING IN ELECTRICAL ENGINEERING AND COMPUTER SCIENC MASSACHUSETTS INSTITUTE OF TECHNOLOGY AT THE MASSACHUSETTS INSTITUTE OF TECHNOLOG e U May 1,2001 JUL 11200 > LIBRARIES © 2001 Seungmyon Park. All rights reserved. The author hereby grants to MIT permission to reproduce and to distribute publicly paper and electronic copies of this thesis document in whole or in part. Signature of Author Department of Electrical Engpeinin'd Computer Science Certified by Paul Ward Charles Stark Draper Laboratory Thesis Supervisor Certified by __ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ __ _ _ _ _ _ Professor James K§ Roberge Professor of Electricaltngneering and-9mputer Science Thasis Advisor Accepted by Frolessor Arthur C. Smith Chairman, Departmental Committee on Graduate Theses Analysis and Simulation of a CIC-Filter-Based MultiplexedInput Sigma-Delta Analog-to-Digital Converter by Seungmyon Park SUBMITTED TO THE DEPARTMENT OF ELECTRICAL ENGINEERING AND COMPUTER SCIENCE ON MAY 23, 2001 IN PARTIAL FULFILLMENT OF THE REQUIREMENTS FOR THE DEGREE OF MASTER OF ENGINEERING IN ELECTRICAL ENGINEERING AND COMPUTER SCIENCE AT THE MASSACHUSETTS INSTITUTE OF TECHNOLOGY Abstract Draper Laboratory's MEMS inertial instruments used for navigation demand extremely high dynamic range and low power consumption. In this thesis, a multiplexed-input sigma-delta analog-to-digital converter using a cascaded integrator-comb filter used in the MEMS instrument electronics is analyzed and simulated in order to determine the tradeoff between resolution and multiplexing rate. A simulation model created in Simulink is used in order to verify the correctness of the analysis and to predict performance. A VHDL simulation model is also created in order to further evaluate performance and to check synthesizability and power consumption. Simulation data shows that the design evaluated is capable of providing a signal-to-noise ratio of up to ~100dB when four slowly-varying ( 5 5Hz) inputs are multiplexed. Technical Supervisor: Paul Ward Title: Group Leader, Charles Stark Draper Laboratory Thesis Advisor: Professor James K. Roberge Title: Professor of Electrical Engineering and Computer Science 2 ACKNOWLEDGMENT May 23, 2001 This thesis was prepared at The Charles Stark Draper Laboratory, Inc., under Internal Company Sponsored Research Project 3050, HPG1 ASIC Test and Evaluation. Publication of this thesis does not constitute approval by Draper or the sponsoring agency of the findings or conclusions contained herein. It is published for the exchange and stimulation of ideas. or's signature) 3 (This page intentionally left blank.) 4 Acknowledgements I would first like to thank the Charles Stark Draper Laboratory for sponsoring my work on this project. I would also like to thank my Draper supervisor Paul Ward and faculty advisor Professor James Roberge for their invaluable technical guidance, insight, and patience. In addition, I would like to thank David McGorty of Draper Laboratory, for this project could not have been completed without his technical guidance. I would also like to express my gratitude towards the following people at Draper who made this thesis possible: Bob Kelley, Phil Juang, Amy Duwel, and Rob Bousquet. Finally, I would like to thank Dr. Marc Weinberg for providing me the opportunity to work at Draper. 5 Contents 1 Introduction Background . . . . . . . . . . . . . . . . . 12 1.1.1 Application . . . . . . . . . . . . . 12 1.1.2 Choosing the ADC Architecture . . 13 1.2 Purpose and Organization of this Paper. . 17 1.3 Definition of Resolution . . . . . . . . . . 17 1.1 2 12 Analysis of the Draper] Design 2.1 2.2 2.3 2.4 2.5 Sigma-Delta Modulato r - - 19 - - - - . . . 19 2.1.1 Sources of Nois e . . . . . . . 21 2.1.2 Signal and Noisse Transfer Fuinctions. 23 2.1.3 Performance .. 25 Digital Filter . . . . . . . . . . . . . . . 27 2.2.1 Overview . . . . . . . . . . 27 2.2.2 Architecture . . . . . . . . . 28 Combined Analysis . . . . . . . . . . . . 30 2.3.1 Signal and Noise Power . . . 30 2.3.2 Downsampling . . . . . . . 32 2.3.3 Obtaining Filter Parameters 33 Results . . . . . . . . . . . . . . . . . . . 34 2.4.1 Filter Parameters . . . . . . ... ... .. ... . 34 2.4.2 Multiplexing . . . . . . . . . ... ... .. ... . 34 Laboratory Setup and Measurements 6 37 3 3.1 Overview . . . . . . . . . . . . . . 40 3.2 Sigma-Delta Modulator . . . . . . 41 . . . . . . 43 3.3 CIC Filter . . . . . . . . . . . . . 43 3.4 Results . . . . . . . . . . . . . . . 44 3.4.1 SDM Settling Time . 44 3.4.2 ADC Performance .. . . 47 3.2.1 4 Thermal Noise 52 Simulation of the Hardware Using VHD IL 4.1 Overview of the Test Bench . . . 52 4.2 Thermal Noise Blocks . . . . . . 54 4.3 VHDL Implementation of the SDIM 57 4.4 VHDL Implementation of the CIC Filter. . . . . . 61 4.5 4.6 5 40 Simulation Using Simulink 4.4.1 Architecture . . . . . . . . 61 4.4.2 Register Sizing . . . . . . 64 4.4.3 Performance . . . . . . . . 67 . . . . . . Design Guidelines . . . . . . . . . 69 4.5.1 Truncation Noise Analysis 69 4.5.2 Approach to Design . . . . 71 4.5.3 Multiplexing . . . . . . . . 73 Synthesis of VHDL Code . . . . . 74 4.6.1 Synthesizability and Power Consi 74 4.6.2 Alternate Architecture . . 76 78 Conclusion Bibliography 80 A Matlab Scripts 82 A.1 A.2 cic-filt.spec.m ... .. 82 ................................ .. rn-choose.m..... .. . ... .. 7 . ... . . . . . . . . .. ... . . 85 B VHDL Code 87 B.1 read-prn.vhd . . .. .... .... . . . . . . . . . . . . .. . .. . . 87 . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . 89 B .3 prn2.vhd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 BA com p-cic.vhd 95 B .2 prn.vhd ............................... B.5 com p-cic2.vhd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 B.6 comp-sdm .vhd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 B.7 comp-allAb.vhd . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . 107 List of Figures 1-1 Flash ADC Architecture . . . . . . . . . . . . . . . 14 1-2 Semi-Flash ADC Architecture . . . . . . . . . . . . 14 1-3 Sigma-Delta ADC Architecture . . . . . . . . . . . 15 2-1 SDM Block Diagram ....... ........................... 20 2-2 SDM Discrete-Time Representation . . . . . . . . . . . . . . . . . . . 20 2-3 Distribution of e[n] based on input voltage . . . . . . . . . . . . . . . 21 2-4 Signal and noise transfer functions of the SD2-ADC . . . . . . . . . . 24 2-5 CIC Filter Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . 28 2-6 Magnitude response of a CIC filter with N=3, R=1000. . . . . . . . . 30 2-7 Laboratory measurement of SDM settling time . . . . . . . . . . . . . 36 2-8 Layout of the Test Chip . . . . . . . . . . . . . . . . . . . . . . . . . 37 2-9 SDM Thermal Noise Plot . . . . . . . . . . . . . . . . . . . . . . . . . 38 3-1 Top-level Simulink Model Block Diagram . . . . . . . . . . . . . . . . 41 3-2 SDM Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 3-3 Details of "Stage 2" of the SDM . . . . . . . . . . . . . . . . . . . . . 42 3-4 Simulink CIC Filter Implementation . . . . . . . . . . . . . . . . . . 44 3-5 Modified SDM Block Diagram . . . . . . . . . . . . . . . . . . . . . . 45 3-6 SDM Settling Response . . . . . . . . . . . . . . . . . . . . . . . . . . 45 3-7 Decay of the SDM output oscillation . . . . . . . . . . . . . . . . . . 46 3-8 SDM Simulation PSD .-. . . . . . . . . . . . . . . . . . . . . . . . . . 48 3-9 ADC Output for 5Hz Sine Input . . . . . . . . . . . . . . . . . . . . . 49 3-10 PSD for ADC Output with 5Hz Sine plus thermal noise input 9 50 3-11 PSD of Thermal-Noise-Stimulated ADC Output . . . . . . . . . . . . 50 . . . . . . . . . . . . . . . . . 51 4-1 VHDL Test Bench Block Diagram . . . . . . . . . . . . . . . . . . . . 53 4-2 Shift-Register-Based Pseudorandom Number Generator . . . . . . . . 55 4-3 PSDs of simulated thermal noise using prn.vhd . . . . . . . . . . . . . 56 4-4 PSDs of simulated thermal noise using prn2.vhd . . . . . . . . . . . . 57 4-5 Block Diagram of COMP..SDM 58 4-6 VHDL-Generated Sine Wave with a Non-Integer Fundamental Frequency 59 4-7 Effect of Resetting the Variable count . . . . . . . . . . . . . . . . . . 60 4-8 Comparison of VHDL- and Simulink-generated Sine Waves . . . . . . 60 4-9 PSD of the VHDL and Simulink SDM Outputs . . . . . . . . . . . . 61 3-12 ADC Output with Multiplexed Inputs . . . . . . . . . . . . . . . . . . . . . . 4-10 PSD of the Simulink CIC Filter Output when Using Different SDM M odels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 4-11 Block Diagram of the CIC Filter Implemented in VHDL . . . . . . . 62 4-12 Magnitude Response Comparison . . . . . . . . . . . . . . . . . . . . 64 4-13 Thermal Noise - Noise Floor Mismatch in VHDL . . . . . . . . . . . 68 4-14 Distribution of Truncation Noise . . . . . . . . . . . . . . . . . . . . . 70 4-15 Comparison of the Predicted and Actual output SNR for R=900, N=3 73 10 List of Tables 2.1 Filter parameters for various ENOB values . . . . . . . . . . . . . . . 34 2.2 Settling time for various ENOB values . . . . . . . . . . . . . . . . . 36 3.1 SDM settling time for various output widths . . . . . . . . . . . . . . 47 3.2 Simulation Summary for a 5Hz, 4V Peak-to-Peak Sine Input . . . . . 50 4.1 Register widths for R and N values used in the Simulink model . . . . 66 4.2 Approximate VHDL ADC signal-to-noise ratio in dB, N=3 . . . . . . 68 4.3 SNRn for 5Hz, 4V Peak-to-Peak Sinusoid Input, N=3 . . . . . . . . 72 4.4 Power consumption for CIC filter, R=900, N=3 . . . . . . . . . . . . 75 4.5 Power consumption for CIC filter, N=3, B0 st = 18 . . . . . . . . . . . 75 4.6 Power consumption for comp.cic2.vhd, N=3, B0 st = 18 76 11 . . . . . . . . Chapter 1 Introduction 1.1 1.1.1 Background Application Draper Laboratory's high-precision MEMS-based inertial instruments for navigation (such as gyroscopes and accelerometers) are capable of providing an extremely high dynamic range difficult to achieve with conventional techniques. MEMS-based in- struments have the added advantage that the sensor is extremely small, significantly reducing the size of the overall package. In order to successfully design such sensors, however, one important issue must be resolved. There are several environmental factors that can affect the behavior of MEMS sensors, and to a much lesser degree, the analog circuitry. Because some applications for these instruments demand extremely high dynamic range, the errors induced by these environmental factors can become very significant. For example, changes in temperature can significantly affect the bias and scale factor of MEMSbased instruments. This dilemma is made more significant by the fact that navigational instruments are typically exposed to various different environmental conditions and need to perform consistently in all conditions. To resolve this problem, various analog sensors are used to measure the environmental conditions that affect the performance of the MEMS sensor. The obtained 12 analog signals, called compensation variables, are then digitized by an analog-todigital converter (ADC). This digital data is processed by an on-board computer using a model of the error introduced by the various environmental stimuli on the MEMS sensor, and the output of the instrument is compensated accordingly. For the application examined in this paper, it is necessary for the electronics surrounding the MEMS sensor to be low-power and minimum-hardware. For this reason, one ADC is shared by multiple compensation variables present in this application. This sharing is done by multiplexing the compensation variables to the ADC input and switching the multiplexer at a constant rate. The next section briefly discusses various common analog-to-digital conversion techniques, and the design choices made in the ADC examined in this paper. 1.1.2 Choosing the ADC Architecture Analog-to-Digital Converter Architectures The topic of analog-to-digital conversion has been studied extensively, and a wide variety of conversion methods exists as a result. Some of the more widely-used methods will be mentioned here. One of the most common type of ADCs is the flash converter. Flash converters can reach very high sampling rates since the only analog building blocks are the comparator and the resistor ladder [1]. Figure 1-1 illustrates the architecture. As the figure shows, the resistor ladder provides various reference levels for the comparators. Each comparator reads in one reference level and compares it against the analog input, and the collective outputs of the comparators are decoded to form a digital output. The main problem with this architecture is that the number of comparators increases exponentially with the number of bits. Because of this hardware requirement, the power and area requirements become unreasonably large for a high number of output bits [1]. In addition, because the resistors must be well-matched, extremely precise analog circuitry is needed. To reduce the number of comparators, the semi-flash converter can be used. As 13 Analo x NV tInpl Digi tal Ou-tpuIt Dlecoder rl+ Figure 1-1: Flash ADC Architecture Figure 1-2 shows, the analog-to-digital conversion is done in two stages. In the first stage, a coarse ADC is used to generate N1 most-significant-bits (MSBs) of the output. A digital-to-analog converter (DAC) then converts the output of the coarse ADC and subtracts it from the original analog input to produce a "residue" signal. A second ADC is then used to convert the residue signal and generate N2 least-significant-bits (LSBs). This ADC architecture is much slower than the flash architecture, but it only requires 2 N1 + 2 N2 -2 comparators, as opposed to the 2 N1+N2 -1 comparators needed for the flash architecture [1]. However, like the flash converter, semi-flash converters also require high-precision analog circuitry in order to achieve good resolution. Residue Analo ig Input ADC1 ADC2 DAC Ni Coars e Bits - N2 Fine Bits Figure 1-2: Semi-Flash ADC Architecture There are several other ADC architectures based on the architectures shown so far. The folding and interpolating ADC architecture is similar to the semi-flash architecture, but instead of using a DAC and a subtractor to create the residue 14 signal, it uses an analog "folding circuit" that takes in the analog input and produces the same signal. Thus, the coarse and the fine ADCs can convert the input signal almost simultaneously. The multi-stage pipelined ADC is similar to the semi-flash ADC, but it differs in that there are many more stages (Figure 1-2 shows only two), and each stage is pipelined. This variation allows the pipelined ADC to have a much higher sampling rate than the semi-flash ADC [1]. The oversampling sigma-delta ADC architecture is quite different from the architectures mentioned thus far. Figure 1-3 shows a simplified block diagram of the sigma-delta ADC. ----------------------------- Analog filter ' Quantizer Digital Output Input clk DAC *- - Sigma-Delta Modulator Figure 1-3: Sigma-Delta ADC Architecture As the figure shows, the sigma-delta ADC is divided into two major parts: the sigma-delta modulator (SDM) and the digital filter. The basic thought behind sigmadelta modulation is the exchange of resolution in time for resolution in amplitude. As shown in the figure, the quantizer (which can be thought of as a very coarse ADC) quantizes the signal at its input, creating a digital output. This digital output is converted back to an analog signal by the DAC, and the DAC output is compared to the input of the modulator by the subtractor. This negative feedback of the loop suppresses the error caused by the quantizer for the signals falling within the passband of the loop filter [2]. Also, by oversampling the quantizer, noise power is spread over to frequencies beyond the band of interest. Thus, the output of the SDM will have extremely low error in the passband of the ADC (as defined by the loop filter). The digital filter following the SDM has two purposes. First, because the input signal is 15 oversampled, the output of the SDM must be downsampled to the original analog input bandwidth. However, because there is a large amount of out-of-band noise in the SDM output, simply downsampling the SDM output will result in the aliasing of out-of-band noise into the band of interest. Thus, the digital filter must first remove the out-of-band noise, and then downsample the result. Unlike the architectures based on resistor ladder networks, oversampling sigma-delta converters do not require highprecision analog circuitry. Since its resolution is not limited by imperfections in the circuitry, sigma-delta ADCs are suitable for high-resolution applications that require a complete integration of the circuit onto an application-specific integrated circuit (ASIC) [1]. However, because it oversamples the input, sigma-delta ADCs are more suited for narrow-bandwidth applications. Also, sigma-delta ADCs are much slower than the other architectures mentioned, mostly due to the settling time (the time between the initial reading of the input and the output of the filter becoming valid) of the digital filter. As mentioned earlier, this section mentions only some of the more commonly-used ADC architectures. Several other architectures not mentioned in this section, such as the successive approximation converters and various types of integrating converters, are still widely used today. Design Choices For the application described in the previous section, it was decided that a sigmadelta ADC design would be used. There are several reasons for this choice. One is that sigma-delta ADCs do not require precision analog hardware required by the other architectures, thus reducing cost and complexity of the analog circuitry. The reduction of complexity results in a reduction of area and power. In addition, for low-speed, narrow-band applications, sigma-delta ADCs can achieve a much higher signal-to-noise ratio (SNR) compared to other designs, which makes it suitable for high-precision applications like navigational instruments. One major shortcoming of the sigma-delta design is its large settling time. However, this shortcoming is not a cause for great concern since the compensation variables vary at an extremely low 16 rate. Because of this low rate of change, even if the multiplexer switchs the input to the sigma-delta ADC at a rate slow enough for the ADC to settle, all of the compensation variables can be digitized at a satisfactory rate. Prior to the start of this project, the sigma-delta modulator used for the ADC was designed, and the architecture of the filter used for decimation was selected. Some simulation models were created prior to the start of this project to test the feasibility of the planned implementation. The following section discusses the topics covered in this paper. 1.2 Purpose and Organization of this Paper The main focus of this project is to accurately analyze, model, and simulate the performance of the proposed sigma-delta ADC in order to determine the tradeoff between resolution and the multiplexing of the inputs. This tradeoff can more simply be seen as a tradeoff between resolution and settling time. By understanding this relationship, one can easily design the ADC such that it will achieve the desired resolution for multiple inputs. The paper is organized as follows. Chapter 2 analyzes the SDM and digital filter mathematically in order to predict its behavior. It also discusses some laboratory work done in order to verify the performance of the SDM. Chapter 3 describes the ADC simulation model created in Simulink and discusses the results obtained in simulation. Chapter 4 discusses the ADC simulation model created in VHDL and the simulation results. It also discusses issues regarding the implementation of the digital filter in hardware, such as synthesizability and power consumption. Chapter 5 is conclusion. 1.3 Definition of Resolution In order to study the tradeoff between resolution and settling time, the term resolution must be clearly defined. In the analysis shown in the next several chapters, resolution 17 is defined in terms of effective number of bits (ENOB). For an ADC with a finite number of bits at the output to represent an analog input signal, some quantization noise at the output is inherent. Given this fact, Engelen [2] determines the maximum possible signal-to-noise ratio (SNR) of an ADC with B output bits, SNRmax, as follows. The maximum amplitude of a sinusoid that does not cause the quantizer to overload is Ama - 2, , where q is the quantization step size. The root-mean-square (rms) amplitude of this sinusoid is then Amax,rms = 2. The total quantization error power in the Nyquist frequency range is Nq = e. The 12 derivation of this value is explained in Section 2.1.1. The rms amplitude of Nq is Nq,rms =q. SNRmax is then calculated as SNRmax = 20 - log 10 (A,"r""') = 20 -log 1 0 ( =B -6.02 + 1.76 qlV-12) (1.1) For a given B, SNRmax is the highest attainable signal-to-noise ratio. By rearranging Equation 1.1, we can solve for B, which can be construed as the effective number of bits for a given SNR. ENOB = Rmax -1.76 6.02 (1.2) The concept of ENOB will be used in the following chapters as a guideline for design. 18 Chapter 2 Analysis of the Draper Design As mentioned earlier, the sigma-delta ADC design being evaluated is comprised mainly of a second-order sigma-delta modulator (SDM) coupled with a digital lowpass filter. In this section, these components will be analyzed mathematically. The resulting calculations will be used as a guideline to determine the achievable resolution and the associated multiplexing rate. 2.1 Sigma-Delta Modulator The sigma-delta ADC used in the inertial instrument to convert compensation variable signals incorporates the sigma-Delta modulator SD2ADC, a second-order switchedcapacitor-based design. This SDM typically runs at a sampling rate of 320KHz and consumes 7mW of power at 5V. Figure 2-1 is a block diagram of the modulator. Although the SDM is an analog circuit, it operates like a digital circuit and can be analyzed as such. Figure 2-2 is a discrete-time equivalent of Figure 2-1. In this block diagram, the switched-capacitor-based integrators are represented with the accumulator system function G(z) = __. Also, the 1-bit digital-to-analog converter used to feed back the digital output y[n] can be removed since the system is already digital. The gain values a, b, c, d, and e are chosen as such in order to keep the system stable. 19 e=1/3 1-bit quantizer IN - a=1/5 dt § dt d b=1/3 d=1/6 Figure 2-1: SDM Block Diagram e [n] =15G(z) G(z) bn s[n]= 1-bi x[n]+t[n] quan izer d=1/6 c=1/5 Figure 2-2: SDM Discrete-Time Representation 20 2.1.1 Sources of Noise Quantization Noise The 1-bit quantizer, which lies at the output of the SDM, produces an output of 2.5V if the input is positive, and -2.5V if it is negative. As shown in Figure 2-2, the effect of the quantizer can be approximated simply as an additive noise sequence e[n]. Typically, given the quantization level A = 5.OV, e[n] can be approximated as a uniformly distributed white-noise sequence, distributed over ± with a probability of A. This distribution is shown by Figure 2-3. The variance of uniformly distributed white noise is calculated as follows: -2 A Te2 'A2 de = (2.1) -=2.0833 2 P (e) 1/5 e 2.50 -2.50 Figure 2-3: Distribution of e[n] based on input voltage In the case of a white noise sequence, its power spectral density (PSD) is constant over all frequency with its magnitude equal to its variance. Thus, for e[n]: V2 <De(ejw) = 2.0833rad (2.2) In reality, the quantization error sequence e[n] is not exactly a white noise sequence due to the fact that e[n] is correlated with the input x[n]. However, the white noise approximation is made more valid by the fact that other sources of noise in the SDM act as a dither signal that randomizes the input. 21 Thermal Noise Because the SD2_ADC is a switched-capacitor-based design, it is also susceptible to thermal noise. According to Norsworthy [3], thermal noise is caused by the random fluctuation of carriers due to thermal energy. Because thermal noise is present even at equilibrium (e.g., in a turned-on MOSFET with zero average current flow), it needs to be taken into account for both the switches and op-amps in a switched-capacitor circuit. Thermal noise can be approximated as having a flat spectrum and a wide band that is limited by the time constants of the switched capacitors (which is determined by the size of the capacitors and the on-resistance of the switches) or the bandwidth of the op-amps. Thermal noise spectrm is flat because it is generally uncorrelated with the input. Because the sampling rate of the circuit is typically lower than the bandwidth of the thermal noise, the effect of the noise is worsened by aliasing. The thermal noise performance of an SDM is determined mainly by the switch noise and the op-amp noise of the first integrator (that is, the integrator closest to the input) because of the gain this integrator provides for the lower in-band frequencies [3]. Thus, as shown in Figure 2-2, thermal noise can be modeled as additive noise t[n] at the input of the SDM. As mentioned earlier, thermal noise is generally uncorrelated with the input [2]. Because of this fact, thermal noise can be modeled as a normally distributed bandlimited white noise sequence. Previous testing of the SDM indicate that the thermal noise level is approximately -1 14 dBv HZ 2 1 Other Sources of Noise In addition to quantization and thermal noise, there are several other sources of noise in the SDM. They are not considered in the analysis because they are insignificant compared to thermal and quantization noise. Aliasing noise and idle tones are two such sources of noise. Because the input signal is bandlimited by a low-pass filter, the effect of aliasing due to SDM sampling is minimized. In this analysis, this type 'From an unpublishable Draper internal memorandum 22 of aliasing noise will be simply grouped with thermal noise. Idle tones can become a noticeable noise source in the passband for constant inputs near the rail. Such inputs cause problems because a constant positive input near the rail may produce an output pattern that consists mostly of I's with an occasional, periodic 0, while the converse will occur with a constant negative input. These occasional O's or l's have low periodicity and are reflected as spikes in the passband. In order to avoid this form of noise, the input voltage to the SDM is limited to +2. Thus, this source of noise need not be considered. 2.1.2 Signal and Noise Transfer Functions The behavior of the SDM is characterized by its signal transfer function (STF) and noise transfer function (NTF). As the name suggests, the STF determines how the input signal x[n] is affected by the modulator, while the NTF determines how the quantization noise sequence, in this case e[n], is shaped. By using superposition, the STF YN)and X(z) the NTF YE(z) can be determined independently. Based on Figure 2-2, the STF is determined as follows: Y(z) = V(z)G(z) (2.3) V(z) = eX(z) + bG(z)W(z) - dY(z) (2.4) W(z) = aX(z) - cY(z) (2.5) which combine to form: Y(z) X(z) _ - abG2 (z) + eG(z) 1+dG(z)+bcG2 (z) (2.6) Substituting in appropriate values for a, b, c, d, e, and G(z): 2 _ STF(z) = - 37 30 23 1-1 3 13 Z-1 + Z- 2 T (2.7) The NTF of the SDM can be determined similarly. To determine the NTF: Y(z) = E(z) + G(z)V(z) (2.8) V(z) = bG(z)W(z) -dY(z) (2.9) W(z) = -cY(z) (2.10) 1 - 2z-' + z-2 NTF (z)--7-13 z- 1 + z- 2 6 TO- (2.11) which combine to form: 2-T 1.8- 1.6 1.4- 0.80.6 0.40.2- 0 0.05 0.1 0.15 0.2 0.25 frequency (rad) 0. 3 0.35 0.4 0.45 0.5 Figure 2-4: Signal and noise transfer functions of the SD2_ADC The frequency characteristics of the STF and the NTF can be examined by replacing the variable z in Equations 2.7 and 2.11 with ej'. The variable W ranges from 0 to 27r, which is equivalent to 0Hz to the sampling frequency f,. Figure 2-4 shows the magnitude response of the STF and the NTF, with the x-axis being the radian frequency w. It can be seen from Figure 2-4 that at low frequencies, the signal x[n] will be minimally affected by the SDM since it is shaped by the STF. However, the quantization noise will be shaped by the NTF such that it is minimized at low frequencies. 24 2.1.3 Performance The performance of an SDM is typically measured in terms of its signal-to-noise ratio (SNR), a ratio of the signal and the noise power. Before introducing the nonidealities associated with the actual filter used in the Draper Laboratory design, a 100Hz brick-wall low-pass filter can be applied in order to get a good sense of the SDM performance. In [4], total power in signal g[n], P9 is defined as: P9 = E(g 2 [n]) = Ogg [0] = where E(g 2 [n]) is the expected value of g2 [n], 4bg,(eiw) is the fourier tranform of #gg 1 jD.,(eiW)dw qgg[r] (2.12) is the autocorrelation of g[n], and [7]. bgg(eiw) is also the power spectral density (PSD) of the sequence g[n]. In determining the power of the input signal x[n], the signal transfer function of the SDM, STF(ew), and the low-pass filter must also be taken into account. Px = -Lfw_". (ew) -ISTF(w)| 2 dW w, = 27rfcT = 27r(lOOHz)( 3 2 KH 0.2rad (2.13) (2.14) Some simplifying assumptions can be made with regards to Equation 2.13. In this analysis, the input x[n] is simply a 5Hz, 4V peak-to-peak sinusoid. Thus, the signal is unaffected by the low-pass filter. Also, since the signal is a at relatively low frequency, the STF can be approximated as unity. This simplification makes power easy to determine. If x[n] = 2 cos(t), then using Equation 2.12 Px = E([2cos(t)] 2 ) = 4. E( 1[1 + cos(2t)]) = 2V 2 (2.15) The quantization noise power is calculated in a similar manner, but its PSD is 25 shaped by the noise transfer function rather than the signal transfer function. - INTF(w) 2 dw Pe = -Lf_','De(ew) = f_"': -(2.0833) - INTF(ew) = 8.62 x 10-13V 2 (2.16) dw 2 (2.17) It can be seen from Equation 2.16 that quantization noise in the low-pass-filtered region is significantly reduced by the noise transfer function. Given the power of the signal and the quantization noise, the SNR of the SDM due to the quantization noise can be determined. SNRq = 10- log 10 (Pi) ~ 123.66dB Pe (2.18) Using the definition of effective number of bits (ENOB) described in Section 1.3, 123.66dB translates to approximately 20 bits of resolution. However, thermal noise further limits the effective resolution of the SDM. In fact, because thermal noise is not shaped by the NTF, it could actually be more significant at lower frequencies. Earlier, the thermal noise level was given as -114 Hz 2. The value -114dbV 2 can also be represented as follows. 2 = 10. log o ((V 2 -114dB VdB1 1 \ 2 V2 ) 2. (2.19) x = 3.98 x 10~ 2 V2 bth (f) = 3.98 x 10 -12V 2 (2.20) As shown above, the thermal noise level can also be expressed as 3.98 x 10-12VHz For a 100Hz band, the resulting thermal noise power is: Pth = 0 Pth(f)df f = 3.98 x 10- _- Hz 26 100Hz = 3.98 x 10~ 10 V 2 (2.21) resulting in a signal-to-noise ratio of S NRh = 10 -log y0 ~ 97.01dB (2.22) (Pth This value, which is significantly lower than SNRq, is equivalent to approximately 16 bits of resolution. These calculations assume an ideal filter in order to focus on the performance of the SDM. In reality, non-idealities associated with the digital filter actually used further limit the achievable resolution. This relationship is examined in later sections. 2.2 2.2.1 Digital Filter Overview The output of the SDM represents an oversampled input sequence along with various in- and out-of-band noise. The purpose of the digital filter is to preserve the original input while removing the out-of-band noise. Once the filtering is done, the signal must be downsampled in order to reflect the original input. Insufficient filtering can result in significant noise penalty due to aliasing caused by downsampling. In the Draper sigma-delta ADC design, the architecture used for digital filtering is a finite-input-response (FIR) low-pass filter implentation known as the cascaded integrator-comb (CIC) filter [5]. This implementation is used for two main reasons. First, it has a simple hardware implementation. As mentioned earlier, one of the main design considerations for the Draper sigma-delta ADC is low power consumption. As shown in the next section, the CIC filter is extremely hardware efficient, requiring only adders and registers. Because of its hardware simplicity, it consumes less power than FIR architectures that require multipliers. Second, the filter architecture is such that a separate decimator is not needed. The downsampling rate can simply be specified as a filter parameter. 27 Integrator Section Stage 1 Z-1 * S Comb Section Stage N S OSO Stage N+1 Z- Z-1 S 1 * * Stage 2N Z-1 -1 f -.s fs OSS fs -1 * * R R Figure 2-5: CIC Filter Block Diagram 2.2.2 Architecture A block diagram of the CIC decimation filter is shown in Figure 2-5. As the figure shows, the filter is divided into two main sections, the integrator section consisting of a set of N integration stages and the comb (differentiator) section formed by a set of N differentiation stages. Each integration stage is implemented as a one-pole filter with a unity feedback coefficient. It runs at the high sampling rate of f8, which is the same as the clock rate of the SDM. The system function of each integrator stage is Hi(z) = 1 1 (2.23) As seen from Figure 2-5, the comb section receives only every Rt" dati sample from the integrator section. Also, each differentiation stage runs at the downsampled frequency of L. This reduced clock-rate operation of the comb section effectively results in the downsampling of the output data by a factor of R. The system function of a single differentiation stage, relative to the high sample rate 28 f, is Hc(z) =1 - z- (2.24) Combining equations 2.23 and 2.24, the system function of the overall filter can be determined. N N H(z) = HIN(z)HC 1 = -g-1 ( lN -1 )N -Z-R = ) -k] [ (2.25) k=O It can be seen from Equation 2.25 that a CIC filter with N stages in each section is essentially an Nth-order FIR filter. The magnitude response of the Nth order CIC filter is as follows. |H(ejw)I2 _ _ n)N _ (e ± -2j sin t)N N 1N N ~ N (sin 2 (2.26) _ As Equation 2.26 shows, the magnitude response of a CIC filter is approximately equal to an Nh -order sinc function. The shape of the sinc function is dependent solely on the order N and the downsampling rate R. Thus, these variables can be manipulated to provide the desired passband and rolloff characteristics of the filter. Figure 2-6 is an example with N = 3 and R = 1000. It should be noted that the system functions of the CIC filter shown above apply to the filter operating at the high sample rate can be viewed as a two-step process. f,. The operation of the CIC filter First, the SDM data, which is sampled at f, = 320KHz, is shaped by the function shown in Equation 2.26. The variable W in this function is calculated relative to the sampling rate of the SDM (the high sample rate). Next, output of the filter is resampled at the low sample rate of L'. This resampled output is the final output of the filter. The effect of decimation, as well as the details regarding the hardware implementation of the filter, are discussed in later sections. 29 CIC Filter Power Response, R=1000, N=3 1010 10 -4 0 2 10-51 log frequency (rad) Figure 2-6: Magnitude response of a CIC filter with N=3, R=1000. 2.3 Combined Analysis analysis will be In this section, the results of the SDM analysis and the CIC filter ADC. combined to estimate the performance of the Draper sigma-delta 2.3.1 Signal and Noise Power unchanged, while In the case of the ideal 100Hz brickwall filter, the signal remained filter exhibits some noise remained only in the passband. However, because the CIC Also, noise must attenuation in the passband, signal power must be reevaluated. cannot be removed be evaluated over the entire spectrum since out-of-band noise completely by the CIC filter. sinusoid. The input signal in this analysis is a fi, = 5Hz, 4V peak-to-peak signal power, P'f, is Since all of its power is contained at one frequency, the filtered calculated simply as 2 Pxf = Px -jH(ewaig)1 Wig = 27rfsigT = 27r(5Hz)(2 1kH) 30 = 9.8175 x 10-5rad (2.27) where IH(ej')I is from Equation 2.26. As long as the design of the filter is such that W,8 g is less than the cutoff (-3dB) frequency of the filter, the attenuation of the signal in the passband is not significant. Out-of-band quantization noise power is significantly reduced by the CIC filter, but it cannot be completely removed. Power of the shaped quantization noise is calculated as: Pef = +Jc 2,7r -w e(e3) -|NTF(w)12 - H(ejw) dW (2.28) While most of Pef comes from the noise in the passband, filtered out-out-band noise covers a wide frequency band and cannot be ignored for several reasons. One is that the out-of-band noise covers a much wider spectrum than the in-band noise. More importantly, the out-of-band noise is shaped by the NTF, which increases according to the order of the SDM at high frequencies. The filter must be good enough to attenuate the rising noise. It was previously stated that the thermal noise level of the SDM running at 320KHz was - which 1 1 4 dbv, Hz 7Hz is equal to 3.98 x 10-12V2 (Equation 2.20). Given this information, the thermal noise PSD in radians, cJth(ejw), and thermal noise power after filtering, Pthf, can be calculated. foo4 Dth(f)df = ot = (3.98 x 10-12) (2.29) - ( ) = 6.368 x 10- 7 V2 Noting that Dth (eiw) is also constant over the entire spectrum, 2 = _L~T~j'r Jr Dth (ejw)dW =th2 4Dth(ejw) = Pthf = -Lf, rIth(ejw) - a2 2 dw |STF(w)12 -_IH(ejw)1 Equations 2.29 and 2.31 can be found in [6] and [4], respectively. (2.30) (2.31) (2.32) The above equations assume that thermal noise, like quantization noise, is white. While both quantization and thermal noise are approximately white, out-of-band thermal noise 31 is less significant than quantization noise due to its shaping by the STF rather than the NTF. Using Equations 2.27, 2.28, and 2.32, the signal-to-noise ratio of the overall SDM can be calculated as: SNR = 10 - log 0 2.3.2 \Pef + Pthf (2.33) ( Downsampling As mentioned earlier, the CIC filter not only low-pass-filters the signal but also downsamples the output by a factor R relative to the input. In order to prevent the aliasing of the passband that could result from downsampling, R must satisfy the following inequality. 2f >fp R< fpb 2 b (2.34) fpb in the above equation represents the highest frequency in the passband. In the case of the input signal a~n], fpb can be replaced with foig = 5Hz, resulting in the Rnax = 32, 000. Even if R is less than Rmax and the signal in the passband is not aliased, because the CIC filter cannot completely remove out-of-band noise, aliasing of noise outside of the passband cannot be avoided. As a result, the out-of-band noise essentially "folds into" the passband after downsampling, resulting in an increase in the noise level in the passband. However, the total signal and noise power in the spectrum remains unchanged after downsampling. Since the equations in the previous section take into consideration the signal and noise power over the entire spectrum rather than just the passband, the analysis need not be altered. 32 2.3.3 Obtaining Filter Parameters Given a desired ADC resolution in terms of ENOB (effective number of bits), the equations for signal and noise power in the previous section can be used to determine the necessary filter parameters. However, because it is exceedingly difficult to come up with a closed form expression to solve for the filter parameters N (filter order) and R (decimation rate) given the ENOB, a Matlab script was created to automate this task. This script, rn-choose.m, can be found in Appendix A.1. The following parameters are specified in the script. " Desired ENOB " SDM sampling rate f, * SDM order p " SDM transfer functions STF(ew) and NTF(ew) " Signal frequency f8ig " Quantization noise PSD <I,(ew) =a,. * Thermal noise PSD bIth(e=w) _h Given this information, the script iteratively produces the CIC filter magnitude response IH(eiw)l and calculates the values Pj 1 , Pef, and Pthf in order to determine the ADC signal-to-noise ratio. As the starting point, the script chooses N = p + 1. Setting N as such is to ensure that the rolloff of the filter, which is determined by its order, is greater than the rate at which the NTF rises. For each value of N, R starts from 0 and is incremented by 1 until the calculated SNR is high enough to obtain the desired ENOB. In case the given ENOB cannot be achieved due to the limitations of the SDM and the filter, the script also stops running when increasing R lowers the SNR (which would happen when the cutoff frequency of the filter is low enough to severely attenuate the input signal). The script produces matching R values for N = p+1....-, p + 3. Multiple R-N pairs are obtained in order to find a pair that produces the optimal settling time. 33 2.4 2.4.1 Results Filter Parameters Using the Matlab script rn-choose.m, filter parameters were obtained for ENOB of 14 bits and higher. The resulting filter parameters and the corresponding signal-to-noise ratio are summarized in Table 2.1. R ENOB (bits) 14 15 16 17 17.26 (max) N=3 243 387 1171 5587 12550 N=4 207 333 1021 4875 10909 N=5 186 300 916 4381 9781 N=3 86.20 92.07 98.08 104.10 105.66 SNR (dB) N=4 86.21 92.10 98.09 104.10 105.65 N=5 86.17 92.11 98.08 104.10 105.64 Table 2.1: Filter parameters for various ENOB values As shown in Table 2.1, for a 5Hz input signal, the maximum possible resolution is approximately 17.26 bits according to this analysis. There are two reasons why the ENOB cannot be increased beyond this point. One is that the filter cutoff frequency cannot be less than fig, which results in an unavoidable minimum amount of noise power. The other reason is that the filter's passband gets narrower with increasing R. Since the passband attenuation is greater at higher frequencies, increasing R results in greater input signal attenuation. The calculations also show that the downsampling rate R increases significantly for each additional bit of resolution, regardless of the choice of N. Thus, this filter architecture, and perhaps the overall ADC design, may not be suitable for achieving a significantly higher resolution. 2.4.2 Multiplexing Much analysis and calculation were done so far in order to determine what the filter parameter needs to be for a given resolution of the ADC. This data can now be used to determine how fast the inputs to the ADC can be switched when the inputs are 34 multiplexed into one ADC. In order to determine the optimal rate of switching the multiplexer, the settling time of the ADC must be determined. In this analysis, settling time is defined as the amount of time it takes for the output to reach a steady-state value given a step input. The settling time of the ADC is determined by the settling time of the SDM, tsdm, and the settling time of the digital filter, tfilt. Because these are the dominant delays in the ADC circuit, settling time of the ADC is approximately tadc = tsdm + filt (2.35) The filter settling time tf il can be determined quite easily. In the case of an FIR filter, the settling time of the filter is simply the amount of time it takes to fill every tap of the filter with new data. That is, when the multiplexer switches the input to the ADC from one source to another, the settling time of the filter is the amount of time it takes for all the taps of the filter to contain a data sample of the new source. Thus, in the case of the CIC filter (or any other FIR filter), the settling time can be regarded as being independent of the inputs being multiplexed. In Equation 2.25, the transfer function of the CIC filter was expressed as a summation notation. This equation can be expanded as such. H(z) = 1 + aiz-1 + a 2 z~2 + ... + a(R-1)Nz-(2)36) As expressed by this equation, a CIC filter with order N and downsampling rate R will have (R - 1)N taps. Given this value, the settling time of such a CIC filter is: 1 tfilt= N (R - 1) - 1 (2.37) The settling time of the SDM is harder to derive analytically. Thus, the settling time of the SDM was obtained by testing it in the laboratory. The details of the laboratory setup is discussed in a later section. The SDM settling time was estimated by injecting the SDM with a 20Hz, 4V peak-to-peak square wave. Figure 2-7 is a 35 screen capture of the oscilloscope with this setup. As seen in Figure 2-7, the SDM Tek Run: 2.50MS/s Average A: 20.Opis @D: 20.Ops ... . . . .. . . .. . . . . . . . . . . . . .. . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . ... . . . . .. ..... MM . . 2.65v . L25 . . . . ... . 2OV . . .............. M7W2.OJJs 4 2.UV V10Mar 2001 13:23:54 Figure 2-7: Laboratory measurement of SDM settling time seems to settle approximately 20pus. However, this value is somewhat inaccurate and will be discussed in more detail in Section 3.4.1. Table 2.2 summarizes the settling times for different ENOBs and filter order. Because the SDM settling time is orders of magnitude smaller than the filter settling time, the values in this table only reflect the filter settling time. As the table shows, ENOB (bits) Settling time N=4 0.0023 0.0026 0.0036 0.0042 0.0110 0.0128 0.0524 0.0609 0.1176 0.1363 N=3 14 15 16 17 17.26 (max) (s) N=5 0.0029 0.0047 0.0143 0.0684 0.1528 Table 2.2: Settling time for various ENOB values settling time consistently increases as the filter order goes up. Thus, when optimizing the CIC filter for settling time, the lowest possible order filter should be chosen. For the application in the inertial instrument, it was desired that four multiplexed inputs be switched at a rate of 20Hz, essentially digitizing each input source at 5Hz. This rate of multiplexing would require the settling time of the ADC to be -O-= 0.05s. It can be seen from the above table that such multiplexing would be possible 36 for upto 16 bits of resolution. For higher resolution, the multiplexer must be switched at a slower rate to avoid error. 2.5 Laboratory Setup and Measurements In order to verify the previously measured data and gather new data, various tests were run on the SDM in the laboratory. Due to the lack of availability of the actual inertial instrument electronics, the tests were run on a test chip, shown in Figure 2-8. Figure 2-8: Layout of the test chip One of the main difference between the actual SDM chip and the SDM in the analysis is that the actual SDM does not produce output signals ranging from -2.5V to +2.5V but rather produces t2.5V centered around a DC offset of +2.5V. This offset, known as MID, can be seen as one of the inputs to the SDM core in Figure ??. Both MID and the reference signal PREF are supplied by the a power source, while the SDM clock was generated by the HP3325B Synthesizer/Function Generator. In order to examine the settling behavior of the SDM, the SDM input was connected to a 20Hz, 4V peak-to-peak square wave generated by the HP3325B function generator. The output was viewed with a Tektronix TDS 754D Digital Phosphor Os37 cilloscope. In order to view the settling behavior in the SDM output, the averaging function of the oscilloscope was used. This function reduces random noise in periodic signals by storing the waveforms generated after each trigger event and then displaying the average of the collected waveforms. Thus, the output of the oscilloscope does not exhibit any time delays. Figure 2-7 shows the result of averaging 100 samples. Another test of interest was to verify the previously measured thermal noise level of -114dY2 HZ . Because sine waves generated by the function generator HP3325A has a harmonic distortion of upto -65dB relative to the fundamental in the frequency range of interest, the input to the SDM was simply tied to MID for this test. Also, in order to reduce the noise associated with PREF, PREF was first passed through a passive low-pass filter with a cutoff of 1KHz (R = 5KQ, C = 100pF). The output of the SDM was viewed using the spectrum analyzer HP3585B. In order to improve the resolution on the spectrum analyzer, a passive low-pass filter with a 1KHz cutoff (R = 1.5KQ, C = 0.1puF) was used to reduce the noise level in higher frequencies. Figure 2-9 shows the output of the spectrum analyzer. REF 12.6 mV 10 dB/OIV RANGE 12-6 MARKER 451.0 Hz 183 nV/.rHz mV 1-.-... ......-... .. ...-... . ---- .ii1 i....._.. ----------------........ _ _ CENTER 500.0 Hz RBW 30 Hz VBW 100 Hz . ..L............. SPAN 1 000.0 ST 2-4 SEC Hz Figure 2-9: SDM Thermal Noise Plot The plot shows the thermal noise level to be approximately 180 V 1oX probe was used, this value is actually 1.8--, 38 Since a which is approximately equal to ___22 -115dBvy. Hz 2 This value closely matches the previously measured value From an unpublishable Draper internal memorandum 39 Chapter 3 Simulation Using Simulink 3.1 Overview In order to determine the validity and the accuracy of the analysis shown in the previous section, the sigma-delta ADC was simulated using Simulink, a graphical, block-diagram-based tool that facilitates modeling and simulating dynamic systems in Matlab. Simulink was used to simulate the design before implementing and simulating the hardware in VHDL because of its speed and flexibility. The original Simulink model of the overall compensation variable electronics was created by Ed Balboni of Draper Laboratory, and the model was modified in order to focus on the SDM-CIC filter interaction. The top-level block diagram of the Simulink ADC model is shown in Figure 3-1. As the figure shows, the model is comprised of the inputs, multiplexer, SDM, CIC filter, a random number generator, and blocks to capture the data at various points of the design. The switch s is used to choose between a single input or a multiplexed input based on the type of simulation. All of these components operate on a common clock running at of 320KHz. The following sections discuss the implementation of each component in Simulink and the results of simulation. 40 Corpensaton WriableAD Swimjtion 11heraW os __4 2nd order Sna-Deka 31 sMW Fs =4 MHzwwmW CIC Decmtn Fier N=3 R=1167 Fsdmn=Ms125= 320Khz sintWe Figure 3-1: Top-level Simulink Model Block Diagram 3.2 Sigma-Delta Modulator The SDM model created in Simulink is a discrete-time approximation of the actual SDM design. Although it does not exhibit the various non-ideal qualities of an actual SDM, this model does produce realistic quantization noise. Thus, its output is much more reliable than the white noise approximation used in the previous section. Figure 3-2 is the block diagram of the SDM. In this figure, The quantizer block is followed by a gain of 2.5 in order to simulate a quantization level of 2.5V. The two "stage" blocks are identical except for the inputs they take. Figure 3-3 shows the components of the Stage 2 block. Each stage associates its inputs with the appropriate gain and integrates them. The discrete-time switched-capactior integrator is simulated by a continuous-time adder with a unit delay in its feedback loop. A saturation block is used to keep the integrator from going above or below ±2.5V. 41 SDM kn lnn00 -- 6DM Out Stage I Stage 2 Figure 3-2: SDM Block Diagram abcd24 In2 abcd2l Y12 + +1-2.5 In3 > Wbc25 Figure 3-3: Details of "Stage 2" of the SDM 42 Ot 3.2.1 Thermal Noise As mentioned earlier, this SDM model does not exhibit any non-ideal behavior. Thus it does not include thermal noise, which puts a significant limit on the resolution of the ADC. In order to incorporate thermal noise into this model, a pseudorandom number generator (PRN) block was added to the input of the SDM. The PRN block used in the model generates a pseudorandom number with a Gaussian distribution on every SDM clock cycle using a table lookup algorithm to generate the output. This algorithm is similar to the Fortran function RNOR described in [7] but uses a different uniform random number generator to produce the index to the table. The period of this algorithm is much larger than 21, providing sufficient randomness even for very long simulations. The mean and the variance of the pseudorandom number sequence was set to 0 and 3.98 x 10-12 -160000 = 6.368 x 10-7, respectively. 3.3 CIC Filter The Simulink model of the CIC filter, like the model used in the analysis section, is ideal. As shown in Figure 3-4, ideal delay units are used in the feedback and feedforward paths instead of the finite number of registers used in the actual hardware. This substitution could mask the potential rounding errors associated with having finite number of registers in the hardware. However, the purpose of this model is to verify the correctness of the analysis in the previous section, which did not take such matters into consideration. Thus, this model is sufficiently accurate. The registers a, b, and c are clocked at the same rate as the SDM, f, = 320KHz, while registers d, e, f, and g are clocked at the downsampled rate of L. Register d in this model essentially acts as the switch shown in Figure 2-5. Since CIC filters have an inherent gain of RN, the gain block G found at the input of the filter reduces the gain by g = g, thus allowing the output magnitude to correctly reflect that of the input. 43 3d order CIC fler G p. ab C . dawneaMh by R + d Figure 3-4: Simulink CIC Filter Implementation Results 3.4 SDM Settling Time 3.4.1 this value is Although an estimate for SDM settling time was obtained in the lab, somewhat unreliable due to the resolution limiation of the instrument used. However, a more accurate settling time value can be obtained through simulation. to observe a It is difficult to measure the settling time of the SDM because it is hard settling behavior from an output that is strictly digital in the time domain. However, block. Such this problem can be remedied by replacing the quantizer with a gain of the SDM replacement is valid since the quantizer does not affect the dynamics the quantization loop but simply adds noise. This replacement effectively removes noise, making it possible to observe and measure the settling behavior. from negative Figure 3-6 shows the settling of the SDM when the input transitions approximately rail to positive rail. Although a quick transition occurs in the output from low to high, (sim(6samples) - ( 1second );t~ 19ps after the input transitions ilar to - for quite 20ps observed in the lab), the plot shows that the output oscillates CePt sin(wt - a). a while longer. The oscillation is a decaying sinusoid in the form of of the SDM Based on the simulation results, the oscillation exhibited by the settling 44 GD- quantizer replaed by 5DM hn Outi - -t Mn2 Outi SDM Out 1n2 Stage I Sten Figure 3-5: Modified SDM Block Diagram IIput SDIF SDK Output 2 0 -1 4.8 4.801 4.802 4.803 samples~n] 4.804 Figure 3-6: SDM Settling Response 45 4.805 x 10' f, was found to decay at the rate expressed by Equation 3.1, where is the sampling rate of the SDM. x(t) = 7.38.- e~0 37 f-,(3.1) This decay is shown in Figure 3-7. - SDM Output 5---- 4 - 0- 5 10 15 20 25 30 samples (n) 35 40 45 50 Figure 3-7: Decay of the SDM output oscillation In order to determine the exact settling time of the SDM, it is important to first come up with an accurate definition for the SDM settling time. For this analysis, SDM settling time will be defined as the amount of time it takes for the SDM output to reach a value that is within 2 -- LSB (least-significant-bit) of the output of the ADC when the input transitions from negative rail to positive rail. The half-LSB value is calculated as (*sitg" 2 where Bout is the number of bits at the ,iloltage), ADC output (which is not necessarily ENOB). Using this definition and Equation 3.1, the settling time of the SDM can be estimated for various ADC output widths. Table 3.1 summarizes this information. In Table 3.1, the upper bound for ADC output width is set rather generously at 30 bits. Thus, this entry is labeled "Max", and the corresponding settling time value will be considered the maximum settling time of the SDM. 46 Output Width 14 15 16 17 18 19 20 Max (30) Settling Time (ps) 266.9 282.8 298.6 314.4 330.2 346.0 361.8 520.0 Table 3.1: SDM settling time for various output widths 3.4.2 ADC Performance Data Evaluation Approach In order to evaluate the performance of the ADC, all the raw time-domain data needs to be represented in the frequency domain in the form of power spectral density (PSD). To obtain the PSD, the matlab function PSD was used. The PSD function basically takes the FFT of the specified data sequence and returns the squared magnitude of the result. Unless otherwise specified, each data sequence was obtained by running the simulation for one second. Because the length of the data sequence is finite (and rather short), running an FFT directly on such a sequence is the same as windowing the sequence with a small rectangular window. This type of windowing is undesirable, since the high side lobe amplitude of the rectangular filter in the frequency domain compromises the PSD resolution. Thus, prior to running the PSD function on any data sequence, the data was first windowed by a Blackman window of the same length as the data sequence. While a rectangular window has a side lobe amplitude of -13dB relative to its peak, the Blackman window side lobe is -57dB, providing a higher resolution PSD [4]. The number of points in the FFT also matches the number of points in the time-domain data. Performance Before evaluating the performance of the CIC filter and the overall ADC simulation design, the correctness of the SDM simulation model must be verified. In order to 47 was obtained for the verify the correctness of this model, SDM signal-to-noise ratio shows the PSD of the case when an ideal 100Hz brickwall filter was used. Figure 3-8 wave. SDM output when the input is a 5Hz, 4V peak-to-peak sine 10, 10 10-2 10-4 -- 10 10 1010 10-12 10~1- 10' 10 10 10 10P log frequency (Hz) 106 106 10 Figure 3-8: SDM Simulation PSD 0Hz and 100Hz In order to obtain the SDM signal-to-noise ratio, the noise between shown in Figure 3-8 due must be integrated. Since there is a spike at 5Hz in the PSD out-of-band signal and to the signal, noise power is actually obtained by injecting an SDM using this method integrating the PSD in the band of interest. The SNR of the section, and very is -95dB, which is similar to the -97dB calculated in the analysis measurement. close to the -94dB value which was measured in a previous laboratory result is much The 2dB difference between the analysis result and the simulation for the additive-whitesmaller than the 14dB SNR overestimation Hauser reports The reason for such a noise model in the case of second-order noise shaping [8]. quantization but rather small discrepancy is that the dominant source of noise is not that the Simulink model thermal noise. Based on these results, it is safe to assume accurately emulates the actual SDM. CIC filters Since the analysis in the previous section showed that the lowest-order with N = 3 and R have the smallest settling time, the overall design was simulated 2.1. Figure 3-9 shows a at the values calculated for various ENOB shown in Table 48 sample output of the sigma-delta ADC for a 5Hz, 4V peak-to-peak input, with R and N set at 1171 and 3, respectively. 1.5} 0.5 > 0 -0.5 -1 -1.5 0 50 100 150 Samples (n) 200 250 300 Figure 3-9: ADC Output for 5Hz sine input Figure 3-10 is the PSD of the plot shown in Figure 3-9. In order to determine the SNR of the ADC output, a ratio of the signal power and the noise power was taken. For signal power, the peak of the PSD plot that results from having the sine wave plus the thermal noise as input, such as Figure 3-10, was used. Noise power calculation requires integration of noise over the entire spectrum. In order to do this integration without the interference of the input signal in the PSD, the ADC model was stimulated with only thermal noise as input. The PSD of the resulting output was integrated and used as noise power. Figure 3-11 shows such a PSD. Table 3.2 shows the results of the simulation using the aforementioned method. Simulation of the last two R-N pair in the table were run for 5 seconds instead of 1 second in order to collect enough data points to produce a PSD with good resolution. As the table shows, the SNR and the ENOB obtained from simulation is very similar to the values obtained from the analysis, with the average discrepancy between the simulation and the analysis being approximately 1 to 2 decibels. This small discrepancy is most likely due to the fact that in Section 2.1.1, quantization noise 49 102 100 10-2 10 CD 9I I10, 10 -10 1012 10- ''' 14 lc 101 102 ' ' 103 log frequency (Hz) Figure 3-10: PSD for ADC output with 5Hz sine plus thermal noise input 10 10-2 10-4 10 10' 10"0 10 1014 10 " 102 10' log frequency (Hz) I e Figure 3-11: PSD of thermal-noise-stimulated ADC output N 3 3 3 3 3 R 243 387 1171 5587 12550 SNR 89.31 91.30 96.16 103.14 105.75 ENOB 14.54 14.87 15.68 16.84 17.27 Table 3.2: Simulation summary for a 5Hz, 4V peak-to-peak sine input 50 was approximated as being white. Because the CIC filter design is ideal, it does not add to the discrepancy between the analysis and the simulation. Figure 3-12 shows the ADC output when four DC inputs of -2V, -IV, IV, and 2V are multiplexed and switched at 20Hz, with R = 1171 and N = 3. While the multiplexer switching rate allows the ADC output 50ms to settle, Equations 2.35 and 2.37 show that the settling time of this ADC is only [okHZ)- (1170) - (3)]2 + (298.6ps) 2 11.0ms. Thus, it can be seen from the figure that the output correctly reflects the multiplexed input signals. 2.5 2 1.5- 0.5- 0 > -0.5 -1 -1.5 -2 -2.5 0-. 5 J 100 S 0 samples (n) 200 250 300 Figure 3-12: ADC output with multiplexed inputs The Simulink simulation results verify that the calculations shown in the analysis section do indeed closely model the behavior of the ADC. In the next section, the implementation of the CIC filter in hardware will be examined. 51 Chapter 4 Simulation of the Hardware Using VHDL Some parts of the sigma-delta ADC, most importantly the CIC filter, are implemented in hardware by programming a field-programmable gate array (FPGA) using VHDL (VHSIC Hardware Description Language). Thus, in order to more accurately predict the behavior of the sigma-delta ADC as implemented in hardware, a VHDL test bench was constructed to simulate the most realistic design of the CIC filter. This chapter discusses the design of the VHDL test bench, performance of the hardware implementation of the CIC filter, and guidelines for designing the desired hardware. It concludes with an analysis of synthesis and power consumption. 4.1 Overview of the Test Bench The main purpose of the VHDL test bench is to create a simulation environment that can accurately measure the performance of the CIC filter implemented in VHDL. Because the behavior of the actual hardware implemented using FPGAs exactly matches that of the VHDL simulation model, a synthesizable (that is, realizable in hardware) CIC filter model coupled with a realistic test bench allows one to accurately characterize the behavior of the overall ADC hardware. Synthesis will be discussed in more detail in a later section. All simulation was done using ModelSim version 5.3a. 52 FPGA sdmclock TFGTIM STARTUP RESET T I TIMING astcic .. clock slo w-c dc _c1 ocR INTERFACE COMPSDM sdmxo t COMPCIC 2/ mux_select PRN thermal_ oise Figure 4-1: VHDL Test Bench Block Diagram 53 -icout --- Figure 4-1 shows the block diagram of the overall test bench. As the diagram shows, some components are part of the hardware implemented using an FPGA, while other components are ADC hardware outside of the FPGA. However, all components are coded using VHDL in order to create a homogeneous test bench environment. The component TFGTIM simulates various clock signals. The component TIMING, which is part of the FPGA hardware, takes in external clock signals and generates various new clock and strobe signals to be used within the FPGA. The block labeled STARTUP-RESET handles the proper initialization of the FPGA upon powering up. The block INTERFACES, also part of the FPGA, mainly serves to communicate the data generated in the FPGA with various outside components. It is also responsible for generating the multiplexer select signals for the input multiplexer. The rest of the components will be discssed in greater detail in the following sections. 4.2 Thermal Noise Blocks Figure 4-1 shows a block labeled PRN, which stands for pseudorandom number. This block is responsible for simulating thermal noise which is to be injected at the input of the SDM. Unlike Simulink (i.e. Matlab), VHDL does not have a built-in random number generator. Two approaches were examined in order to provide the VHDL model with a realistic thermal noise source. First approach was to simply generate a Gaussian noise sequence using Matlab, write to a file, and create a VHDL block that reads and incorporates the data into the model at the appropriate clock edges. The source to this approach, read-prn.vhd, can be found in Appendix B.1. One advantage of this approach is that the same algorithm for random number (noise) generation is used in Simulink, thus introducing fewer inconsistencies between the Simulink and the VHDL models. Another advantage is that minimal computation is needed for generating noise, allowing the simulation to run fast. A major downside to this approach is that the simulation is always dependent on the random noise file it reads from. For example, running an extremely long simulation would require an extremely long data file which is large and thus 54 cumbersome to work with. Also, there is the general inconvenience of creating a noise file outside the homogeneous VHDL simulation environment. The second approach was to implement a pseudorandom number generator algorithm directly in VHDL. Gaussian random number sequences are typically generated by first obtaining uniformly distributed random number sequences using one algorithm and mapping them to a Gaussian distribution using another algorithm [9]. One of the simplest of such mapping algorithm is the summing of a large number of independent uniformly distributed random numbers, for the central limit theorem states that such a sum has a Gaussian distribution [10]. However, it was initially decided that a simple, uniformly distributed random number sequence would be used for thermal noise simulation. The reason for this decision was that Simulink simulations showed minimal difference in ADC signal-to-noise ratio when a uniformly distributed noise sequence was used as opposed to a Gaussian sequence as long as the variance and the mean of the two sequences were identical. For the uniformly distributed noise sequence, a shift-register-based pseudorandom number algorithm was selected because of the availability of some previous work. The algorithm used is similar to the R250 algorithm developed by Kirkpatrick and Stoll [11]. 000 30 2928 27 260 Direction of Shift 1 0 sdmclo Figure 4-2: Shift-Register-Based Pseudorandom Number Generator As Figure 4-2 shows, the 29th and the 26th bit of a 31-bit shift register is XORed and then fed back into the shift register as the least-significant-bit (LSB). The code for this block, prn.vhd, is found in Appendix B.2. Figure 4-3 shows the PSDs of the noise generated by both methods. 55 1.2 I-read .pm.vhd P.vh.J 1 0.8 i.0.6 0.4 0.2 00 0.5 1 2 1.5 frequency (rad) 2.5 3 3.5 Figure 4-3: PSDs of simulated thermal noise using prn.vhd Although the PSD of a white noise sequence should be flat across the entire spectrum, Figure 4-3 shows that this flatness is not exhibited when using prn.vhd, with some non-ideal behavior in the low-frequency region. This low-frequency nonideality is significant, since it is the thermal noise at low frequency that limits the ADC performance. In order to resolve this problem, prn2.vhd, a modified version of prn.vhd, was created. In this model, six shift registers are used to generate six independent uniformly distributed random numbers. Each shift register is initialized with the same starting value, but different bit locations are XOR'ed and fed back. The choice of the bit locations for the XOR operation is extremely important, because for a given shift register initialization value, choosing certain bit locations will result in a cyclic pattern that gives a much worse PSD than the one shown in Figure 4-3. Once they are generated, the six random variables are summed together. The main purpose of this summation is not to create a Gaussian sequence (although the summation will have such an effect) but rather to enhance the randomness of the thermal noise sequence. Before using this sum as the noise sequence, the sum of uniform random numbers must be calibrated in order for it to have the desired variance. The easiest way to calibrate is to first obtain the uncalibrated variance, u2, and multiply the sum of uni56 form random numbers with 1h, where (Equation 2.29 shows the a-2h e-th is the square root of the desired variance value used for this particular SDM). Figure 4-4 shows the output of prn2.vhd described above. As the figure shows, the PSD is flat throughout the spectrum and matches closely with the PSD of the output of read-prn.vhd. Simulations have shown that the two models have nearly the same effect on the ADC output. The code for prn2.vhd can be found in Appendix B.3. X1 O- -- pm2.vhd read pm.vhd 0.9. 0.8 0.70.6- 0.5 0.40.3 0.20.10 . 1 2 15 . 3.5 frequency (red) Figure 4-4: PSDs of simulated thermal noise using prn2.vhd 4.3 VHDL Implementation of the SDM The sigma-delta modulator block, COMP.SDM in Figure 4-1, is the VHDL implementation of the digital approximation of the actual SDM chip used in Simulink. However, the COMPSDM block, shown in greater detail in Figure 4-5, also contains some extra functionalities. As shown in Figure 4-5, all test input signals, such as sinusoids and constants, are generated inside the COMP-SDM block. In addition, the block contains a multiplexer, which selects the appropriate input signal as determined by the select bits it takes as input. The selected signal is then summed with the thermal noise the block also takes in as input, and this sum is fed into the input of the SDM. 57 COMP_SDM sdmclock k mux -- select SDM -- sdmout 2 thermal_ noise- Figure 4-5: Block Diagram of COMPSDM It is important to note that values are represented with far less precision in VHDL compared to Matlab and Simulink (32 bits vs. 53 bits). For this reason, great care must be taken in order to ensure that the inherent noise in the VHDL-generated signal, such as sinusoids, is significantly less than other simulated noise sources (in this case thermal and quantization noise). For sinusoids, two factors seem to affect the amount of noise in the VHDL-generated signal. Assume that the following lines of pseudocode was used to generate a sine wave with an amplitude of 2 in VHDL. count=O; period=2*pi/x; if rising-edge(clk) then sin_input=2*sin(count*period); count=count+1; end if; where sinO is the built-in VHDL sine function. Given the above code, one factor that affects the noise level in the generated sine wave is the choice of x. If x is chosen such that the frequency of the sine wave is not an integer value, the noise level of the sine wave becomes excessively high. Figure 58 4-6 shows a comparison of VHDL-generated sine waves with integer and non-integer frequencies. -- 5Hz Sine Wave Sine Wave -5.051Hz 100 10-5 10-'0 10' 20 IT~ 10-251 10-5 I 10, 10 -3 10 10 10010 log frequency (rad) Figure 4-6: VHDL-generated sine wave with a non-integer fundamental frequency Another factor that affects the noise level in the VHDL-generated sine wave is the resetting of the variable count. If this variable is reset after each period of the sine wave (perhaps to limit the amount of memory committed to this variable), a significant amount of noise is introduced. This observation is shown in Figure 4-7. Avoiding both of these issues, sine wave with a sufficiently low noise noise floor can be obtained. Figure 4-8 compares such a sine wave with a Simulink-generated sine wave. As the figure shows, while the Simulink-generated sine wave has a lower noise floor, the noise level of the VHDL-generated sine is low enough to prevent the masking of other noise sources. The performance of the VHDL SDM was determined by evaluating how closely the design matched the Simulink version of the SDM. As Figure 4-9 shows, when the input to the SDM is a sine wave plus thermal noise, the PSDs of the VHDL and Simulink SDM outputs matched closely. In order to further compare the two designs, the output of the VHDL SDM was written to a file and read into the Simulink CIC filter. The SNR of the CIC filter output typically did not vary more than a few decibels bewteen the two SDM models, verifying that the Simulink and the VHDL 59 10P count not reset count reset 10 - 10I, n. 10 io-20 '1' 10 0- 104 10 -3 10 10 log frequency (rad) 10 10 Figure 4-7: Effect of resetting the variable count 10 . VHDL Sine Wave Simulink Sine Wave - 10-5 10-10 N 0 10-' 1C- 0 [ 10 10 10 ' 10 ' '''' ' -' -' 10, 10 ' 10 log frequency (rad) ' '0'] '' 10~ 10 10 Figure 4-8: Comparison of VHDL- and Simulink-generated sine waves 60 -N test benches had virutally identical SDM models. Figure 4-10 is a PSD plot of the Simulink CIC filter output (R=1171, N=3) when the input is the output of the Simulink and the VHDL SDM model. The code for COMPSDM, compsdm.vhd, can be found in Appendix B.6. 10* -VHDL SDM 1Simulink SDM 10 - 10 - 0 10 10 10 1010 10 10 log frequency (rad) Figure 4-9: PSD of the VHDL and Simulink SDM outputs 4.4 VHDL Implementation of the CIC Filter In the previous sections, an ideal CIC filter model was analyzed and simulated. This model did not take into consideration finite hardware and other implementation issues. The VHDL model, however, is the exact representation of the actual hardware. In the following sections, new issues arising from implementing the filter in hardware and the filter performance will be examined. 4.4.1 Architecture Figure 2-5 from Section 2.2.2 shows the block diagram of the CIC filter originally introduced by Hogenauer [5]. The actual architecture of the CIC filter implemented in VHDL, however, is slightly different from this model. The block diagram of the implemented filter is shown in Figure 4-11. 61 - FRIM!M5 - -- - - ---- - R=1171, N=3 I 10 Using SimulinkSDM -Using VHDL 5DM I 10 10 101 ' ' ' '' 10t 10 les 10 log frequency (f) Figure 4-10: PSD of the Simulink CIC filter output when using different SDM models Stage 2 Stage 1 Stage 4 Stage 3 -1 sdmz~ izfi Stage 5 -1 Stage 6 -1 cic_out - -E -40Z-1 fS R Figure 4-11: Block diagram of the CIC filter implemented in VHDL 62 R The reason for the modification is that the new design introduces a shorter critical path in the integrator section. As Figure 2-5 shows, the original design has a signal propagation path that spans three adders. By moving the registers to the new location shown in Figure 4-11, the length of this path is reduced by a factor N, where N is the filter order. This modification is beneficial because it allows the filter to have a higher limit in terms of operating frequency. The 3-adder signal propation path in the comb section is less of a concern, since this section runs at a significantly lower frequency. The aforementioned architectural modification changes the system function of the filter. Hi(z), the system function of a single integrator stage, now becomes y[n] = x[n - 1] + y[n - 1] Hi(z) = X(z) Y(z) - - Z-1 1-Z(4.1) 4.1 This modification changes the overall CIC filter transfer function to H (z) = HIN(z) . HCN(z) z- = Z-k -N [ 1 )N. (1 - z-R)N N (4.2) lk=0 Figure 4-12 shows the magnitude response of both the original and the modified CIC filter architectures. As the figure shows, the frequency response of the two architectures is virtually identical. In addition, it can be seen from Equation 4.2 that the settling time of the new design is longer by N - (f. is the fast sampling frequency of the filter), resulting in the following expression for settling time. 1 tfil = (N - (R - 1) + N) - -=N - R. - -(4.3) (43 Since R is usually much larger than N, this increase in settling time compared to the original design is negligible. Adding in the maximum SDM settling time determined 63 1010 - CICFilter F Moifie riginal CIC Filter 10 110 E -s1 1CF10 10 -15L 'l. 5. 10~ - I .. 104 ..... ..... ----.....----I ----------...... ----- ... 10 10 I log frequency (rad) 10P 101 101 Figure 4-12: Magnitude Response Comparison in Section 3.4.1, the overall settling time of the ADC can be approximated as tadc= 4.4.2 N- R ) 2 + (4.4) (520S)2 Register Sizing In the CIC filter model used in Chapter 2 and Chapter 3, delay components of infinite precision were used for integration and differentiation. However, in the actual hardware, such delay components must be replaced with registers. The appropriate width of the registers in each stage is determined by the filter's maximum register growth, which is defined as the maximum output magnitude resulting from the worst possible input signal. This value is the same as the gain of the ideal CIC filter, which is Gmax = H (ew)( = RN = [z-k k=0 (4.5) z=1 Given this gain value, the width of the register must be set such that there is no register overflow. If Bin represents the number of bits at the input, Hogenauer defines 64 Bmax, the most-significant-bit (MSB) of the register in each stage, as Bmax = [N- log2 R + Bi - 1] (4.6) The LSB of each register is bit number 0, making the width of the registers Bmax +1. It is of critical importance that the register width, especially at the first stage, is set to Bmax +1. Overflow occurs if the register width at the first stage is set at a value less than Bmax + 1, which introduces a significant amount of error. If the register width is set at a value greater than Bmax +1, the higher-bit registers do not fill up. Since the output of the filter is the top Bout MSBs of the last comb stage (where Bout represents the number of output bits of the ADC), not all of the available bits get used, significantly reducing the maximum SNR of the ADC. In [5], a method of reducing the total number of registers in the hardware is discussed. This method is centered around the idea that since Bmax + 1 is typically much larger than Bout, there is always some truncation that occurs at the last stage of the filter. Since this truncation will introduce some error, the intermediate stages of the filter can truncate their registers to a point that the sum of truncation errors at the intermediate stages does not exceed the last-stage error. The number of bits that can be truncated from each stage, Bj, is calculated as follows. Assuming that truncation at each stage produces white noise, the variance of the error at stage j is !( 2 B3 )2 ? (4.7) 12 The statistics at the output due to the jth error source is dependent on hj(k), the system function of the filter from the jth stage upto the last stage. The impulse response coefficients correspond to independent random processes that are summed to produce one output. Thus, the variance due to the kth coefficient in the jth stage is simply uah?(k), and the total error variance at the jth stage, 17,1is 2 =c F2 T, j . 65 (4.8) where F is Jh2(k), j =1, 2, . .. , 2N F = (4.9) k 2N + I 1,7 Stage 2N + 1 refers to the Bout-wide output register stage that follows the last comb stage. hj(k) is defined as ( N) [klR hj (k) = N -j + k - RI E (-1)1 1=0 ( k - R1 (4.10) , , 2N +1-j k j=N+1,..., 2N As mentioned earlier, Hogenauer in [5] makes the design decision that the truncation of intermediate stages is done such that the sum of their errors does not exceed that of the last stage. This decision is expressed through the following inequality. a, _< ) (4.11) , j = 1,2, .. ., 2N 2N' When substitutions are made with Equations 4.7 and 4.8, Bj, the number of bits of truncation allowed at each stage, can be solved as 16 B = -log 2 Fj + log 2 T 2 N+1 + (4.12) 102 The Matlab script cic-filt-spec.m, found in Appendix A.2, automatically solves for B, given Bi., Bout, R, and N. Table 4.1 shows the reduced register widths for R and N values used for the Simulink model simulation. Register Width Bi 1 1 1 1 Bout 14 15 16 17 R 243 387 1171 5587 N 3 3 3 3 Stage 1 25 27 32 39 Stage 2 25 27 32 37 Stage 3 21 22 24 26 Stage 4 18 19 20 21 Stage 5 17 18 19 20 Stage 6 16 17 18 19 Table 4.1: Register widths for R and N values used in the Simulink model 66 4.4.3 Performance The performance of the VHDL ADC model was tested by duplicating the setup used in the Simulink simulation. A 5Hz, 4V peak-to-peak sine wave summed with the simulated thermal noise was used as input, and PSD of the output of the filter was used to evaluate the SNR. As mentioned in Section 3.4.2, the SNR of the Simulink ADC model output was determined by taking a ratio of two values: the peak of the ADC output PSD with sine wave plus thermal noise as input, and the integral of the ADC output PSD with the input simply being the thermal noise. This method was valid with the Simulink model because the output PSD generated with only thermal noise as input accurately reflected the noise floor of the case where the input is the sine wave plus the noise. However, duplicating this method of obtaining the ADC SNR with the VHDL model produces extremely unreliable SNR values. The error arises from the fact that the thermal noise signal amplitude is far smaller than the amplitude of the input signal and thus does not fill up the registers representing bits of higher significance. Since truncation of registers removes the LSBs of each stage, which are used to distinguish one thermal noise sample from another, much accuracy is removed from the representation of thermal noise with truncation. This reduction of accuracy results in a PSD that does not match with the noise floor of the signal-plus-noise PSD. Figure 4-13 illustrates this point. Because of this problem, the noise power of the VHDL ADC output is estimated in a different way. As the signal-plus-noise plot in Figure 4-13 shows, the effect of the smearing of the spike respresenting the signal power becomes unnoticeable in higher frequencies, allowing one to clearly determine the noise floor. Since the noise floor level is constant over all frequencies (as shown by Simulink simulations), the noise power was calculated by averaging the signal-plus-noise PSD in the region unaffected by the smeared spike and then multiplying this value by the output bandwidth. There is one limitation with this method. As R increases, the cutoff of the filter gets closer to the spike representing the input signal. Eventually, it will reach a point where the 67 R=1171, N=3 16, -signa-plus-noise 102 10, 1010-a 10 10 101 102 log frequency (f) Figure 4-13: Thermal noise - noise floor mismatch in VHDL Nyquist frequency of the ADC output overlaps with the region that is still affected by the smearing of the spike, masking the true noise floor. Thus, an evaluation of SNR for high R cases would require very long data sequences that can be acquired much more easily with actual hardware rather than simulation. For this reason, SNR of the filter output with R=5587 and up were not evaluated. Truncation All Stages Last Stage No Stages Simulink R=243 80 80 87 89 R=387 84 85 90 91 R=1171 89 90 95 96 Table 4.2: Approximate VHDL ADC signal-to-noise ratio in dB, N=3 Table 4.2 shows the result of simulating with the same R and N values used in the Simulink simulation. SNR values were obtained for the cases where no truncations are made, truncation is made only at the last stage, and truncations are made in every stage according to the calculations shown in the previous section. The data reveals the following points: As long as the last stage is truncated, truncating the registers in the intermediate stages has no adverse effect (verifying the validity of the design decision made 68 in the previous section). * The VHDL model results match that of the Simulink model if no truncation of any kind are made. * Truncation of the last stage severely degrades the ADC SNR. Although truncation at the last stage reduces the SNR significantly, it cannot be avoided since the number of bits at the output of the ADC, B0,±, will always be smaller than Bma, + 1, the width of the first stage of the CIC filter. Thus, the approach to obtaining R and N values for the desired ADC SNR must be modified. The following section analyzes truncation noise and discusses design guidelines for implementing the CIC filter in hardware. 4.5 4.5.1 Design Guidelines Truncation Noise Analysis Because the VHDL implementation of the CIC filter introduces the new issue of truncation, the approach to design and metrics for performance must be modified accordingly. However, in order to revise the design approach, the effect of truncation must first be analyzed. As shown in the previous section, avoiding truncation at the output allows the VHDL simulation model performance to match that of the Simulink model. However, as the LSBs of the output get truncated, additional noise is introduced. As mentioned in Section 4.4.2, this noise can be modeled as uniformly distributed white noise. Figure 4-14 illustrates the noise distribution. The value Bt shown in the figure is the number of bits truncated. Given this figure, the variance of truncation noise o and the mean of the truncation noise Mtn are 1 a42 = tn 12 69 (2 Bt)2 (4.13) P (e) 1/2 Bt e 2 Bt Figure 4-14: Distribution of truncation noise and n = 1 2 -- (4.14) respectively. These values can be used to obtain Pt, the truncation noise power. P = 1-( = Or2 + m2 1 + 2 Bt)2 Bt 2 2 2Bt -3 (4.15) In order to calculate SNRtn, the signal-to-truncation-noise ratio, Pig, the signal power at the CIC filter output, must be calculated. Assuming that the input is a sinusoid with an amplitude of A, its power can be calculated as follows. Psi9 = A (R). 2 ,2 ]2 (4.16) The expression inside the brackets of Equation 4.16 is the root-mean-squared voltage of the sinusoidal input signal multiplied by the filter gain. The gain value in this expression is RN instead of RN because this gain is applied to the positive and the negative amplitude, resulting in an overall gain of RN. In the case that A = 2V, which is the value used in the simulations, Pi9 = I2 - R 2 N Before combining Pi 9 and Pt to determine the expression for SNRtn, one substitution must be made. Given Equation 4.6, Bt can be expressed in terms of R, N, 70 and Bout, the number of bits at the output of the ADC. Bt = Bmax + 1- Bout = [N log 2 Ri + 1 - Bout (4.17) Combining the above equations results in the following expression for SNRt" (for a sinusoid with an amplitude of 2). SSNRnotruc, SNR1 = l 10 - log1 I.*22([N 1092 R+1-BoUt) )2N , Bt = 0 (18) .W. SNRnotrunc represents the SNR of the ADC when no output bits are truncated. This value is identical to the SNR that would be attained in the Simulink model given the same R and N. It must be noted that SNRtn is always less than SNRnotrunc. It is also important to note that, based on the findings in the previous section, Equation 4.18 is applicable not only to the case where the truncation occurs only at the output, but also to the case where truncation is done at the intermediate stages. 4.5.2 Approach to Design With the ideal CIC filter model examined in In Chapters 2 and 3, an SNR value corresponding to the number of bits at the output of the ADC was obtained using the definition of ENOB (effective number of bits) shown in Section 1.3. Using this SNR value, which represents the highest achievable SNR for the given number of bits at the ADC output, the filter parameters R and N were calculated. This is a good approach in the ideal case since the ENOB definition gives a good starting point for design, and the resulting design is always optimal. When truncation is involved in the design, however, this method can result in suboptimal filter parameters. The reason for this is that for a fixed Bout, the number of bits truncated, Bt, changes as the filter parameters change. That is, truncation noise is a noise source that depends on both the output width and the filter parameters. 71 Because of this dependency between the output width and the truncation noise, the noise level in the output can actually go up as the filter parameters are increased (noise level always goes down in the ideal model if the filter parameters are increased). Thus, in most cases, the SNR corresponding to a particular ENOB cannot even be obtained. In addition, although equal filter parameters guarantee equal output SNR regardless of the output width in the ideal model, this is not the case when truncation noise is involved. A wider output can have a higher or lower SNR than a narrower output. Considering these facts regarding the truncation noise, a better design approach is to start with a target ADC output SNR and choose the lowest filter parameters that will satisfy the SNR requirement, regardless of what the output width may be (unless it is unreasonably large for a particular application). By doing this, it will be guaranteed that the hardware size as well as the filter settling time will be minimized. Table 4.3 can be used as a guideline for a third-order filter (N=3) with a 5Hz, 4V peakto-peak sinusoid as input. The values were obtained using Simulink for SNRnotunc and Equation 4.18 for the various values of Bout. Settling time was obtained using Equation 4.4. R 300 600 900 1200 1500 2000 3000 4000 5000 Bma + 1 26 29 31 32 33 34 36 37 38 Settling Time (ms) 2.803 5.615 8.428 11.241 14.053 18.741 28.115 37.491 46.866 14 78.1 78.1 76.7 78.1 77.9 79.4 77.9 79.4 79.2 SNR 15 84.2 84.2 82.7 84.2 83.9 85.4 84.0 85.4 85.2 for Various B,t (dB) 16 17 18 19 90.2 91 91 91 90.2 93 93 93 88.7 94.7 95 95 90.2 96 96 96 90.0 96.0 97 97 91.5 97.5 99 99 90.0 96.0 101 101 91.5 97.5 102 102 91.2 97.3 103 103 20 91 93 95 96 97 99 101 102 103 SNRnotrunc (dB) 91 93 95 96 97 99 101 102 103 Table 4.3: SNRtn for 5Hz, 4V peak-to-peak sinusoid input, N=3 Extensive simulation in VHDL has shown that the truncation noise analysis detailed thus far matches closely with the actual VHDL model. Figure 4-15 plots the SNR predicted by the truncation noise analysis and the actual SNR obtained from VHDL simulation for a CIC filter with R=900 and N=3. 72 R=900, N=3 1001 . -- - -- -- - -- - - - - 95 - .- -- - -- --.- --.- - -- - 90- 5 -85- 80- 75 - d[ed- ... actual!f 14 15 16 17 Bout is 19 20 Figure 4-15: Comparison of the predicted and actual output SNR for R=900, N=3 4.5.3 Multiplexing The method for selecting a filter design that is optimal in terms of settling time is simple: choose the lowest R and N that will provide a satisfactory SNR. The number of bits at the output and the size of the hardware after truncation of LSBs in every stage does not affect settling time. From Table 4.3, it can be seen that for a given R, much flexibility is provided in terms of setting the output SNR by the means of truncating different number of bits at the output. This fact makes it very natural to use multiplexing rate as the starting point of CIC filter design. In order to design a filter that would satisfy a certain multiplexing rate, the following steps can be taken. 1. Using Equation 4.4, Determine the highest R and N pair that will satisfy the multiplexing rate specification. 2. Using either the analysis shown in Chapter 2 or the Simulink model, determine SNRtrunc associated with the chosen R and N. 3. Using Equation 4.18, determine Bout by truncating until SNR becomes affected. 4. Using the R, N, and Bout values, truncate intermediate stages following the 73 analysis in Section 4.4.2. Following these steps guarantees mimimum hardware for the highest attainable SNR for a given multiplexing rate. 4.6 4.6.1 Synthesis of VHDL Code Synthesizability and Power Consumption In order to successfully create the desired hardware using FPGAs (Field Programmable Gate Array), care must be taken in writing the VHDL code such that only the synthesizable constructs are used. In order to verify the synthesizability of the VHDL CIC filter code, the logic synthesis tool Synplify was used. This tool not only verifies the synthesizability of a design but also gives details regarding the size and the composition of the hardware. In order to compensate for the fact that the final design may run at a system clock frequency that is higher than 4Mhz, the VHDL CIC filter code was synthesized for a clock frequency of 6Mhz. With this specification, Synplify was able to successfully synthesize the VHDL CIC filter code comp-cic.vhd for the Xilinx XCV200E FPGA that is used for the inertial instrument electronics. Using the hardware information provided by Synplify and a power estimation tool provided by the Xilinx web site, the effect of changing certain filter parameters on power consumption of a third-order CIC filter was examined. One experiment was to set R at 900 and measure power for output widths ranging from 14 to 20. The other experiment was to set the output width at 18 and varying the R from 300 to 5000. Tables 4.4 and 4.5 summarize the results provided by the power estimation tool. It can be seen from Table 4.4 that changing the output width has a minimal effect on the power consumed by the filter. The small variation in the filter power is made even less significant when considering the fact that the quiescent power of the FPGA is approximately 29mW. From these results, it is safe to conclude that power need not be a concern when opting for a wider filter output. 74 Bout 14 15 16 17 18 19 20 Filter Power(mW) 7 7 7 7 7 8 8 Total Power(mW) 35 36 36 36 36 37 37 Gate Count 3259 3365 3471 3577 3683 3789 3895 Table 4.4: Power consumption for CIC filter, R=900, N=3 Filter Power(mW) R 300 7 600 7 900 7 1200 8 8 1500 2000 8 3000 8 4000 8 8 5000F Total Power(mW) 36 36 36 36 36 37 37 37 37 Gate Count 3463 3603 3683 3723 3763 3823 3903 3943 3983 Table 4.5: Power consumption for CIC filter, N=3, Bout = 18 75 The same conclusion can be made about changing the variable R of the CIC filter. As Table 4.5 shows, increasing the R of the CIC filter from 300 to 5000 causes only a 1mW increase in the CIC filter power, an insignificant value when compared to the total power consumed by the FPGA. Thus, it can be concluded that power consumption need not be a concern when varying the filter parameters within a reasonable range. 4.6.2 Alternate Architecture In Section 4.4.1, it is mentioned that the model shown by Figure 4-11 is the CIC filter architecture implemented in VHDL due to its shorter critical path. However, as long as extremely high clock frequencies are not needed, the original CIC filter architecture shown in Figure 2-5 could be a better option in terms of hardware efficiency. This is due to the fact that the integrator section can be written as a finite state machine (FSM) in VHDL if the longer critical path is allowed. Tests have shown that finite state machines are more efficiently synthesized into hardware compared to a more straight-forward implementation of a sequential circuit. Because the comb section runs at a much slower clock rate, it is already implemented as an FSM. The resulting reduction in hardware could reduce the overall power consumption. The VHDL code for this version of the CIC filter, compcic2.vhd, can be found in Appendix B.5. This VHDL code was successfully synthesized using the same setup as described in the previous section. VHDL simulation has shown that its output is virtually identical to that of the shorter-critical-path architecture. Table 4.6 summarizes the result of synthesis with various R values and B0.t fixed at 18. R 1200 2000 3000 4000 5000 Filter Power(mW) 8 8 8 8 8 Total Power(mW) 36 37 37 37 37 Gate Count 3473 3558 3626 3660 3694 Table 4.6: Power consumption for comp-cic2.vhd, N=3, B,,t = 18 76 As Table 4.6 shows, comp-cic2.vhd does have a lower gate count compared to comp.cic.vhd with identical filter parameters. However, the savings in hardware was not significant enough to show a visible difference in power consumption. Since the savings in power is so small, comp-cic2.vhd may be a better architecture only if FPGA area absolutely has to be optimized. Finally, in order to further optimize hardware, the CIC filter code was written such that the three integration stages would share one adder. However, the overhead involved in sharing the adders made the overall gatecount higher than the gatecount for comp-cic2.vhd. 77 Chapter 5 Conclusion Draper Laboratory's multiplexed-input sigma-delta analog-to-digital converter (ADC) has been examined in this paper. The sigma-delta converter design was first analyzed mathematically in order to predict its performance. A model was then created in Simulink to test the accuracy of the analysis. Finally, a VHDL model was created in order to accurately test the feasibility and the performance of the actual hardware. One important conclusion that can be drawn is that the optimum converter design cannot be obtained by simply increasing all the filter parameters. A careful combination of three ADC parameters, R (the downsampling rate of the digital filter), N (the order of the digital filter), and B0,t (the width of the ADC output in bits), must be selected in order to ensure the best performance with minimum hardware. The analog-to-digital converter performance not only depends on the cascaded integratorcomb filter parameters R and N, but also the number of bits at the output of the filter, B.Ut. The ideal filter model used in Chapters 2 and 3 does not take into consideration that the precision of the storage units used in the filter and the output of the converter are finite. Simulation of the actual hardware in VHDL showed that due to truncation of bits that must occur at the output of the digital filter, optimal signal-to-noise ratio values obtained in the Simulink simulation cannot be achieved with the number of output bits given by the effective-number-of-bits (ENOB) definition. Based on the data collected from the VHDL simulation model, the best approach to designing the digital filter is to decide what the target multiplexing rate is, and then using that 78 value to calculate the filter parameters that provides the smallest hardware. Another important point to note is that when creating a simulation model in VHDL, great care must be taken when simulating signals and hardware that are not part of the final synthesized hardware. For example, because of limited precision, signals such as sine waves must be generated such that the noise caused by limited precision is not greater than other noise that needs to be measured. VHDL simulation data has shown that the ADC created by combining the SD2_ADC sigma-delta modulator with a cascaded integrator-comb (CIC) filter can achieve a signal-to-noise ratio of approximtely 99dB while settling at about 19ms. This settling time would allow four multiplexed ADC inputs to be digitized at 5Hz, which is a satisfactory rate for inertial instrument compensation variables. A signal-to-noise ratio higher than 99dB can be achieved, but increasing the resolution further comes at a significant settling time penalty. The simulation models used in this project have shown that high resolution (~ 100dB) can be achieved at low power (< 20mW) with the current design. However, there are several areas where more work can be done. Analysis has shown that signal-to-noise ratio of the current design is limited most significantly by the thermal noise of the sigma-delta modulator. Due to the significant amount of thermal noise present in the current SDM design, a filter with a large number of taps is required in order to achieve a high resolution. However, finite-input-response filters with a large number of taps take a long time to settle. If higher performance is needed in terms of settling time or resolution, a sigma-delta modulator design that does not use switched capacitors should be considered. Although there are other tradeoffs that could compromise performance, this type of sigma-delta modulator does not suffer from high thermal noise and thus could potentially require filters with smaller hardware. In terms of the simulation model, the current models only simulate quantization and thermal noise. In order to more accurately study the effects of multiplexing inputs, it may be worthwhile to examine noise and settling time associated with the multiplexer. Finally, it may be useful to evaluate the performance of the sigma-delta ADC with inputs that more accurately reflect the actual compensation variables. 79 Bibliography [1] Gustavsson, M., Wilkner, J. J., and Tan, N. N., CMOS Data Converters for Communications, Kluwer Academic Publishers, Boston, 2000, pp. 67-72. [2] van Engelen, J., van de Plassche, R., Bandpass Sigma Delta Modulators, Kluwer Academic Publishers, Boston, 1999, pp. 1-2, 14-15. [3] Norsworthy, S. R., Schreier, R., and Temes, G. C., Delta-Sigma Data Converters: Theory, Design, and Simulation, IEEE Press, New York, 1997, pp. 353-355. [4] Oppenheim, A. V., and schafer, R. W., Discrete-Time Signal Processing, 2nd ed., Prentice-Hall, Upper Saddle River, NJ, 1999, pp. 65-70, 187-213, 471. [5] Hogenauer, E. B., "An Economical Class of Digital Filters for Decimation and Interpolation", IEEE Transactions on Acoustics, Speech, and Signal Processing, Vol. 29, No. 2, April 1981, pp. 155-162. [6] Couch Jr., Leon, Modern Communication Systems: Principles and Applications, Prentice Hall, Upper Saddle River, NJ, 1995, pp. 62-64. [7] Kahaner, D., Moler, C., and Nash, S., Numerical Methods and Software, Prentice Hall, Upper Saddle River, NJ, 1989. [8] Hauser, M. W., "Principles of Oversampling A/D Conversion", Journal of the Audio Engineering Society, Vol. 39, No. 1, Jan./Feb. 1991, pp. 3-26. [9] Schollmeyer, M., and Tranter, W., "Noise Generators for the Simulation of Digital Communication Systems", Proceedings of the 24th Annual Simulation Symposium, April 1994, pp. 264-274. 80 [10] Orfandis, Blah, Blah blah blah blah, Blah Publishing, Blahtown, 19xx, pp. x-x. [11] Kirkpatrick, S., and Stoll E., "A Very Fast Shift-Register Sequence Random Number Generator", Journal of Computational Physics, Vol. 40, 1981, pp. 517526. [12] Ashenden, P. J., The Designer's Guide to VHDL, Morgan Kaufmann Publishers, San Francisco, 1996. [13] Oppenheim, A. V., and Willsky, A. S., Signals and Systems, 2nd ed., Prentice Hall, Upper Saddle River, NJ, 1997. [14] Medeiro, F., Perez-Verdu, A., and Rodriguez-Vaizquez, A., Top-Down Design of High-Performance Sigma-Delta Modulators, Kluwer Academic Publishers, Boston, 1999 81 Appendix A Matlab Scripts A.1 rn-choose.m The script rn-choose.m was used in order to obtain the R and N values for the CIC filter for a specified effective-number-of-bits (ENOB), analog-to-digital converter sampling rate, and sigma-delta modulator order. % rnchoose.m - Script to determine R and N that will satisfy % the SNR requirements for both quantization and thermal 7 noise for the given ENOB. % 4/7/2001 - fixed bug in the signal transfer function. % Steve Park 2/6/2001 clear; . sampling and signal frequency fsamp = 320000; % signal bandwidth fsig = 5; % sample representing signal sig.samp = ceil(fsig/(fsamp/2)*32768); X Specifying ENOB ENOB = 17; % Desired (Equivalent) SNR SNRD = 6.02*ENOB + 1.76; X Specifying order of the SDM sdm-o = 2; snr = 0; 82 X Vector holding the SNR values snrs = linspace(0,0,3); % PSD of quant and thermal noise (variance) delta = 5; % quantization level quantvar = (delta^2)/12; thermvar = (3.98e-12)*(160000); % refer to snrtherm.m for origin of value X signal transfer function stf = abs(freqz([2/5 -1/3], stfsq = stf.^2; [37/30 -13/6 1], 32768)); % noise transfer function ntf = abs(freqz([1 -2 1], [37/30 -13/6 1], 32768)); ntfsq = ntf.^2; % vectors holding 3 R values corresponding to N through N+2 Rs = linspace(0,0,3); w = linspace(0, pi, 32768); %check upto 3 orders higher than SDM order for N=(sdm-o+1):(sdm-o+3), R = 1; snr = 0; snrprev = -1; %variable used to check if SNR decreasing % run loop as long as desired SNR not reached or SNR starts % decreasing with increased R value while ((snr < SNRD) & (snr-prev < snr)) R = R+3; % hsq is the PSD of the CIC filter h = linspace(0, 0, 32768); h(1) = R^N; % correct value for H(e-jw) at w=0 for j=2:32768 h(j) = (abs(sin((w(j)*R/2))./(w(j)/2))).^N; end hsq = h'.^2; % PSD of filtered thermal noise phith = thermvar*stfsq.*hsq; % Power of filtered thermal noise Pth = 2*(1/2/pi)*sum(phith)*(pi/(32768)); 83 % PSD of shaped and filtered quantization noise phiq = quantvar*ntfsq.*hsq; phiq(1) = 0; % to remove NaN at index=1. % Avg. power of quant. noise Pq = 2*(1/2/pi)*sum(phiq)*(pi/(32768)); % hsq at signal freq multiplied by amplitude of sinusoid Ps = 2*hsq(sigsamp); snr-prev = snr; % to check if the SNR is decreasing snr = -1*(10*loglO((Pth+Pq)/Ps)); end snrs(N-sdm-o) = snr; Rs(N-sdm-o) = R end % display signal-to-noise ratio values snrs 84 A.2 cic-..flltspec.m The script cic-filt-spec.m automates the register sizing calculations shown in Section 4.4.2. Approprite register widths are provided for the specified R, N, Bj, and B0 ,, values. % cicfiltspec.m - CIC filter register sizing script % 1/30/2001 - Modified to calculate integrator and comb section % register widths at the same time. % 11/6/2000 - % Given R, N, Bin, and Bout, this script calculates the number '. of LSBs to truncate from each stage of the CIC filter. These % values are stored in the matrix B. clear; R=1171; . specifying R N=3; % specifying N Bin = 1; % specifying Bin Bout = 16; 7 specifying Bout fs = 320000; fd = fs/R; G = R^N; Bmax = ceil(N*log2(R)+Bin-1); 7 Bmax = 26 at R=400, 32 at R=1600 B2np1 = Bmax-Bout+1; %==== Calculating register widths for the integrator section sigma = sqrt((1/12)*(2-(2*(Bmax-Bout+1)))); thatval = log2(sigma) + .5*log2(6/N); B = linspace(0, 0, 2*N); for j=1:N kmax = (R - 1)*N + j- 1; k = linspace(O, kmax, kmax+1); hl = linspace(0, 0, kmax+1); for i = 0:kmax %for k hsum = 0; for 1 = 0:floor(i/R) hsum end = hsum + (-1)^l*nchoosek(N, hl(i+1) = hsum; 85 1)*nchoosek(N-j+i-R*l, i-R*1); end h1sq = h1.^2; Flsq = sum(hlsq); F1 = Flsq^(0.5); B(j) = floor(-l*log2(Fl) + thatval) end %==== Calculating register widths for the comb section for j=l+N:2*N kmax = (R - 1)*N + j - 1; for i = 0:(2*N+l-j) h2(i+1) = (-l)^i*nchoosek(2*N+l-j, i); end This following line is to compensate for the suckiness of % Matlab's nchoosek command. h2((2*N+1-j+1+1):kmax+l) = linspace(O, 0, kmax+1-(2*N+1-j+1)); o/ h2sq = h2.-2; F2sq = sum(h2sq); F2 = F2sq^(0.5); B(j) = floor(-1*log2(F2) + thatval) end Bmax+1 % display widths Bmax+l-B 86 Appendix B VHDL Code B.1 read-prn.vhd read-prn.vhd reads an ASCII text file named thermaLnoise.m which contains thermal noise data. On every SDM clock edge, a sample of thermal noise is added to the input of the SDM. -- readprn.vhd - Reads matlab-generated Gaussian pseudorandom numbers -- from the file thermal-noise.m and feeds it to the SDM modeled by -- comp-sdm.vhd on every SDM clock cycle. smp3454 -2/28/2001 -- library ieee; use use use use ieee.stdlogic1164.all; ieee.std-logic-arith.all; ieee.std-logic-unsigned.all; work.constants.all; use std.textio.all; entity READPRN is port(RANDNUM: out real:=0.0; RESET: IN stdjlogic; SYSCLK: IN std-logic); end READPRN; architecture archREADPRN of READPRN is signal randnum: real:=0.0; signal flag : std-logic := '0'; begin -- archREADPRN RANDNUM <= randnum; 87 ---- This process reads the data file until the end of the file is reached. If the system is reset, the file is reopened and data is read from the beginning of the file again. read-data: process is type real.filetype is file of real; variable open-status: file-open-status; variable tnoise: real; file noisefile: text open read-mode is "thermalnoise.m"; variable L: line; begin wait until SYSCLK = '1'; if RESET='1' then file-open(open.status, noise-file, "thermalnoise.m", read-mode); randnum <= 0.0; flag <= '1'; else if (endfile(noise.file)=false) then flag<='O'; readline(noisefile, L); read(L, t-noise); rand-num <= t-noise; end if; end if; end process; --- Write output to another text file (thermal-noise.rec) in order to make sure the correct values were read in. output-check: process variable buf: line; file fouti: text is out "thermalnoise.rec"; begin wait until SYSCLK='1'; write(buf, rand-num); writeline(foutl, buf); end process; end archREAD-PRN 88 B.2 prn.vhd prn.vhd generates a uniformly distributed random noise sequence using a feedback shift register. ---- prn.vhd - Pseudorandom number generator based on the file prn-gen.vhd created by Dave McGorty. smp3454 -2/27/2001 library ieee; use ieee.stdilogic_1164.all; use ieee.stdlogic-arith.all; use ieee.std-logic-unsigned.all; use work.constants.all; use std.textio.all; entity PRN is port(RANDNUM: out real:=0.0; RESET: IN std-logic; SYSCLK: IN stdlogic); end PRN; architecture archPRN of PRN is signal prn: signed(30 downto 0); -"0101001011110100101111010010111"; signal prnreal : real:=O.0; signal temp-xor std-logic; signal flag : stdlogic := '0'; constant half-delta: real := 0.0014; constant zero_31: signed(30 downto 0) := (others => '0'); constant prnload: signed(30 downto 0) := "0101001011110100101111010010111"attribute attribute attribute attribute syn-preserve : boolean; syn-preserve of prn: signal is true; syn-state-machine : boolean; syn.statemachine of prn: signal is false; begin -- maximal length pseudo random sequence generator -- 31 bit wide RANDNUM <= prn-real; 89 This process shifts the register on every clock cycle and feeds back the XORed value. random.gen : PROCESS BEGIN wait until SYSCLK = '1'; IF RESET = '1' THEN flag <= '1'; prn <= prnjload; ELSE flag <= '0'; IF prn = zero_31 THEN prn <= prnjload; ELSE --- prn <= prn(29 downto 0) & temp-xor; END IF; END IF; END PROCESS; -- XOR 2 bit locations temp.xor <= prn(30) xor prn(27) after 1 ns; -- Converting the signed prn to the appropriate real value with the uniform distribution range of plus or minus half-delta. Multiply real(conv-integer(prn)) with a different value to change -- variance. --- prn.real <= real(conv-integer(prn))*(0.0014/2**30); output-capture: process variable buf: line; file fouti: text is out "prn-out.rec"; begin wait until SYSCLK='1'; write(buf, prn-real); writeline(foutl, buf); end process; end archPRN; 90 B.3 prn2.vhd prn2.vhd generates a pseudo-Gaussian random noise sequence using a sum of six feedback shift registers used in prn.vhd. -- prn2.vhd - modified version of PRN.VHD to fix the non-idealities at low frequencies. Modified using the advice from Prof. Roberge. -- smp3454 -4/16/2001 -- library ieee; use ieee.stdlogic_1164.all; use ieee.std-logic-arith.all; use ieee.stdilogic-unsigned.all; use work.constants.all; use std.textio.all; entity PRN2 is port(RANDNUM: out real:=0.0; RESET: IN stdjlogic; SYSCLK: IN std-logic); end PRN2; architecture archPRN2 of PRN2 is signal prnl: signed(30 downto 0); signal prn2: signed(30 downto 0); signal prn3: signed(30 downto 0); -- signal prn4: signed(30 downto 0); signal prn5: signed(30 downto 0); -- signal prn6: signed(30 downto 0); --- : "0101001011110100101111010010111"; := "0101001011110100101111010010111"; := "0101001011110100101111010010111" -- : : "0101001011110100101111010010111"; "0101001011110100101111010010111"; -- : "0101001011110100101111010010111"; signal signal signal signal signal signal signal signal signal prnreal : real:=0.0; prnone : real:=0.O; prn.two : real:=0.O; prnthr : real:=0.0; prnjfou : real:=0.0; prnrfiv : real:=0.0; prnsix : real:=0.O; prn-sum: real:=0.0; temp.xorl, temp-xor2, temp-xor3, temp-xor4, temp-xor5, temp-xor6: std-logic; signal flag : std-logic := '0'; constant halfdelta: real := 0.0014; 91 constant zero_31: signed(30 downto 0) := (others => '0'); constant prn-loadl: signed(30 downto 0) :="0101001011110100101111010010111"; attribute syn-preserve : boolean; --attribute syn-preserve of prn: signal is true; attribute syn-state-machine : boolean; --attribute synrstate.machine of prn: signal is false; begin -- maximal length pseudo random sequence generator -- 31 bit wide RANDNUM <= prn-real; random-gen : PROCESS BEGIN wait until SYSCLK = '1'; IF RESET = '1' THEN flag <= '1'; prnl <= prn-loadl; prn2 <= prnjloadl; prn3 <= prn-loadl; prn4 <= prnjloadl; prn5 <= prnjloadl; prn6 <= prnjloadl; ELSE flag <= '0'; IF prnl = zero_31 THEN prnl <= prnjloadl; prn2 <= prn-loadl; prn3 <= prnjloadl; prn4 <= prnjloadl; prn5 <= prnjloadl; prn6 <= prnjloadl; ELSE prnl <= prnl(29 downto prn2 <= prn2(29 downto prn3 <= prn3(29 downto prn4 <= prn4(29 downto 0) 0) 0) 0) & & & & temp-xorl; temp-xor2; temp-xor3; temp-xor4; prn5 <= prn5(29 downto 0) & temp-xor5; prn6 <= prn6(29 downto 0) & temp-xor6; END IF; END IF; END PROCESS; 92 ---- The XOR'ed bit pairs for each feedback register is carefully selected such that good random number is generated by each shift register. temp.xorl <= prnl(30) xor prnl(27) after 1 ns; temp-xor2 <= prn2(25) xor prn2(22) after 1 ns; tempxor3 <= prn3(28) xor prn3(25) after 1 ns; temp.xor4 <= prn4(4) xor prn4(26) after 1 ns; tempxor5 <= prn5(27) xor prn5(24) after 1 ns; temp-xor6 <= prn6(24) xor prn6(21) after 1 ns; -- Summing the six random variables and scaling it to have the desired -variance. prnrsum <= real (conv-integer(prnl)+convinteger(prn2)+convjinteger(prn3) +convjinteger(prn4)+conv-integer(prn5)+conv-integer(prn6)) *(7.98e-4/1.1854e9); -- Used prnone prntwo prnthr prnfou prn_fiv prn-six for file output to verify the output quality of each shift register. <= real(conv-integer(prnl))*(0.0014/2**30); <= real(conv-integer(prn2))*(0.0014/2**30); <= real(convjinteger(prn3))*(0.0014/2**30); <= real(conv-integer(prn4))*(0.0014/2**30); <= real(conv-integer(prn5))*(0.0014/2**30); <= real(conv-integer(prn6))*(0.0014/2**30); output-capture: process variable buf: line; file fouti: text is out "prnsum.rec"; file file file file fout2: fout3: fout4: fout5: text text text text is is is is out out out out "prn-one.rec"; "prntwo.rec"; "prn-thr.rec"; "prn-fou.rec"; file fout6: text is out "prnfiv.rec"; file fout7: text is out "prn.six.rec"; begin wait until SYSCLK='1'; write(buf, prnsum); writeline(foutl, buf); write(buf, prn-one); writeline(fout2, buf); write(buf, prntwo); writeline(fout3, buf); 93 write(buf, prn-thr); writeline(fout4, buf); write(buf, prn.fou); writeline(fout5, buf); write(buf, prn-fiv); writeline(fout6, buf); write(buf, prn.six); writeline(fout7, buf); end process; end archPRN2; 94 B.4 comp-cic.vhd This is the VHDL code for the CIC filter used in the VHDL simulation and synthesis. -- $Id: compcic.vhd,v 1.7 2000/08/11 20:52:54 nch2506 Exp $ -- Steve Park smp3454 2/18/2001 Modified the filter to match hand calculations. Bmax=31, Bj's are -11,-1,8,12,13,14, Bin=1, Bout=16, fs=320KHz. -- CIC filter for the compensation variables in the HPG revised design -- Nick Homer June 5, 2000 ----- -- -- The coefficients used in this CIC filter are based on the following calculations. The equations used were derived in "An Economical Class of Digital Filters for Decimation and Interpolation" by -- Hogenauer, 1981. --- library ieee; use ieee.std-logic-1164.all; use ieee.std-logicarith.all; use ieee.std-logicunsigned.all; --pragma translateoff use std.textio.all; --pragma translateon entity COMPCIC is port(CLKFS: IN STDLOGIC; -System clock DATAIN: IN stdjlogic; -data from SDM DATAVALID: OUT std-logic; -output valid DOUT: OUT stdjlogic-vector(17 downto 0); -- output RESET: IN STD-LOGIC; -reset STBFSH: IN STDLOGIC; -CIC high sampling rate STBFSL: IN STDLOGIC); -CIC low sampling rate end COMPCIC; architecture archCOMPCIC of COMPCIC is -- set integration stage register widths constant BI1 : integer : 31; constant B12 : integer := 31; constant B13 : integer := 26; 95 set comb stage register widths -- constant BC1 : integer constant BC2 : integer constant BC3 : integer 22; 21; 20; number of bits for the output -- constant TAPWIDTH : integer := 18; used to synchronize inputs to system clock. -- signal reset-sync : std-logic; : std-logic; signal sdms signals used for accumulators -- signal acci : signed(BI1-1 downto 0); signal acc2 : signed(BI1-1 downto 0); signal acc3 : signed(BI1-1 downto 0); signals used for comb filters -- signal signal signal signal signal signal signal combi: signed(BC1-1 downto 0); comb2: signed(BC2-1 downto 0); comb3: signed(BC3-1 downto 0); : std-logic; tempdin bminusa, b, a : signed(BC1-1 downto 0) := (others => '0'); : integer range 0 to 3; validcount : signed(17 downto 0); dout-i type states is ( idle, comb-stagel, comb-stage2, comb-stage3, comb-stage4); signal state : states; begin -- Synchronize the inputs to our system clock register-inputs : process begin wait until CLKFS = '1'; <= DATA-IN after I ns; sdm-s after 1 ns; reset-sync <= RESET end process; -- perform the integrations: --- note: some of the least significant digits are truncated in the later stages of integration, because they are unimportant for the -- 16-bit output. integrators : process begin 96 wait until CLKFS = '1'; if reset-sync = '1' then acci <= (others => '0') after 1 ns; acc2 <= (others => '0') after 1 ns; acc3 <= (others => 0'') after 1 ns; elsif STBFSH = '1' then if sdm-s = '1' then acci <= acci + 1 after 1 ns; else acci <= acci - 1 after 1 ns; end if; acc2 <= acc2 + accl(BI1-1 downto BI1-BI2) after 1 ns; acc3 <= acc3 + acc2(BI2-1 downto B12-BI3) after 1 ns; end if; end process integrators; b_minusa <= b - a; comb filters: These comb filters are set up in a state machine, where each stage corresponds to a state. Usually, we are in the --idle state, and when the low frequency strobe goes high, the data -is run through all of the comb stages, and the output is updated. -When the filtering is done, the system returns to idle state. comb-registers : process variable temp : signed(BC1-1 downto 0) : (others => '0'); begin wait until CLKFS = '1'; if RESET = '1' then <= idle; state DATA-VALID <= '0'; <= (others => '0'); douti else case state is => when idle if STBFSL = '1' then <= acc3(BI3-1 downto B13-BC1); b <= combi; a state <= comb-stagel; end if; DATAVALID <= '0'; when comb-stagel => -- combi <= b; temp := bminusa; <= b-minus-a; b a <= comb2 & CONV-SIGNED('0', 97 BC1-BC2); state <= comb-stage2; DATAVALID <= '0'; when combstage2 => comb2 <= temp(BC1-1 downto BC1-BC2); temp := bminus-a; b <= b-minus-a; a <= comb3 & CONVSIGNED('0', BC1-BC3); state <= comb-stage3; DATA-VALID <= '0'; when comb-stage3 => comb3 dout-i <= temp(BC1-1 downto BC1-BC3); <= bminus.a(BC1-1 downto BC1-DOUT'length); DATAVALID <= '1'; state <= comb-stage4; when comb-stage4 => DATAVALID <= '0'; state <= idle; when others => DATAVALID <= '0'; state <= idle; end case; end if; end process comb-registers; update the actual output with the value in our internal variable. DOUT <= std-logic-vector(dout-i); temp-din <= DATAIN after 1 ns; -- -- pragma translate-off process (STBFSL) recorddata: variable buf : line; file fouti : text open write-mode is "dout.rec"; begin -- process if risingedge(STBFSL) then write(buf, CONVJINTEGER(dout i)); writeline(foutl, buf); end if; end process; end archCOMP-CIC; 98 B.5 comp-cic2.vhd This version of the CIC filter more closely resembles the model described by Hogenauer. compcic2.vhd uses a finite state machine (FSM) for both the integrator and comb sections. While using an FSM in the integrator section reduces the maximum frequency at which the filter can be clocked, it reduces the overall hardware. Steve Park smp3454 comp-cic2.vhd --- CIC Filter that more closely resembles the one described in Hogenauer's paper. This is done by replacing the code in the --- integrator section with another FSM. 4/8/2001 --- library ieee; use ieee.std-logic1164.all; use ieee.std-logic-arith.all; use ieee.std-logic-unsigned.all; -- pragma translateoff use std.textio.all; --pragma translate-on entity COMPCIC2 is port(CLK-FS IN DATAIN IN DATAVALID OUT DOUT OUT RESET IN STB_FSH : IN STBFSL IN end COMP-CIC2; STDLOGIC; -System clock std-logic; -data from SDM std-logic; -output valid std.logic.vector(17 downto 0); -- output STD-LOGIC; -reset STDLOGIC; -CIC high sampling rate STDLOGIC); -CIC low sampling rate architecture archCOMPCIC2 of COMPCIC2 is -- Number of constant BIl constant B12 constant B13 -- Number of constant BC1 constant BC2 constant BC3 -- number of bits in each stage of integration : integer 31; : integer 31; : integer 26; bits for each of the combs : integer 22; : integer 21; : integer 20; bits for the output 99 constant TAPWIDTH : integer := 18; -- integration registers signal isl-reg : signed(BI1-1 downto 0); signal is2.reg : signed(B12-1 downto 0); signal is3_reg : signed(B13-1 downto 0); -- comb registers signal cslreg : signed(BC1-1 downto 0); signal cs2_reg : signed(BC2-1 downto 0); signal cs3_reg : signed(BC3-1 downto 0); type states is (iidle, isi, is2, is3, cjidle, cs1, cs2, cs3, cs4); signal i-state, cstate: states; -- number of bits at the output : signed(17 downto 0); signal dout-i signal bminusa, b, a : signed(BC1-1 downto 0) : (others => '0'); signal reset-sync : stdlogic; : stdlogic; signal sdms begin -- -- archCOMPCIC2 Synchronize the inputs to our system clock sync-inputs : process begin wait until CLKFS = '1'; <= DATA-IN after 1 ns; sdmns resetsync <= RESET end process; --- after 1 ns; the following process implments the FSM that acts as the 3 integrator stages of the 3rd order CIC filter. integratorsection: process(clkfs) begin if reset-sync = '1' then islreg is2_reg is3_reg i-state <= <= <= <= (others => '0') after 1 ns; (others => '0') after 1 ns; (others => '0') after 1 ns; ijidle; else case i-state is when i-idle => if STBFSH='1' then i_state <= isi; 100 else i-state <= i-idle; end if; when isi => if sdm-s = '1' then isireg <= islreg + 1 after 1 ns; else islreg <= islreg - 1 after 1 ns; end if; i_state <= is2; when is2 => is2_reg <= is2_reg + islreg(BI1-1 downto BI1-BI2); i-state <= is3; when is3 => is3_reg <= is3_reg + is2.reg(BI2-1 downto B12-BI3); i_state <= i.idle; when others => i_state <= iLidle; end case; end if; end process; b_minusa <= b - a; combsection process variable temp : signed(BC1-1 downto 0) begin wait until CLKFS = '1'; if reset-sync = '1' then cslreg cs2_reg cs3_reg c-state <= <= <= <= (others => '0'); (others =>'0'); (others =>'0'); (others =>'0'); c-idle; else case c-state is => when c-idle if STBFSL = '1' then b <= is3_reg(BI3-1 downto B13-BC1); a <= csl-reg; cstate <= csl; else c-state <= c-idle; end if; DATA.VALID <= '0'; when csl => cslreg <= b; 101 temp := b_minusa; <= bminus-a; b a <= cs2_reg & CONVSIGNED(&O', BC1-BC2); c_state <= cs2; DATAVALID <= '0'; when cs2 => cs2.reg <= temp(BC1-1 downto BC1-BC2); temp := b_minusa; <= bminus-a; b a <= cs3-reg & CONV-SIGNED('O', BC1-BC3); c_state <= cs3; DATAVALID <= '0'; when cs3 => cs3_reg <= temp(BC1-1 downto BC1-BC3); douti <= bminusa(BC1-1 downto BC1-DOUT'length); DATAVALID <= '1'; <= cs4; c_state when cs4 => DATAVALID <= '0'; <= cjidle; c_state when others => DATAVALID <= '0'; c_state <= cjidle; end case; end if; end process comb-section; DOUT <= std-logic-vector(dout-i); -- pragma translateoff -- Record data. record-data : process (STBFSL) variable buf : line; file fouti : text open writemode is "dout2.rec"; begin -- process if rising-edge(STBFSL) then write(buf, CONVINTEGER(douti)); writeline(foutl, buf); end if; end process; --pragma translate-on end archCOMPCIC2; 102 B.6 compsdm.vhd compsdm.vhd is the VHDL version of the sigma-delta modulator used in the Simulink simulation. -- $Id: comp-sdm.vhd,v 1.6 2000/08/09 18:29:28 nch2506 Exp $ -- Nick Homer June 5, 2000 -- -- Compensation Variable Sigma-Delta converter model for the testbench of the revised design of the HPGD Rate processing logic. This SDM pushes noise away from frequencies around DC, as opposed to the rate channel SDM, which is centered around 20KHz. Based on Ed -- Balboni's sigma-delta Matlab module. --- library ieee; use ieee.std-logic_1164.all; use ieee.std.logic.arith.all; use ieee.std-logic-unsigned.all; -- synthesis translate-off use ieee.MATHREAL.all; use std.textio.all; -- synthesis translate-on entity COMP_SDM is port(CVSDMDATA : out std-logic; : in stdjlogic; --EN : in std-logic; SO : in std.logic; Si THERMNOISE : in SDM_CLK_IN : in -- --- SDM data output -- MUX enable MUX select 0 MUX select 1 real:=0.0; std-logic); -- SDM sampling clock end COMPSDM; architecture archCOMPSDM of COMP_SDM is constant OUTPUTONES : std-logic := '0'; type sample is array (0 to 1) of real; -- for mux select signal sel: std-logic.vector(1 downto 0); -- INPUT SIGNALS: signal step-input, sin-input, sin-fast, : real impulse, squarewave, ramp-input 103 : 0.0; signal sincount : integer 0; Output monitors for writing to file -- signal fn-mon, input-mon : real 0.0; -- Matrix to hold coefficients for calculating output type abcdmatrix-type is array (1 to 2, 1 to 3) of real; constant ABCD : abcd-matrix-type ( 1 => (-0.001, 0.999, 0.2, -0.2), 2 => ( 0.001, 0.999, 0.33333, -0.16667)); 1 => (1.000, 0.2, -0.2), --- 2 => (1.000, 0.3333333, -0.16666667)); Periods for resetting the generated sin waves. -- constant SINCOUNTMAX : integer -- constant SIN5_PERIOD : real 6666667; (2*3.1415/66666.666667); constant SIN5_PERIOD : real := (2*3.1415/66667); constant SINFASTPERIOD: real:= (2*3.1415/10); begin sel(l) <= Si; sel(0) <= SO; --- synthesis translateoff Make simple inputs: step and impulse GenerateSDMInput : process begin wait until SDM_CLK_IN = '1'; -- make sine waves if sincount >= SINCOUNTMAX then sincount <= 0; -- Reset counter so that it doesn't overflow else sincount <= sin-count + 1; end if; sin-input <= 2.0 * sin(real(sincount) * SIN5_PERIOD) after 1 ns; sin-fast <= 2.0 * sin(real(sin-count) * SINFASTPERIOD) after 1 ns; end process; -- synthesis translate-on -- Sigma Delta Modulator test module optimized to reduce noise at low frequencies -- 104 SigmaDeltaModulator : process ---- 0.0; -- input to SDM : real variable xn output of first stage -: 0.0; : real variable z output of second stage -: 0.0; : real variable w (0.0, 0.0); -- remembers history of z : sample variable yl : sample : (0.0, 0.0); -- remembers history of w variable y2 -output of SDM: quantized to 1 bit : 0.0; : real variable fn 2.5; -- magnitude limit on values : real constant L 0; -- used for keeping track of samples: : integer constant n 0; : integer variable count3 begin wait until SDMCLKIN = '1'; 11/29/00 smp3454 Changing it so that only one input is read. Uncomment to make input dependent on mux select signals sO and si case sel is when "00" => --- xn := sininput+THERMNOISE; ----------- -- when "01" => xn := -0.5; when "10" => xn := 1.0; when "11" => xn := 0.5; when others => xn := 0.0; end case; comparator: we need to do this here so that it doesn't get registered. if y2(n) > 0.0 then fn := 2.5; CVSDMDATA <= '1'; else fn := -2.5; CVSDMDATA <= '0'; end if; -- used for writing output to file input-mon <= xn; <= fn; fnmon --- calculate value at first stage purpose of 1st term? 105 z := ABCD(1, 1)*yl(n) + ABCD(1, 2)*xn + ABCD(1, 3)*fn; -- restrict magnitude to less than or equal to L if z > L then yl(n+1) := L; elsif z < -L then yl(n+1) -L; else yl(n+1) z; end if; calculate value at second stage -purpose of 1st term? w := ABCD(2, 1)*y2(n) + ABCD(2, 2)*yl(n) + ABCD(2, 3)*fn; -- -- restrict magnitude to less than or equal to L if w > L then y2(n+1) := L; elsif w < -L then y2(n+1) -L; else y2(n+1) w; end if; y1(n) yl(n+1); y2(n) y2(n+1); end process; -- -- synthesis translate-off write simulation variables to file for graphing SIMULATIONOUTPUT : process : line; variable buf file fouti : text is out "s-d-in.dat"; file fout2 : text is out "s-d-out.dat"; begin wait until SDM-CLK-IN = '1'; write(buf, inputmon); writeline(foutl, buf); write(buf, fn-mon); writeline(fout2, buf); end process; -- synthesis translateon end archCOMP-SDM; 106 B.7 compalL-tb.vhd This is a VHDL testbench file created in order to speed up simulation by not incorporating the INTERFACES block. The input to the SDM should be set such that it does not depend on multiplexer-select signals. In the code shown below, READPRN is used for thermal noise generation. library ieee; use use use use use ieee.stdlogic_1164.all; ieee.std-logic-arith.all; ieee.std-logicunsigned.all; work.constants.all; std.textio.all; entity COMPALLTB is end COMPALLTB; architecture archCOMPALLTB of COMPALLTB is -- choose random noise block component READPRN port(RANDNUM: out real; RESET: IN std-logic; SYSCLK: IN std-logic); end component; component COMP_SDM is port(CVSDMDATA : out stdjlogic; : in stdlogic; --EN : in stdlogic; SO : in stdlogic; Si THERMNOISE : in real; SDM_CLK_IN : in stdilogic); end component; -- --- -- SDM data output -- MUX enable MUX select 0 MUX select 1 SDM sampling clock component COMPCIC is -System clock port(CLK-FS: IN STD-LOGIC; -data from SDM DATAIN: IN stdlogic; -output valid DATAVALID: OUT std-logic; DOUT: OUT stdlogic-vector(17 downto 0); -- output reset -RESET: IN STDLOGIC; -CIC high sampling rate STBFSH: IN STD-LOGIC; -CIC low sampling rate STB_FSL: IN STDLOGIC); end component; 107 -- set R of CIC filter here constant R: integer := 900; signal reset: stdilogic:='O'; signal randnum : real; stdlogic; signal cv-sdmdata signal sdmclkin : std-logic := '0'; signal clkfs : std-logic : '0'; signal signal -- set signal signal stbfsh : std-logic := '0'; stbfsl : stdlogic := '0'; the output width of the CIC filter here dout: stdlogic.vector(17 downto 0); datavalid: stdjlogic; begin Ul: READPRN port map(RANDNUM => randnum, RESET => reset, SYSCLK => sdm_clk_in); --sysclk is a misnomer. it's 333KHz. U2: COMPSDM port map(CV-SDMDATA => cv-sdmdata, SO => '0', S1 => '0', THERMNOISE => randnum, SDMCLKIN => sdmclkjin); U3: COMPCIC port map(CLKFS => clk-fs, DATAIN => cvsdmdata, DATAVALID => data-valid, DOUT => dout, RESET => reset, STBFSH => stbjfsh, STBFSL => stbfsl); -- The following section generates clocks and strobes so that a separate clock generation block is not needed. -- generating simple clock signals -- reset <= '1' after 1000 ns, '0' after 2000 ns; sdmclk-in <= not sdmclkin after 1500 ns; clkfs <= not clk-fs after 125 ns; 108 -- generating strobe signals for CIC filter cvtiming: process variable cfsh: integer range 0 to 20; variable cfsl: integer range 0 to R; --- for stb_fsh for stbfsl begin wait until clkjfs = '1'; if cfsh = 11 then c_fsh : 0; stbjfsh <= '1' after 1 ns; if c-fsl = (R-1) then cfsl := 0; stb-fsl <= '1' after I ns; else c-fsl := cfsl + 1; end if; else c-fsh := c-fsh + 1; stbfsh <= '0' after 1 ns; stbfsl <= '0' after 1 ns; end if; end process; end archCOMPALLTB; 109 4e6/12 = 333.33KHz -- -- 333.333KHz/R