You are on page 1of 59

Lecture 9

Today: Basics of A/D and D/A. Spartan-3 analog I/O and DDS. Digilent family boards. Printed copy of todays lecture slides. VHDL materials on handouts web page Pedroni, data sheets, etc. Please keep the lab clean and organized. Last one out should close the lab door!!!!

Handouts: Read: References:

Nothing is more dicult, and therefore more precious, than to be able to decide. Napoleon I.
EECS 452 Fall 2009 Lecture 9 Page 1/59 Mon 9/28/2009

This weeks reminders

HW 3b due this Wednesday. HWs 2 and 3 due this Friday. Project team formation and topic selection next Wed night.

EECS 452 Fall 2009

Lecture 9 Page 2/59

Mon 9/28/2009

ADC and DAC


ADC (analog to digital converter) and DAC (digital to analog converter) are two critical elements in most digital systems.

We will take a look at the basic idea behind these. We will introduce the A/D and D/A on S3-SB and other related IO. You will get to practice these in Lab 4. Discretize it in time: sampling or time quantization. Discretize it in value/amplitude: quantization or amplitude quantization. Reverse quantization: assign real value to each quantile Reverse sampling: interpolation (reconstruction)

What do you do when you have an analog waveform?


What do you do when you have a sequence of discrete numbers?


EECS 452 Fall 2009

Lecture 9 Page 3/59

Mon 9/28/2009

Visualize sampling & reconstruction


Analog waveform 1 amplitude 0.5 0 0.5 1 0 1 amplitude 0.5 0 0.5 1 0 1 amplitude 0.5 0 0.5 1 0

0.2

0.4

0.6

0.8 x 10

1
3

Analog waveform.

Time quantized waveform

0.2 0.4 0.6 0.8 1 3 x 10 Reconstructed time quantized waveform

Discretize in time: sampling using ADC.

0.2

0.4 0.6 time in seconds

0.8 x 10

1
3

Reconstruct: order hold.

zero-

EECS 452 Fall 2009

Lecture 9 Page 4/59

Mon 9/28/2009

Comments on sampling

Given a real valued lowpass spectrum with bandwidth BW (zero to null), the sampling frequency 2BW is often called the Nyquist sampling rate/frequency.

There is good reason behind this. You may recall from 216 and/or 451. We will take another more realistic look at this in another two lectures.

In practice one often should sample at a rate of at least two or three times the Nyquist sampling rate. It is also common practice to take the analog signal through an anti-alias lter before sampling.

We will see more details on this later, but this is basically a low pass lter to get rid of high frequency components in the analog signal. The AIC23 used on the C5510 DSK has built in anti-alias lters. The cuto frequencies change with the selected sampling rate.
Lecture 9 Page 5/59 Mon 9/28/2009

EECS 452 Fall 2009

Interesting audio frequencies

Many waveforms can have energy beyond a band of interest. Voice: fundamental around 150 Hz, overtones to about 5 kHz. male fundamental about 120 Hz. female fundamental about 200 Hz. bass low E is 82.4 Hz. soprano high C is 1,046.5 Hz. 27.5 Hz (A0) to 4816 Hz (C8).

Piano:

Normal young adult hearing range is 20 Hz to 20,000 Hz. Telephone nominally passes range 300 Hz to 3200 Hz.

EECS 452 Fall 2009

Lecture 9 Page 6/59

Mon 9/28/2009

Common sampling rates

Common sampling rates: standard telephone system wideband telecommunications home music CDs professional audio DVD-Audio instrumentation, RF, video 8 kHz 16 kHz 44.1 kHz 48 kHz 192 kHz extremely fast

EECS 452 Fall 2009

Lecture 9 Page 7/59

Mon 9/28/2009

Most common A/D techniques


There are several additional ways in which the conversion of an analog waveform into a series of numbers can be implemented.

Pencil and paper. Dual slope integration. Successive approximation. R-2R resistive ladders. charge redistribution. Flash. Delta-sigma (DSP systems in their own right).

EECS 452 Fall 2009

Lecture 9 Page 8/59

Mon 9/28/2009

Successive approximation A/D


Sampling: uses a track and hold to capture a voltage on a capacitor. Quantization: uses a local voltage reference bits of a D/A converter; they are successively switched so as to match the D/A output to the captured voltage. High speed, high MHz is possible. Common accuracies range from 8 to 16 bits. Successive approximation converters can also be pipelined to develop a few bits at a time as values pass through the pipeline. This provides high speed at the cost of a small of delay.
Figure from Atmel AD023 data sheet.

