110 likes | 138 Views
Learn how to generate sine waves using TI TMS320C6748 DSP hardware and software tools. Explore methods like function calls, lookup tables, difference equations, output techniques, polling, interrupts, and EDMA.
E N D
EE 445S Real-Time Digital Signal Processing LabFall 2013 Lab #2Generating a Sine Wave Using the Hardware & Software Tools for the TI TMS320C6748 DSPDebarati Kundu
Outline • Sine Wave Generation • Function Call • Lookup Table • Difference Equation • Output Methods • Polling • Interrupts • EDMA 2
Sine Wave Generation • One-sided discrete-time signal of frequency ω0 • cos(ω0n) u[n] • One-sided continuous-time signal of frequency ω0 • cos(2 π f0 t) u(t) • Using a sampling frequency fssuch that fs > 2 f0 Substitute t=nTs=n/fs • fs cos(2π (f0/fs) n) u[n] • ω0 = 2π (f0/fs) rad/sample 3
Sine Wave Generation • Function Call: Use the C library function sin(x) whenever a sine value is needed, approximated as the ratio of 2 10th order polynomials in x • Computation: 21 multiplications, 21 additions and 1 division • Memory Usage: 22 coefficients and 1 intermediate variable (x) and one constant (2) • Lookup Table: Pre-compute and store one period of samples, can even store one-half or one-quarter or one-eighth period and use symmetry. • Frequency is ω0=2πN/L • L is the period in discrete-time • Interpolate stored values to get result at all frequencies • No computation needed, just memory reads. 4
Sine Wave Generation • Difference Equation: Input x[n] and output y[n] (zero IC’s) • y[n] = (2 cos 0) y[n-1] - y[n-2] + x[n] - (cos 0) x[n-1] • Results from z-transform of cos(ω0n)u[n] • Computation: 2 multiplications and 3 additions • Memory Usage: 2 coefficients, 2 previous values of y[n] and 1 previous value of x[n] • Drawback is the build-up of error due to feedback 5
McASP CPU SR12 Poll RRDY ADC READ SR12 DATA AIC3106 Audio Codec SR11 Poll XRDY DAC WRITE SR11 Polling: • Poll XRDY (transmit ready) bit of the McASP(Multi-Channel Audio Serial Port) • until TRUE then write to SR11 register of the McASP. • If XRDY is TRUE, function returns the sample and the value 1, • If XRDY is FALSE, function returns immediately without sending a sample and • return the value 0. 4
Output Methods • Drawbacks of Polling: • Most of the time in the polling method is spent in the infinite loop waiting for the RRDY/XRDY flag to get set, • DSP is doing nothing, • A more efficient approach is to let DSP run tasks in background (modulating/demodulating, coding/decoding…), • So, serial port will interrupt background tasks when sample is received and needs to be transmitted. 7
Output Methods • Interrupts: are signals from hardware/software indicating the need for attention or change of execution. • C6748 DSP has a vectored priority interrupt controller that can handle 16 different interrupts: • RESET interrupt has highest priority, cannot be masked, • NMI (Non-Maskable Interrupt) has the second highest priority (used to notify DSP of serious hardware errors), • 2 reserved maskable interrupts come next, • 12 additional maskable interrupts (INT4-INT15) have the lowest priority. 8
CPU Interrupts from McASP CPU CODEC SR12 XRSR RDATA=1 “Ready to Read” McASP0_INT SR11 XRSR XDATA=1 “Ready to Write” • RCV/XMT INTs combined into one interrupt:MCASP0_INT • RDATA triggers when SR12 is filled (32 bits) • XDATA triggers when SR11 is emptied (32 bits) 7
… How do Interrupts Work? 1. An interrupt occurs 2. Interrupt Selector 3. Sets flag in Interrupt Flag Register (IFR) • EDMA • McASP • Timer • Ext’l pins 124+4 12 4. Is this specific interrupt enabled? (IER) 5. Are interrupts globally enabled? (GIE/NMIE) 6. • CPU Acknowledge • Auto hardware sequence • HWI Dispatcher (vector) • Branch to ISR 7. Interrupt Service Routine (ISR) • Context Save, ISR, Context Restore • User is responsible for setting up the following: • #2 – Interrupt Selector (choose which 12 of 128 interrupt sources to use) • #4 – Interrupt Enable Register (IER) – individually enable the proper • interrupt sources • #5 – Global Interrupt Enable (GIE/NMIE) – globally enable all interrupts • #6 – Hardware Interrupt (HWI) Dispatcher – the vector to the ISR 12
Example Interrupt Service Routine • interrupt void Codec_ISR() • { • /* add any local variables here */ • if(CheckForOverrun())// overrun error occurred (i.e. halted DSP) • return;// so serial port is reset to recover • CodecDataIn.UINT = ReadCodecData();// get input data samples • /* algorithm begins here */ • phaseIncrement = 2*pi*fDesired/fs; /* calculate the phase increment */ • phase += phaseIncrement; /* calculate the next phase */ • if (phase >= 2*pi) phase -= 2*pi; /* modulus 2*pi operation */ • CodecDataOut.Channel[ LEFT] = A*sinf(phase); /* scaled L output */ • CodecDataOut.Channel[RIGHT] = A*cosf(phase); /* scaled R output */ • /* algorithm ends here */ • WriteCodecData(CodecDataOut.UINT);// send output data to port • } 11