* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download report
Immunity-aware programming wikipedia , lookup
Time-to-digital converter wikipedia , lookup
Alternating current wikipedia , lookup
Flip-flop (electronics) wikipedia , lookup
Pulse-width modulation wikipedia , lookup
Voltage optimisation wikipedia , lookup
Quantization (signal processing) wikipedia , lookup
Oscilloscope history wikipedia , lookup
Two-port network wikipedia , lookup
Voltage regulator wikipedia , lookup
Mains electricity wikipedia , lookup
Resistive opto-isolator wikipedia , lookup
Power electronics wikipedia , lookup
Buck converter wikipedia , lookup
Network analysis (electrical circuits) wikipedia , lookup
Schmitt trigger wikipedia , lookup
Integrating ADC wikipedia , lookup
Switched-mode power supply wikipedia , lookup
SUCCESSIVE APPROXIMATION REGISTER CHAPTER 1 INTRODUCTION In our daily life, anything we deal like sound, pressure, voltage or any measurable quantity, are usually in analog form so what if we want to interface any analog sensor with our digital controllers? There must be something that translates the analog inputs to digital output, and so analog to digital convertors come to play. Usually we call them ADC (Analog to digital convertor). Before going to learn how to interface an ADC with a controller we first take a look at basic methods of analog to digital conversion In the past few years, more and more applications are built with very stringent requirements on power consumption. For electronic systems, such as wireless systems or implantable devices, the power consumption is becoming one of the most critical factors. The stringent requirements on the energy consumption increase the need for the development of low voltage and low power circuit techniques and system building blocks. Analog-to-Digital Converters (ADCs) translate the analog quantities into digital language, used in information processing, computing, data transmission and control systems. ADCs are key components for the design of power limited systems, in order to keep the power consumption as low as possible. The successive approximation ADC is much faster than the digital ramp ADC because it uses digital logic to converge on the value closest to the input voltage. A comparator and a DAC are used in the process. Block Diagram: Dept. Of E&CE Page 1 BIT. SUCCESSIVE APPROXIMATION REGISTER A SAR ADC requires: An input voltage source Vin. A reference voltage source Vref to normalize the input. A DAC to convert the approximation to a voltage. A Comparator to perform the function by comparing the DAC's voltage with the input voltage. A Register to store the output of the comparator. Requirements: Xilinx 9.1 IES. ISE simulator/model sim. Dept. Of E&CE Page 2 BIT. SUCCESSIVE APPROXIMATION REGISTER CHAPTER 2 ADC ARCHITECTURES Analog to Digital Converter (ADC), is an electronic circuit that converts continuous analog signals into discrete values. An analog signal needs to be quantized in order to be converted in a digital one. An analog signal can take infinite values; quantization consists in the substitution of these infinite values into discrete and finite amounts of values. In Figure 2 is shown an example of conversion. The input signal varies between 0 and FS (full scale), and it’s converted in a digital word of N-bits. Figure 2: Analog-Digital Conversion The resolution of an ADC is the number of discrete levels that it can produce at the output. The resolution is expressed in bits, for a resolution of N-bits, there are 2n digital values allowed. The resolution is also defined as the minimum voltage difference between two analog signals coded into two adjacent levels (LSB). Successive Approximation Register ADC (Figure 3) represents the majority of the ADC market for medium to high resolution. This topology requires just one comparator; an N-bit SAR ADC will require N comparison periods and will not be ready for the next conversion until the current one is complete. This topology is expected to allow the lowest power dissipation, but paying the price with the slowest sampling rate. Dept. Of E&CE Page 3 BIT. SUCCESSIVE APPROXIMATION REGISTER Comparison between published data Topology Ref. Bits Sampling Rate Power Vdd Technology Folding and/or Interpolatin g ADC Ref [6] 8 70 MS/s 45 mW 3.3 V 0.8 μm Ref [7] Ref [8] Ref [9] Ref [10] Ref [11] Ref [12] Ref [13] Ref [14] 10 8 6 6 6 40 MS/s 30 MS/s 50 MS/s 4 MS/s 1.5 MS/s 1 MS/s 1.2 GS/s 1.3 GS/s 65 mW 18 mW 20 mW 140 μW 40 μW 80 μW 90 mW 600 mW 5V 1.8 V 1V 1V 0.9 V 0.7 V 1.5 V 1.8 V 0.6 μm 0.18 μm 0.35 μm 90 nm 0.5 μm 0.18 μm 0.13 μm 0.25 μm Ref [15] 6 1 MS/s 7 μW 0.5 V 90 nm Ref [16] Ref [17] Ref [18] 8 10 5 200 kS/s 1 MS/s 250 MS/s 2.5 μW 1.9 μW 1.2 mW 0.9 V 1V 0.8 V 0.18 μm 65 nm 65 nm Sigma Delta ADC Flash ADC SAR ADC Table 2: Comparison between published data The data in the table shows that the SAR ADC is the one that allows the lower power consumption. The price to pay is the sampling rate that is the lowest with respect to the other topologies. 2.1 Successive Approximation Register ADC Comparing Successive Approximation Register, Flash, Folding and Interpolating and Sigma-Delta ADCs, the SAR ADC seems allowing the lowest-power consumption. This architecture has the advantage to be very simple; it implements the binary search algorithm. Power dissipation scales with the sample rate, unlike flash ADCs that usually have constant power dissipation versus sample rate. This is especially useful in low-power applications. Moreover SAR ADC does not contain an operational amplifier; that are generally power-hungry, it needs just one comparator that consume much less power than operational amplifiers. Dept. Of E&CE Page 4 BIT. SUCCESSIVE APPROXIMATION REGISTER SAR ADC has four mains building blocks (Figure 2.1): Sample-and-Hold Stage (S/H) Digital-to-Analog Converter (DAC) Comparator Successive Approximation Register (SAR) Figure 2.1: Simplified N-bit SAR ADC architecture. The basic functionality of a SAR ADC is very simple. The analog input voltage VIN is sampled by the Track & Hold block. To implement the binary search algorithm, the N-bit register is first set to midscale setting the MSB to '1' and all other, the comparator output is logic 0 and the MSB of the register is cleared to 0. The SAR control logic then moves to the next bit down, forces that bit high, and does another comparison. The sequence continues all the way down to the LSB. Once this is done, the conversion is completed, and the N-bit digital word is available in the register [bits to ‘0’. This forces the DAC output, VDAC, to be half of the reference voltage, VREF/2. VIN is then compared with VDAC, if VIN is greater than VDAC, the comparator output is logic 1 and the MSB of the N-bit register remains at 1. Conversely, if VIN is less than VDAC the comparator output is logic 0 and the MSB of the N-bit gets 0. Dept. Of E&CE Page 5 BIT. SUCCESSIVE APPROXIMATION REGISTER Figure 2.2: SAR operation (4-bit ADC example). SAR ADC works with two different clock frequencies. The first clock is an input of the chip, and its frequency, fint, is the one at which the internal circuit works. The second clock drives the Sample and Hold in order to sample the analog input value. This second clock is internally created by a frequency divider; it should be X times slower the first one, where X is the number of comparison periods needed from the control logic to complete a conversion. The conversion rate is determined by this second clock, an N-bit SAR ADC will require minimum N periods and will not be ready for the next conversion until the current one is complete. Dept. Of E&CE Page 6 BIT. SUCCESSIVE APPROXIMATION REGISTER FIGURE 2.3 – Timing diagram of 8-bit SAR ADC & SAR algorithm for 8-bit ADC. Dept. Of E&CE Page 7 BIT. SUCCESSIVE APPROXIMATION REGISTER CHAPTER 3 SAMPLE-AND-HOLD CIRCUIT A sample-and-hold (S/H) or track-and-hold (T/H) circuit is frequently required to Capture rapidly varying signals for subsequent processing by slower circuitry. The function of the S/H circuit is to track/sample the analog input signal and to hold that value while subsequent circuitry digitizes it. Although an S/H refers to a device which spends an infinitesimal time acquiring signals and a T/H refers to a device which spends a finite time in this mode, common practice will be followed and the two terms will be used interchangeably throughout this discussion as will the terms sample and track. The function of a track-and-hold circuit is to buffer its input signal accurately during track mode providing at its output a signal which is linearly proportional to the input, and to maintain a constant output level during hold mode equal to the T/H output value at the instant it was strobed from track to hold by an external clock signal. The sample-and-hold circuit is shown in Fig. 3. Capacitors CH1 and CH2 are alternately operated in sample and in hold operation. The sampling clock “fS” provided by the SAR is divided by two. A non-overlapping two phase clock is generated. Both signals are provided in complementary form to control the n MOS switches and the related n-MOS dummy switch devices. The operating point of the switch transistors determines the minimum settling time. At ultra-low supply voltage these transistors are operated in weak inversion when switched “on”. However, a relaxation of the impact of this operating condition is obtained due to the fact that the sampling frequency is an order of magnitude lower than the operating frequency of the comparator. Moreover, the switching frequency is two times lower compared to the sampling frequency since two time-interleaved sampling paths are used. The sampling capacitors are not integrated on-chip. We use relatively large values of 47pF here in order to suppress parasitic coupling effects caused by packaging and bond wire capacities. Integration of these capacitors on-chip allows to significantly decreasing their value. Figure 3 - Sample-and-hold circuit Dept. Of E&CE Page 8 BIT. SUCCESSIVE APPROXIMATION REGISTER The circuit implementation of the Sample & Hold circuit is given in the Fig. 3.1. The simple sample and hold circuit suffers with the problem of substantial charge injection, which is encounter by adding a dummy device with half the width of the sampling switch and is driven with complementary clock. Fig. 3.1. Schematic of Sample & Hold circuit. In the circuit when M1 turns off and injects charge onto holding c a p a c i t o r , M2 turns on and absorbs charge from the capacitor. Hence it is exactly half of the M 1 channel charge is injected o n t o , then complete cancellation occurs and the held voltage on is not corrupted by charge injection. A pair of the same circuit can be used in differential fashion for Differential SAR ADC. Dept. Of E&CE Page 9 BIT. SUCCESSIVE APPROXIMATION REGISTER CHAPTER 4 COMPARATOR The comparator can be basically defined as a quantizer where in the quantization noise forms the crux of the ADC design. A quantizer is a device that converts a continuous range of input amplitude levels into a finite set of discrete digital code words. Theoretically an analog-to-digital conversion process comprises a sampling and quantization processes. A/D converter system usually consists of a quantizer along with other signal conditioning circuitry such as amplifiers, filters, sample-and-hold circuits etc. Despite this difference, the terms quantizer and A/D converter are often used synonymously. A quantizer can be uniquely described by its transfer function or quantization characteristic, which contains two sets of information: the first includes the digital codes associated with each output state, and the second includes the threshold levels which are the set of input amplitudes at which the quantizer transitions from one output code to the next. The analog input voltage normalized to full scale (FS) is shown on the horizontal axis. The digital output code is given on the vertical axis. The quantizer has been designed so that the output digital word changes when the analog input is at odd multiples of FS/16. The LSB of the digital output code changes each time the analog input changes by FS/2n where n is equal to the number of digital bits. A change of in the analog input is called an LSB. In (Fig. 4), an LSB is the length of the horizontal part of the stair step, or FS/8. The ideally quantized ranges of the analog input are shown just above the horizontal axis on Fig. 3.4. These ranges are centered about even multiples of FS/16 except for the rightmost and leftmost, which have no right or left limits, respectively. Fig. 4 – Ideal input output characteristics for a 3 bit quantizer Dept. Of E&CE Page 10 BIT. SUCCESSIVE APPROXIMATION REGISTER Graphically, the quantizing process means that a straight line representing the relationship between the input and the output of a linear analog system is replaced by a transfer characteristic that is staircase-like in appearance. The quantizing process has a twofold effect: (i) the peak-to-peak range of input sample values is subdivided into a finite set decision levels or decision thresholds that are alighted with the “risers” of the staircase, and (ii) the output is assigned a discrete value selected from a finite set of representation levels or reconstruction values that are aligned with the “treads” of the staircase. The transfer characteristic of uniform quantizer is shown in Fig. 4.1(a) for midtread type and in Fig. 4.1(b) for midriser type. The separation between the decision thresholds and the separation between the representation levels of the quantizer have a common value called the step size Δ. Fig. 4.1 Ideal quantizer transfer characteristic (a) midtread (b) midriser Fig 4.2 – Symbol of Comparator Dept. Of E&CE Page 11 BIT. SUCCESSIVE APPROXIMATION REGISTER Fig 4.3 – Schematic of Comparator. The comparator circuit presented in Fig 4.3 is a clocked comparator with power consumption of 30uW. The input stage has been designed to facilitate any common mode voltage from 0 to 1.2 V. The output stage of this circuit consists of SR latch which provides the Comparator decision value to the SAR Digital logic. The positive terminal of the comparator is driven by the output of the track and hold circuit. Here we have presented the comparator with appropriate connections for the Positive going signal. To accommodate the complete input common mode range NM OS differential pair (M3 & M4) and PMOS differential pair (M1 & M2) is used. The P2, P3, P5, P6, P7 and P8 can be imagined as a clocked inverter with cross coupling to achieve positive feedback. P1 and P4 are driven by the clock which can pull up the output nodes to Vdd. This leaves the output nodes at a dynamic state. The dynamic output nodes are converted into static nodes by using a RS latch. Use of RS latch also eliminates metastability errors. An inverted based driver is placed at the output if necessary to ensure that it can drive the required capacitivie load. Positive terminal accepts the time varying input and compares the reference voltage applied on the Negative terminal. A decision is made and applied to the Output terminal of the comparator. Another comparator with Input terminals of Von_TH, Von_DAC and Output terminal of Von_CM P is used where the functionality of these terminals are exactly the same as the one mentioned above. The comparator has a rise time of 1ns. This slewing is necessary to ensure it doesn ’t create a race condition by changing the Output state along with the rising edge of the clock. More details on this problem and its solution have been presented in the SAR Digital logic section. Dept. Of E&CE Page 12 BIT. SUCCESSIVE APPROXIMATION REGISTER CHAPTER 5 DIGITAL TO ANALOG CONVERTER DAC is the component in SA R ADC which determines the overall linearity of the ADC. The basic purpose of the DAC is to generate analog output proportional to digital code. Each digital code contains a certain fraction of reference which multiplied or divided, where the reference may be one of the three electrical quantities: voltage, current or charge. The accuracy of this function determines the linearity of the DAC, while the speed at which each reference can be selected and established gives the conversion rate of the DAC. The linearity and SNDR of D/A converters depend on the accuracy of the reference multiplication or division employed to generate the output levels. The resistor ladder based DAC is on voltage division, where a given reference voltage can be divided into N equal segments using a ladder composed of N identical resistors R1 = R2 = … = Rn. An n-bit DAC theoretically requires about 2n resistors, manifesting exponential growth of the number of resistors as a function of resolution. An important aspect of resistor ladder is integral and differential non-linearities they introduce when used in SAR ADC. These errors result from mismatches in the resistors comprising of the ladder. The resistors do not exhibit linear gradient rather random mismatch. This type of mismatch originates primarily from the uncertainties in geometry definition during processing, as well as random variations in contact resistance. Consider two resistors lay out with identical geometry and dimensions. In the ideal case, the value of the resistor can be expressed as …….(Eqn. 5.1) Where is the resistivity, L, W and t are the length, width and thickness of the resistors, respectively and represents additional resistance due to each contact. In reality the resistors suffer from several mismatch components: resistivity mismatch, width, length and thickness mismatch and contact resistance mismatch. In a typical process, width an length mismatch results from limited edge definition capability in lithography and etching or deposition of the resistor material, the variation in thickness arises from gradients across the die and contact resistance mismatch caused by random variations in the finite resistance at the interface of the resistor and the interconnect. Taking the total differential the overall mismatch between two resistors can be given as Dept. Of E&CE Page 13 BIT. SUCCESSIVE APPROXIMATION REGISTER …….(Eqn. 5.2) The value can be normalized to the mean value of the resistors, R to yield the relative mismatch. Since the contact resistance decreases as the resistor width increases we can write, where r is the proportionality factor. Thus the above Eqn. 5.2 can be modified a …….(Eqn5.3) In a typical process, and t are given, leaving L, W and R as the only variable under designer’s control. To minimize the overall mismatch, each of these parameters must be maximized. Large dimensions lead to high parasitic capacitance between the resistor and substrate as well as large chip space. Fig. 5.1 - R-2R ladder based DAC Dept. Of E&CE Page 14 BIT. SUCCESSIVE APPROXIMATION REGISTER Resistor ladder networks provide a simple, inexpensive way to perform digital to analog conversion (DAC). The most popular networks are the binary weighted ladder and the R/2R ladder. Both devices will convert digital voltage information to analog, but the R/2R ladder has become the most popular due to the network’s inherent accuracy superiority and ease of manufacture. Fig. 5.1 is a diagram of the basic R/2R ladder network with N bits. The “ladder” portrayal comes from the ladder-like topology of the network. Note that the network consists of only two resistor values; R and 2R (twice the value of R) no matter how many bits make up the ladder. The particular value of R is not critical to the function of the R/2R ladder. The binary weighted ladder shown in Fig. 5.1 requires double multiples of R as the number of bits increase. As the ratios of the resistors become more and more obtuse in a binary weighted network, the ability to trim the resistors to accurate ratio tolerance becomes diminished. More accurate ratios can be obtained in a resistor network with consistent, similar values as in the R/2R network. The R/2R network provides the most accurate method of digital to analog conversion. The last resistance in the ladder is the termination resistor which is connected to ground. The termination resistor assures that the Thevenin resistance of the network as measured to ground looking toward the LSB (with all bits grounded) is R as shown in Fig. 5.1. The Thevenin resistance of an R/2R ladder is always R, regardless of the number of bits in the ladder. Digital information is presented to the ladder as individual bits of a digital word switched between a reference voltage (Vr) and ground. Depending on the number and location of the bits switched to Vr or ground, Vout will vary between 0 volts and Vr. If all inputs are connected to ground, 0 volts is produced at the output, if all inputs are connected to Vr, the output voltage approaches Vr, and if some inputs are connected to ground and some to Vr then an output voltage between 0 volts and Vr occurs. These inputs (also called bits in the digital lingo) range from the Most Significant Bit to the Least Significant Bit. As the names indicate, the MSB, when activated, causes the greatest change in the output voltage and the LSB, when activated, will cause the smallest change in the output voltage. If we label the bits (or inputs) bit 1 to bit N the output voltage caused by connecting a particular bit to Vr with all other bits grounded is: ……(Eqn5.4) Where N is the bit number. For bit 1, Vout =Vr/2, for bit 2, Vout = Vr/4 etc. Since an R/2R ladder is a linear circuit, we can apply the principle of superposition to calculate Vout. The expected output voltage is calculated by summing the effect of all bits connected to Vr. For example, if bits 1 and 3 are connected to Vr with all other inputs grounded, the output voltage is calculated by: Dept. Of E&CE Page 15 BIT. SUCCESSIVE APPROXIMATION REGISTER …….(Eqn5.5) The R/2R ladder is a binary circuit. The effect of each successive bit approaching the LSB is 1/2 of the previous bit. If this sequence is extended to a ladder of infinite bits, the effect of the LSB on Vout approaches 0. Conversely, the full-scale output of the network (with all bits connected to Vr) approaches Vr as shown in Eqn. 5.6 ….(Eqn5.6) The full-scale output is less than Vr for all practical R/2R ladders, and for low pin count devices the full-scale output voltage can be significantly below the value of Vr. Eqn. 5.7 can be used to calculate the full-scale output of an R/2R ladder of N bit …….(Eqn5.7) An R/2R ladder of 4 bits would have a full-scale output voltage of 1/2 +1/4 + 1/8 + 1/16 = 15Vr/16 or 0.9375 volts (if Vr=1 volt) while a 10 bit R/2R ladder would have a fullscale output voltage of 0.99902 (if Vr=1 volt). The number of inputs or bits determines the resolution of an R/2R ladder. Since there are two possible states at each i nput, ground or Vr, (also designated as “0” or “1” in digital lingo for positive logic) there are 2N combinations of Vr and ground to the inputs of an R/2R ladder. The resolution of the ladder is the smallest possible output change for any input change to the ladder and is given by 1/2N where N is the number of bits. This is the output change that would occur for a change in the least significant bit. For a 10bit R/2R there are 2N or or 1024 possible binary combinations at the inputs. The resolution of the network is 1/1024 or .0009766. A change in state at the LSB input should change the output of the ladder by .09766% of the full scale output voltage. The output accuracy of the R/2R ladder is typically specified in terms of full-scale output ± some number of least significant bits. R/2R ladders are usually specified with output accuracies of ±1 LSB or ±1/2 LSB. For example, a ±1/2 LSB specification on a 10 bit ladder is exactly the same as ±0.04883%full-scaleaccuracy. Dept. Of E&CE Page 16 BIT. SUCCESSIVE APPROXIMATION REGISTER CHAPTER 6 PROS AND CONS Pros: High-Performance . Stand-Alone A/D Converters for a Variety of Embedded Systems Applications. SAR converter ideal for many real-time applications, including motor control, touchscreen sensing, medical and other data acquisition systems. Precision Analog Signal Processor. Precision Sensor Interface. High Accuracy DC Measurements. SAR ADCs are low power consumption, high resolution and accuracy, and a small form factor. Cons: Higher resolution successive approximation ADC’s will be slower Speed limited to ~5Msps The SAR architecture are the lower sampling rates and the requirements that the building blocks, the DAC and the comparator, be as accurate as the overall system Dept. Of E&CE Page 17 BIT. SUCCESSIVE APPROXIMATION REGISTER CHAPTER 7 APPLICATIONS The applications of Data Converters are listed below: Battery powered equipment Wireless Communication Data acquisition systems Medical instruments Test and measurement Industrial imaging (Analog Device I., 2009) (Analog Device I., 1995-2009) SAR converter ideal for many real-time applications, including motor control, touch-screen sensing, medical and other data acquisition systems. Precision Analog Signal Processor Precision Sensor Interface High Accuracy DC Measurements Dept. Of E&CE Page 18 BIT. SUCCESSIVE APPROXIMATION REGISTER CHAPTER 8 RESULT Dept. Of E&CE Page 19 BIT. SUCCESSIVE APPROXIMATION REGISTER CHAPTER 9 FUTURE WORK In the limited time available for this project we couldn’t perform some important analysis, such as noise analysis. As future work, several improvements can be brought to the circuit in order to increase the performances. First a study of the most suitable design for Track and Hold circuit to be inserted in the circuit can be performed; adding this block the sampling rate can be increased. Also, the analog components, such as the level shifter, can be redesigned to decrease the amount of current that they require. But the most important element that we should care about is the logic block. Currently it is built by components from the standard 90nm CMOS technology; targeting a lower consumption of power the digital part can be implemented with STSCL gates, this would help a lot to decrease the current flowing through it. The last important part that we still have to work on, is the layout of the whole circuit and the post layout simulations in order to see the real behavior and performances of the ADC. Dept. Of E&CE Page 20 BIT. SUCCESSIVE APPROXIMATION REGISTER CHAPTER 10 CONCLUSIONS This project has been started with an extensive research in order to study and analyze the state of the arts of the ultra-low power ADCs. Based on this study the SAR architecture has been chosen as the one that allows targeting few micro-Watts of power consumption. Then, a behavioral model in Verilog has been implemented to study the working principle and the effects of non-idealities on the converter performances. A deep research on the available literature has been carried out to define the topologies of the various building blocks of the ADC core. The ADC core is composed by comparator, DAC, SAR control logic and delay elements; these components have been designed targeting to fulfill several constraints on requirements such as the offsets due to mismatch. From the results presented in the previous chapter it can be deduced that the performance of the ADC less than ideal. Actually it consumes a low amount of power, few tens of microWatts, but the price to pay is in the speed of the conversion that decreases to few k Sample/s. However the conversion is performed without missing codes. Dept. Of E&CE Page 21 BIT. SUCCESSIVE APPROXIMATION REGISTER BIBILOGRAHPY JOURNAL: MOSCOVICI, A. (2001). HIGH SPEED A/D CONVERTERS. KLUWER ACADEMIC PUBLISHERS. S. MORTEZAPOUR, E. K. F. LEE, "A I-V, 8-BIT SUCCESSIVE APPROXIMATION ADC IN STANDARD CMOS PROCESS", IEEE JOURNAL OF SOLID STATE CIRCUITS, VOL. 35, N. 4, APRIL 2000. INTERNET RESOURCES: http://www.analog.com/en/analog-to-digitalconverters/adconverters/ad7980/products/ prouduct.html www.analog.com. http://www.analog.com/library/analogDialogue/archives/39-06/architecture.pdf. Dept. Of E&CE Page 22 BIT. SUCCESSIVE APPROXIMATION REGISTER APPENDIX VERILOG CODE FOR SUCCESSIVE APPROXIMATION REGISTER. module sar(clk,rst,cmp,soc, eoc, q); input clk,rst,cmp,soc; output eoc; output [3:0] q; reg [3:0]qtemp; reg [2:0] qcntr; reg en,eoctemp; always @(posedge clk or posedge rst) begin if(rst) en=1'b0; else if(eoctemp) en=1'b0; else if(soc) en=1'b1; end always @(posedge clk or posedge rst) begin if(rst) eoctemp=1'b0; Dept. Of E&CE Page 23 BIT. SUCCESSIVE APPROXIMATION REGISTER else if(qcntr==3'b111) eoctemp=1'b1; else eoctemp=1'b0; end assign eoc=eoctemp; always @(posedge clk or posedge rst) begin if(rst) qcntr=3'b0; else if(eoctemp) qcntr=3'b0; else if(en) qcntr=qcntr+1; end assign q=qtemp; always @(posedge clk or posedge rst) begin if(rst) qtemp=4'b1000; else if(en) begin case(qcntr) 3'b001: begin if(cmp) qtemp[3]=qtemp[3]; else Dept. Of E&CE Page 24 BIT. SUCCESSIVE APPROXIMATION REGISTER qtemp[3]=1'b0; end 3'b010:begin qtemp[2]=1'b1; end 3'b011:begin if(cmp) qtemp[2]=qtemp[2]; else qtemp[2]=1'b0; end 3'b100:begin qtemp[1]=1'b1; end 3'b101:begin if(cmp) qtemp[1]=qtemp[1]; else qtemp[1]=1'b0; end 3'b110:begin qtemp[0]=1'b1; end 3'b111:begin if(cmp) qtemp[0]=qtemp[0]; Dept. Of E&CE Page 25 BIT. SUCCESSIVE APPROXIMATION REGISTER else qtemp[0]=1'b0; end default:begin qtemp=qtemp; end endcase end else qtemp=4'b1000; end endmodule Dept. Of E&CE Page 26 BIT.