EECS 452 Fall 2009

Lecture 9 Page 9/59

Mon 9/28/2009

Flash A/D (1/2)


Multiple comparators: determine all bits at the same time. VERY fast. Note that there is no explicit sampling, but the comparators are controlled by clock tics. What is the output for reference 4V and input 2.5? How many possible output values?

EECS 452 Fall 2009

Lecture 9 Page 10/59

Mon 9/28/2009

Flash A/D (2/2)


CLK CLK

VRT

Analog Input Preamp Comparator 256

CLOCK BUFFER DEMUX CLOCK BUFFER

255

DRB (DATA READY) D8 (OVR) D7 (MSB) D6 D8B D7B DRB (DATA READY) D8B (OVR) D7B (MSB)

152

D6B D5B D4B

256 TO 8 Bit Decoder With Metastable Error Correction

D5B

ECL Output Buffers And Latches

151

D3B D2B

D4B D3B D2B D1B D0B (LSB) DRA (DATA READY) DRA (DATA READY) D8A (OVR) D7A (MSB)

128

1:2 DEMULTIPLEXER

D5

D1B D0B

VRM

127

D4

D8A D7A D6A D5A D4A D3A

64

D3

63

D2

D5A D4A D3A D2A D1A D0A (LSB)

D1

D2A D1A

D0 (LSB)

D0A

VRB

Figure from Fairchild Semiconductor SPT7750 data sheet.

EECS 452 Fall 2009

Lecture 9 Page 11/59

BANK A

D6A

BANK B

D6B

Mon 9/28/2009

Delta-sigma A/D

 
 






Basic idea is to save bandwidth by sending the changes (often encoded using a single bit) in a waveform rather than the full waveform. Samples very fast. Exploits the cheap availability and small size of todays digital logic. More details to come in a later lecture.

EECS 452 Fall 2009

Lecture 9 Page 12/59

Mon 9/28/2009

Going from voltages to numbers


Consider a B -bit A/D converter. Two common mappings from voltages to numbers are: Oset Binary. Most negative value is 0. Most positive value is 2B 1. Twos Complement. Most negative value is 2B 1 . Most positive value is 2B 1 1.

To convert between the two formats, invert the most signicant bit.
EECS 452 Fall 2009 Lecture 9 Page 13/59 Mon 9/28/2009

Twos complement scaling


Given a B -bit A/D output value: most positive value is 2B 1 1, most negative value is 2B 1 . Note that these limits are slightly asymmetric. Usually place zero volts mid input step. This will be seen to give zero DC oset with a zero DC input. Assume a maximum input voltage excursion of Vp Assign voltage Vp to 2B 1 . Voltage step size per count change is V = Vp /2B 1 for uniform quantization. Often write V simply as and refer to it as a quanta. That is, the voltage change required for a increment of one in the A/D converter output value.

EECS 452 Fall 2009

Lecture 9 Page 14/59

Mon 9/28/2009

Uniform quantization
Converts analog voltages into B-bit numbers. Change in number by 1 is one quanta. One quanta change one voltage change. = Vp /2B 1 Usually place A/D bits into computer word most signicant bits. Note the placement of the zero input relative to the output count. Plots x-axis is normalized.
EECS 452 Fall 2009 Lecture 9 Page 15/59 Mon 9/28/2009

4bit linear quantizer input to output transfer function 8 6 Quanizer integer output 4 2 0 2 4 6 8 1 0.75 0.5 0.25 0 0.25 0.5 0.75 Quantizer analog input level 1

Non-uniform quantization: mu-law companding

COMpression and exPANDing of digitized waveforms (companding).

Originally developed for use in digital parts of the telephone system.

International Telecommunication Union ITU-T Recommendation G.711. Instead of using equal step sizes, use smaller steps for small input values. Why? What if you have a weak signal?

Idea: progressive taxation

EECS 452 Fall 2009

Lecture 9 Page 16/59

Mon 9/28/2009

-law transfer function


How to implement?

Idea one: come up with unequal step sizes for the entire range. idea two: lets skew the signal instead.

stretch the small values and compress the large values. Now apply a uniform quantizer. This has an equivalent eect of assigning small steps when input is small, and large steps when input is large. y = Q sgn(x) ln(1 + |x |/V ) ln(1 + ) , = 255.

V normalizes the input signal.


Implemented as logarithmic xed-point number sign, 3-bit. characteristic and 4-bit mantissa (8-bit code word). Performance roughly equivalent to 14-bit uniform (linear) encoding.
Lecture 9 Page 17/59 Mon 9/28/2009

EECS 452 Fall 2009

A/D converter worries

The real world seems to always get in the way. Oset Error Gain Error Dierential Nonlinearity (DNL) Error Integral Nonlinearity (INL) Error Absolute Accuracy (Total) Error Aperture Error

A good reference is TIs Understanding Data Converters, SLAA013, July 1995.

EECS 452 Fall 2009

Lecture 9 Page 18/59

Mon 9/28/2009

Errors introduced in A/D

Now lets take a look at the amount of error we introduce in the process of A/D.

We know if we dont sample fast enough we get into trouble; details to come later. In quantization and encoding, analog values (uncountably innite) are converted into a nite number of values. Information is lost.

Digital values are most often represented using binary words. Common A/D word sizes are 8, 10, 12, 14, 16 and 24 bits. A word having B bits can represent 2B numeric values. The more A/D bits the greater the quality of the sampled data.

EECS 452 Fall 2009

Lecture 9 Page 19/59

Mon 9/28/2009

Quantizer model and assumptions

The quantization errors are uniformly distributed over the range from /2 to /2. The quantization errors are independent of the waveform being quantized. Quantization error values are independent of each other. This leads to the concept of a white spectrum. The statistics of the quantization errors are wide sense stationary. A wide sense stationary random process is one whose rst and second moments are time invariant and whose autocorrelation function is invariant to time shift.
Mon 9/28/2009

xz n~ nE=F xz=Z nExzF

xz xz=Z xz=H xz

xz

EECS 452 Fall 2009

Lecture 9 Page 20/59

Uniformly quantized sinewave and error


Sinewave quantized using 4bits 1 0.5 Amplitude 0 0.5 1 0 0.1 0.2 0.3 0.4 0.5 0.6 Sinewave period 0.7 0.8 0.9 1

Sinewave quantization error using 4bit quantizer 1 0.5 Quanta 0 0.5 1 0 0.1 0.2 0.3 0.4 0.5 0.6 Sinewave period 0.7 0.8 0.9 1

EECS 452 Fall 2009

Lecture 9 Page 21/59

Mon 9/28/2009

Really?

Do You Really Expect Me to Believe Those Assumptions? No. But you do have to start somewhere and these provide a relatively simple starting point. In actual practice these assumptions have proven to give surprisingly good results. Systems designed based on them often work as expected. On occasion, when designers run into problems they often think it is because of something they did. They forget that the theory is only an approximation to reality. Dont forget this!

EECS 452 Fall 2009

Lecture 9 Page 22/59

Mon 9/28/2009

Quantization noise model


xz xz H H xz=Z xz=H xz

The noise mean and variance are: e


2 e

= =

0,
2 Vp 2 = 12 12 22B 2

Signal-to-noise ratio: SQNR SQNR(dB) = = =


EECS 452 Fall 2009

12 22B Px Px = Px = 3 2 2 2B 2 Pe 3Vp Vp 10 log10 SQNR = 10 log10 constant given Px + 6B


Lecture 9 Page 23/59 Mon 9/28/2009

3Px 2B 2 + 10 log10 2 Vp

Peak to RMS worries


Most signals are much more unstructured than is a sinusoid and one has to worry about the peak-to-rms ratio in order to minimize clipping. This means using an rms level somewhat reduced from the maximum safe sine wave value. Basically one need to set the normal level and allocate some head room for when the signal is large. For example working with a music selection with soft passages and loud passages. OFDM (orthogonal frequency division multiplexed) communication systems generally have a signicant peak-to-rms dynamic range problem. Choosing a maximum safe level is often done in a somewhat hand wavy manner.

EECS 452 Fall 2009

Lecture 9 Page 24/59

Mon 9/28/2009

Now onto D/A . . .

Reversing the quantization is easy. One of many ways: voltage divider. Whats the input-output mapping? Is there anything wrong with this scheme?

EECS 452 Fall 2009

Lecture 9 Page 25/59

Mon 9/28/2009

Reversing the sampling process . . .


Spectrum of the reconstructed waveform 0.5 Magnitude 0.4 0.3 0.2 0.1 0 3 2 1 0 1 Frequency (Hz) 2 3 x 10
4

Theoretically we can perfectly reconstruct if we sample fast enough. In practice sampling itself is imperfect. Example D/A output:

Three tones: 200 Hz, 1000 Hz, and 3500 Hz, fs = 8000 Hz. Using a zero-order hold D/A converter. The dashed line shows the eects of the zero-hold on the spectrum magnitude. It possesses images of the baseband spectrum.

EECS 452 Fall 2009

Lecture 9 Page 26/59

Mon 9/28/2009

Anti-image lter

Zero-order hold has weighted (shaded) the spectrum. Low pass lter needed to attenuate/remove the images. Might correct for the zero-order hold amplitude shading. Low pass cuto will nominally be somewhat below fs /2. May have concerns about phase distortion. Filter may be solely analog or switched capacitor analog cascade.

EECS 452 Fall 2009

Lecture 9 Page 27/59

Mon 9/28/2009

Quick summary of A/D and D/A

Basics of converting an analog signal to digital form. A/D: sampling and quantization. D/A: the reverse of the above processes. Next: the ADC and DAC on Spartan-3 and their use in Lab 4.

EECS 452 Fall 2009

Lecture 9 Page 28/59

Mon 9/28/2009

Digilent Spartan-3 family boards


Digilent sells a variety of design platforms based on Spartan-3 variants. These dier in terms of

Spartan-3 sub-family, S3, S3E. Size of the FPGA used. The type of external memory, static RAM, DRR2, paged and so on. Connectors used to connect o board devices to the FPGA. The over voltage protection included on the FPGA lines. extra and/or dierent o board connectors. Eight slide switches. Four digit seven segment display. Four push buttons. At least four 6-pin PMod connectors. A special board (MIB) is needed for the S3SB in order to add these.
Lecture 9 Page 29/59 Mon 9/28/2009

These boards have in common


EECS 452 Fall 2009

Spartan-3 Starter Board used by EECS 452


FPGA : XC3S1000 (106 gates) Package : FT256 (a ball grid package) Speed: -4 (not the fast part) EPROM : XCF04S (larger than on base board) Board powered by 5 Volt supply. Regulated voltage : 3.3 Volts. Signal lines are NOT 5 Volt tolerant!!!! Three 40-pin connectors, A1, A2 and B1. Supplied with Parallel Port JTAG programming cable. Cable supported by IMPACT and ExPort. Connector A2 cabled to C5510 External Peripheral Interface connector. Module Interface Board on B1 is used to convert 40-pin connector to 8 6-pin PMod connection positions.
Lecture 9 Page 30/59 Mon 9/28/2009

EECS 452 Fall 2009

Some available PMod boards

Dual 12-bit A/D converter, AD1. Dual 12-bit D/A converter, DA2. Four slide switches, SWITCH. Digital input, DIN1. Dual BNC, CON2. Speaker/headphone amplier, AMP1. Rotary encoder, ENC. and many more.

Given sucient lead time we can create our own project specic boards.

EECS 452 Fall 2009

Lecture 9 Page 31/59

Mon 9/28/2009

Digilent D/A, A/D and MIB

P1: CS P2: Data1 J1 Connector ADC 1 Filter P1 J2 Connector P2 P3: Data 2 P4: Clk P5: GND P6: Vcc AD1 Circuit Diagram ADC 2 P3 P4 P5 P6

Filter

From Digilent data sheets.

We have modied our MIB boards to have sockets in positions J1, J3, J5, J7 and pins in the other positions. The UCF naming is J1pmod_a, J3pmod_b, J5pmod_c and J7pmod_d.

EECS 452 Fall 2009

Lecture 9 Page 32/59

Mon 9/28/2009

Pmod, MIB and other connectors


Pins on MIB connect to pins on PMod modules. We have installed sockets on alternate positions. Use socket-socket cables to connect pins. Make sure VB on MIB connects to VCC on PMod! Make connections with power OFF! For now connector A1 is not being used. (Actually is connected to memory bus which is used by the XVGA entity.) A2 is reserved for connecting to DSK peripheral interface bus to the Spartan-3 Starter Board. B1 is left for use by other devices. MIB goes here ! The Spartan-3 Starter Boards has provision for lots of connections. This is the primary reason we chose it.
Lecture 9 Page 33/59 Mon 9/28/2009

On the S3SB:

EECS 452 Fall 2009

PMod pins
PMod pin names used on the MIB.

IO1 IO2 IO3 IO4 V

general I/O general I/O general I/O general I/O power ground. never use any voltage other than 3.3 volts.

GND

Names used on individual boards vary with the board. Please try very hard to connect V to the V pin on the PMod being plugged in. Things will often work better that way.

EECS 452 Fall 2009

Lecture 9 Page 34/59

Mon 9/28/2009

EECS 452 standard PMod placement

Our goal is to always place, one to all, the switch, A/D and D/A PMod boards as follows.

Four slide switch PMod goes J1 (PMod A). A/D PMod goes J3 (PMod B). available, J5 (PMod C). D/A PMod goes J7 (PMod D).

It makes life a bit simpler having some predictability.

EECS 452 Fall 2009

Lecture 9 Page 35/59

Mon 9/28/2009

Lab exercise 4

Demonstrates:

interfacing the PMod DA2 D/A converter, DDS using the S3SB, interfacing the PMod AD1 A/D converter, single supply level shifting, S3SB electret microphone interface. simple A/D in, D/A out loop, S3SB/C5510 link, C5510 master, metastability demonstration, S3SB/C5510 link, S3SB master.

The exercise introduces the dual-channel A/D and D/A PMod modules.

EECS 452 Fall 2009

Lecture 9 Page 36/59

Mon 9/28/2009

Combined top-down, bottom-up design


The only real design eort was implementing the bit serial interfaces for the D/A and A/D devices.

Two chips mounted per PMod board. One converter per chip. Four lines: data 1, data 2, sync, clock. Max clock rates of 30 (D/A) and 20 (A/D) MHz.! 16-bit data frames are used.

Low level entities were created rst. Attention was given on these would be used by higher levels. Tested using test VHDL. These might be considered device drivers written in VHDL.

EECS 452 Fall 2009

Lecture 9 Page 37/59

Mon 9/28/2009

Starting with the D/A


A simple test is to run a counter and send the count values to the D/A and observe the waveform. About as basic test you can do. Check the schematic and data sheet to

determine the part number. see how the part is designed into the board. nd the PMod pin signal assignments.

Check the D/A data manual to determine


how it works. Actually, to learn how to make it work. the signal timings. the mapping from digital input values to output voltages.

EECS 452 Fall 2009

Lecture 9 Page 38/59

Mon 9/28/2009

The Digilent PMod-DA2 module


Analog Outputs D1 DAC121S101 D/A Converter J2 Connector Sync, Clock DAC121S101 D/A Converter

J1 Connector

D2 GND

VCC

The PMod-DA2 uses two National Semiconductor DAC121S101 12-bit digital-to-analog converters with rail-to-rail output. Uses a bit-serial interface. Maximum serial clock rate is 30 MHz. Operates using supply voltages in the range 2.7V to 5.5V.
Figure from the PMod Digilent data sheet.

EECS 452 Fall 2009

Lecture 9 Page 39/59

Mon 9/28/2009

The DAC121S101 D/A


Max serial clock : 30 MHz Data uses oset binary. Analog output updates on 16th shift clock falling edge.

From the National Semiconductor data sheet.

20114906

EECS 452 Fall 2009

Lecture 9 Page 40/59

Mon 9/28/2009

How to make the D/A work


Here are some observations/guesses about the control of the D/A. These are based on the timing diagram and written signal descriptions contained in the data sheet. Use of a state machine in the D/A control logic is assumed.

sync_n can remain high between updates going low when a serial transfer is to start. The start of a serial transfer is detected by sampling sync_n using the rising edges of sclk. Data bits are sampled on the falling edges of sclk. There is a counter in the D/A that loads D/A holding register from the input shift register. Possibly on the 16th falling edge of sclk. After loading the DAC register the state machine waits for the next high to low transition on sync_n

EECS 452 Fall 2009

Lecture 9 Page 41/59

Mon 9/28/2009

Going from now to next


if rising_edge(clk) then what shall be <= depends upon what now is; end if; ------------------------------------------------------------------------------------------------------counter <= counter+1; if counter = 15 then whatever end if; What happens when entering this code segment with counter containing 14? Does whatever happen or not?
EECS 452 Fall 2009 Lecture 9 Page 42/59 Mon 9/28/2009

D/A driver body


entity pmod_dac0 is Port ( go : in STD_LOGIC; da_a : in STD_LOGIC_VECTOR (11 downto 0); da_b : in STD_LOGIC_VECTOR (11 downto 0); pmod : out STD_LOGIC_VECTOR (3 downto 0); clk : in STD_LOGIC); end pmod_dac0; architecture Behavioral of pmod_dac0 is signal sync_n, sclk : std_logic := 1; signal counter : std_logic_vector(3 downto 0); signal d_a, d_b : std_logic_vector(11 downto 0); signal sr_a, sr_b : std_logic_vector(15 downto 0); signal goo, clear_goo : std_logic := 0; signal mygoo : std_logic_vector(1 downto 0); type t_state is (s_idle, s_wait, s_run); signal state : t_state := s_idle; begin pmod(0) <= sync_n; pmod(1) <= sr_a(15); pmod(2) <= sr_b(15); pmod(3) <= sclk; process(go, clear_goo) is begin if clear_goo = 1 then goo <= 0; elsif rising_edge(go) then d_a <= da_a; d_b <= da_b; -- copy input values goo <= 1; -- note go happened end if; end process; -- main process goes here end Behavioral;

EECS 452 Fall 2009

Lecture 9 Page 43/59

Mon 9/28/2009

D/A driver main process


process(clk, da_a, da_b) is begin if rising_edge(clk) then sclk <= not sclk; -- generate clk/2 shift clock mygoo <= mygoo(0) & goo; -- sample go signal case state is when s_idle => sclk <= 1; -- hold DA clock high if mygoo = "01" then -- rising edge test sr_a <= "0000" & not d_a(11) & d_a(10 downto 0); sr_b <= "0000" & not d_b(11) & d_b(10 downto 0); counter <= (others => 0); sync_n <= 0; sclk <= 0; clear_goo <= 1; state <= s_wait; end if; when s_wait => clear_goo <= 0; state <= s_run; when s_run => if sclk = 0 then sr_a <= sr_a(14 downto 0) & 0; sr_b <= sr_b(14 downto 0) & 0; counter <= counter+1; if counter = 15 then sync_n <= 1; state <= s_idle; end if; end if; end case; end if; end process;

EECS 452 Fall 2009

Lecture 9 Page 44/59

Mon 9/28/2009

Initiating a conversion

This entity is designed so that the go and the clk signal can exist in dierent clock domains. Moving a signal between clock domains usually involves a level in one domain whose change signals an event, and a clock in a second domain that samples the event signal. If the setup time on the register being used to latch the event is smaller than required, the register can enter a metastable state. A metastable state is one where the latch knows that a decision is needed about whether or not the event occurred, but it cant decide. In theory this can take forever. Metastable events cannot be avoided. However there are things that one can do to minimize the probability of a metastable state becoming a problem.

EECS 452 Fall 2009

Lecture 9 Page 45/59

Mon 9/28/2009

Walk through

50 MHz clock is assumed. 25 MHz SCLK is generated unless explicitly held high. 25 MHz is within the the D/A 30 MHz limit. GO pulses are assumed to be spaced at least 1 s apart. Only needs to be one 50 MHz clock period long. When GO is 1 then set four-bit counter to 0, copy 12-bit a and b values into 16-bit shift registers with normal ag bits. Send sync_m and SCLK low. Skip the low part of SCLK. Loop changing state only when SCLK is low. At the low to high transition, shift data, increment the counter. However, if the counter is 15 then also set sync_m high and go back to idling state.

Recall that the values to be updated are updated on the NEXT rising edge of the clk.
EECS 452 Fall 2009 Lecture 9 Page 46/59 Mon 9/28/2009

D/A timing diagram

= | ~=~~ NR NQ NP NO NN NM

EECS 452 Fall 2009

Lecture 9 Page 47/59

Mon 9/28/2009

Simple test using ramps


entity rampgen is Port ( go : out STD_LOGIC; ramp_a : out STD_LOGIC_VECTOR (11 downto 0); ramp_b : out STD_LOGIC_VECTOR (11 downto 0); led : out STD_LOGIC_VECTOR(7 downto 0); clk : in STD_LOGIC); end rampgen; architecture Behavioral of rampgen is signal a_ramp, b_ramp : std_logic_vector(11 downto 0); signal counter : std_logic_vector(5 downto 0); begin ramp_a <= a_ramp; ramp_b <= b_ramp; process(clk) is begin if rising_edge(clk) then counter <= counter+1; go <= 0; if counter = 0 then go <= 1; a_ramp <= a_ramp+1; b_ramp <= b_ramp+3; end if; end if; end process; end Behavioral;
EECS 452 Fall 2009 Lecture 9 Page 48/59 Mon 9/28/2009

D/A test top


entity DACtest0top is Port ( pmod_d : out STD_LOGIC_VECTOR (3 downto 0); led : out STD_LOGIC_VECTOR (7 downto 0); mclk : in STD_LOGIC); end DACtest0top; architecture Behavioral of DACtest0top is signal signal signal signal begin pmod_d <= pmod; clk <= mclk; -- reduce the clock when generating scope display ---clk <= dclk(3); -- normally a big no-no! led <= ramp_b(11 downto 4); dac : entity work.pmod_dac0 port map(go => go, da_a => ramp_a, da_b => ramp_b, pmod => pmod, clk => clk); ramper : entity work.rampgen port map(go => go, ramp_a => ramp_a, ramp_b => ramp_b, clk => clk); process(mclk) is begin if rising_edge(mclk) then dclk <= dclk+1; end if; end process; end Behavioral; clk, go : std_logic; dclk : std_logic_vector(3 downto 0); pmod : std_logic_vector(3 downto 0); ramp_a, ramp_b : std_logic_vector(11 downto 0);

EECS 452 Fall 2009

Lecture 9 Page 49/59

Mon 9/28/2009

Using the D/A to create a sine wave DDS

Now that we have a D/A driver and know how to make a counter lets make a sine wave direct digital synthesizer! The Xilinx CORE Generator provides modules for a sine/cosine lookup table and for a DDS. We could use these. Some other day. For now we will go DIY (using the DDS VHDL code we showed in the previous lecture). To create a DDS we need a ROM and we need to program the ROM.

EECS 452 Fall 2009

Lecture 9 Page 50/59

Mon 9/28/2009

Working with block RAM


Something like 24 18K bit blocks of dual port memory on the S-3/1000 boards. Divided into parity and data sections. Word size is independently congurable for each port. Are initialized upon the FPGA is programmed. Becomes a ROM if one does not write to it. Initialized using 256 bit vectors. Can share a block RAM between ROM for a DDS and a delay memory used by a FIR lter. Use instantiation templates found in ISE. Not very dicult to work with. RAM blocks are clocked, so one need to think a bit about what happens when.

EECS 452 Fall 2009

Lecture 9 Page 51/59

Mon 9/28/2009

A simple DDS entity (1/2)


Uses two processes.

begin AC0 <= ACC0(31 downto 24); AC1 <= ACC1(31 downto 24); process(clk, reset) begin if reset = 1 then elsif rising_edge(clk) then counter <= counter_next; ACC0 <= ACC0_next; ACC1 <= ACC1_next; FTV0R <= FTV0R_next; FTV1R <= FTV1R_next; DAC_load <= DAC_load_next; end if; end process;

EECS 452 Fall 2009

Lecture 9 Page 52/59

Mon 9/28/2009

A simple DDS entity (2/2)


process(FTV0_load, FTV1_load) begin ACC0_next <= ACC0; ACC1_next <= ACC1; FTV0R_next <= FTV0R; FTV1R_next <= FTV1R; DAC_load_next <= 0; if counter = 49 then ACC0_next <= ACC0+FTV0R; ACC1_next <= ACC1+FTV1R; DAC_load_next <= 1; counter_next <= "000000"; else counter_next <= counter+1; end if; if FTV0_load = 1 then FTV0R_next <= FTV0; end if; if FTV1_load = 1 then FTV1R_next <= FTV1; end if; end process; end Behavioral;

EECS 452 Fall 2009

Lecture 9 Page 53/59

Mon 9/28/2009

Sine table initialization


-- Address INIT_00 => INIT_01 => INIT_02 => INIT_03 => INIT_04 => INIT_05 => INIT_06 => INIT_07 => INIT_08 => INIT_09 => INIT_0A => INIT_0B => INIT_0C => INIT_0D => INIT_0E => INIT_0F => 0 to 255 X"2E112B1F2826252822231F1A1C0B18F915E212C80FAB0C8C096A064803240000", X"584255F5539B51334EBF4C3F49B4471C447A41CE3F173C56398C36BA33DF30FB", X"750473B5725470E26F5E6DC96C236A6D68A666CF64E862F160EB5ED75CB35A82", X"7FF57FD87FA67F617F097E9C7E1D7D897CE37C297B5C7A7C79897884776B7641", X"776B788479897A7C7B5C7C297CE37D897E1D7E9C7F097F617FA67FD87FF57FFF", X"5CB35ED760EB62F164E866CF68A66A6D6C236DC96F5E70E2725473B575047641", X"33DF36BA398C3C563F1741CE447A471C49B44C3F4EBF5133539B55F558425A82", X"03240648096A0C8C0FAB12C815E218F91C0B1F1A2223252828262B1F2E1130FB", X"D1EFD4E1D7DADAD8DDDDE0E6E3F5E707EA1EED38F055F374F696F9B8FCDC0000", X"A7BEAA0BAC65AECDB141B3C1B64CB8E4BB86BE32C0E9C3AAC674C946CC21CF05", X"8AFC8C4B8DAC8F1E90A2923793DD9593975A99319B189D0F9F15A129A34DA57E", X"800B8028805A809F80F7816481E38277831D83D784A485848677877C889589BF", X"8895877C8677858484A483D7831D827781E3816480F7809F805A8028800B8001", X"A34DA1299F159D0F9B189931975A959393DD923790A28F1E8DAC8C4B8AFC89BF", X"CC21C946C674C3AAC0E9BE32BB86B8E4B64CB3C1B141AECDAC65AA0BA7BEA57E", X"FCDCF9B8F696F374F055ED38EA1EE707E3F5E0E6DDDDDAD8D7DAD4E1D1EFCF05",

256 values of 16-bits. Used MATLAB to generate. Primary thing to realize is that the least signicant bit is on the right and the most signicant bit is on the left.

EECS 452 Fall 2009

Lecture 9 Page 54/59

Mon 9/28/2009

The Digilent PMod-AD1 module


P1: CS P2: Data1 J1 Connector ADC 1 Filter P1 J2 Connector P2 P3: Data 2 P4: Clk P5: GND P6: Vcc AD1 Circuit Diagram ADC 2 P3 P4 P5 P6

Filter

That was D/A. Now lets take a look at the A/D PMod. The PMod-AD1 uses two National Semiconductor ADCS7476 12-bit analog-to-digital converters supporting rail-to-rail input. Uses a bit-serial interface. Maximum serial clock rate is 20 MHz. Operates using supply voltages in the range 2.7V to 5.25V.
Figure from the PMod Digilent data sheet.

EECS 452 Fall 2009

Lecture 9 Page 55/59

Mon 9/28/2009

The ADCS7476 A/D


Max serial clock : 20 MHz Max sample rate: 1 MHz Data uses oset binary. Input switches from track to hold on falling edge of the sync signal.
From the National Semiconductor data sheet.

EECS 452 Fall 2009

Lecture 9 Page 56/59

Mon 9/28/2009

Shifting the voltage: A/D input using a single supply


oO oP oQ oN ~
J H

oR

Analysis of this is included in the lab write-up. A common problem well encounter is that our signals are zero referenced: it is centered on zero and swing between positive and negative voltage levels. Most of todays signal sources are voltage sources and DC coupled sources. The problem is that the ADC expects voltages from 0 to Vcc. So we need to shift the signal voltage.
EECS 452 Fall 2009 Lecture 9 Page 57/59 Mon 9/28/2009

A/D driver body


entity pmod_adc0 is Port ( go : in STD_LOGIC; ad_a : out STD_LOGIC_VECTOR (11 downto 0); ad_b : out STD_LOGIC_VECTOR (11 downto 0); pmod : inout STD_LOGIC_VECTOR (3 downto 0); clk : in STD_LOGIC); end pmod_adc0; architecture Behavioral of pmod_adc0 is signal signal signal signal signal signal goo, clear_goo : std_logic := 0; sclk, cs_n : std_logic := 1; ad0, ad1 : std_logic; mygoo : std_logic_vector(1 downto 0); counter : std_logic_vector(3 downto 0); ar_a, ar_b : std_logic_vector(11 downto 0);

type t_state is (s_idle, s_convert); signal state : t_state; begin pmod(0) <= cs_n and (not goo); ad0 <= pmod(1); ad1 <= pmod(2); pmod(3) <= sclk; process(go, clear_goo) is begin if clear_goo = 1 then goo <= 0; elsif rising_edge(go) then goo <= 1; end if; end process; -- main process goes here end Behavioral;

EECS 452 Fall 2009

Lecture 9 Page 58/59

Mon 9/28/2009

A/D driver main process


process(clk) is begin if rising_edge(clk) then sclk <= not sclk; mygoo <= mygoo(0) & goo; case state is when s_idle => sclk <= 1; if mygoo = "01" then cs_n <= 0; counter <= (others => 0); state <= s_convert; end if; when s_convert => clear_goo <= 1; if sclk = 1 then ar_a <= ar_a(10 downto 0) & ad0; ar_b <= ar_b(10 downto 0) & ad1; counter <= counter+1; if counter = 15 then ad_a <= not ar_a(10) & ar_a(9 downto 0) & ad0; ad_b <= not ar_b(10) & ar_b(9 downto 0) & ad0; clear_goo <= 0; cs_n <= 1; state <= s_idle; end if; end if; end case; end if; end process;

EECS 452 Fall 2009

Lecture 9 Page 59/59

Mon 9/28/2009

You might also like