1 of 19

EE 319K�Introduction to Embedded Systems

Lecture 8: Digital-to-Analog Conversion, Sound, Lab 6

Bard, Gerstlauer, Cuevas, Holt, Telang, Tiwari, Valvano, Yerraballi

http://users.ece.utexas.edu/~valvano/Volume1/E-Book/C12_Interactives.htm

http://users.ece.utexas.edu/~valvano/Volume1/E-Book/C13_Interactives.htm

Interrupts: read Sections 6.1 to 6.4

Sound: read Sections 6.5 to 6.7

Modularity, watch: https://youtu.be/2MLsbyNt8mk

8-1

2 of 19

Agenda

  • Recap
    • Data Flow Graph
    • Call Graph
    • Interrupts
      • Vector, arm, trigger, enable
      • Priority, stack, acknowledge
    • Thread communication
  • Agenda
    • Digital to Analog Conversion
    • Nyquist Theorem
    • Sound generation
    • Modular Design

Bard, Gerstlauer, Cuevas, Holt, Telang, Tiwari, Valvano, Yerraballi

Flag is 1

Flag is 0

ISR

Where are I and Flag defined?

DAC_Out(wave[I])

I = I+1

8-2

3 of 19

Conversion from Digital to Analog

  • Range
    • 0 to 3.3V
  • Resolution
    • 3.3V/63=0.05V
  • Precision
    • 6 bits
    • 64 alternatives
  • Speed
  • Monotonic

Bard, Gerstlauer, Cuevas, Holt, Telang, Tiwari, Valvano, Yerraballi

http://users.ece.utexas.edu/~valvano/Volume1/E-Book/C13_Interactives.htm

Output rate: fs = 1/Δt

Signal has frequencies 0 to ½ fs

8-3

4 of 19

6-bit Sinusoid Table

// 6-bit 64-element sine wave

const uint8_t wave[64] = {

32,35,38,41,44,47,49,52,54,56,58,

59,61,62,62,63,63,63,62,62,61,59,

58,56,54,52,49,47,44,41,38,35,

32,29,26,23,20,17,15,12,10,8,

6,5,3,2,2,1,1,1,2,2,3,

5,6,8,10,12,15,17,20,23,26,29

};

64 value sinusoid

Bard, Gerstlauer, Cuevas, Holt, Telang, Tiwari, Valvano, Yerraballi

Digital: voltage vs. time

8-4

5 of 19

Write software for continuous out

  • 293.7 Hz sine wave generated by 6-bit DAC

Bard, Gerstlauer, Cuevas, Holt, Telang, Tiwari, Valvano, Yerraballi

Speaker not connected

8-5

6 of 19

Signal to noise ratio (EE319H)

  • Continuous sine-wave without speaker
  • Connect DAC out to scope
  • Measure frequency spectrum (amplitude vs freq)

Bard, Gerstlauer, Cuevas, Telang, Tiwari, Valvano, Yerraballi

dBFS=20log10(V/3.3)

Signal = -8.7 dB

Noise = -40 dB

SNR = -8.7-40=31.3 dB

ENOB = log2(1031.3/20)

= 5.2 bits

Signal

Noise

Speaker not connected

Time domain

Frequency domain

8-6

7 of 19

Dynamic Testing DAC

Bard, Gerstlauer, Cuevas, Holt, Telang, Tiwari, Valvano, Yerraballi

What are range, resolution, precision?

PB5

PB4

PB3

PB2

PB1

PB0

Connect DAC out to scope with speaker

DAC

+

-

Speaker

8-7

8 of 19

Device driver

  • DAC software
    • Interactions via device drivers
    • Two device driver functions required

void DAC_Init(void); // initializes the device

void DAC_Out(uint8_t data); // transfers data to device

(Device driver provides the functions associated with the device but hides the detailed actions necessary to implement the functions.)

Bard, Gerstlauer, Cuevas, Telang, Tiwari, Valvano, Yerraballi

How do you make it faster?

How do you make it friendly?

8-8

9 of 19

Sound

  • Loudness and pitch
    • Controlled by amplitude and frequency

    • Humans can hear from about 25 to 20,000 Hz.
    • Middle A is 440 Hz
    • Other notes on a keyboard are determined
      • 440 * 2N/12, where N is no. of notes from middle A
    • Middle C is 261.6 Hz.
    • Music contains multiple harmonics

Bard, Gerstlauer, Cuevas, Telang, Tiwari, Valvano, Yerraballi

8-9

10 of 19

Tone Generation

uint32_t I; // 0 to 63

// 6-bit 64-element sine wave

const uint8_t wave[64] = {

32,35,38,41,44,47,49,52,54,56,58,59,61,62,62,63,63,63,62,62,61,59,

58,56,54,52,49,47,44,41,38,35,32,29,26,23,20,17,15,12,10,8,

6,5,3,2,2,1,1,1,2,2,3,5,6,8,10,12,15,17,20,23,26,29

};

  • What RELOAD is needed??
    • What is the desired sound frequency: 440 Hz
      • P = 1/f = 2272.7us
    • What is the bus clock frequency?
      • SysTick count every ∆t=12.5ns
    • How many outputs per interrupt?
    • How many entries in the table, N=64
      • P = (RELOAD+1)*N*∆t

Bard, Gerstlauer, Cuevas, Telang, Tiwari, Valvano, Yerraballi

8-10

11 of 19

Make sound vs be quiet?

  • Use a semaphore
    • Switch goes from off to touched
      • Set Flag=1
      • Update RELOAD
    • Switch goes from touched to off
      • Clear Flag=0
  • ARM/disarm
    • Arm SysTick and set RELOAD on touch
    • Disarm SysTick on release
  • RELOAD
    • Set RELOAD on touch
    • RELOAD=0 on release

Bard, Gerstlauer, Cuevas, Telang, Tiwari, Valvano, Yerraballi

DAC_Out(wave[I])

I = I+1

Flag is 1

Flag is 0

SysTick ISR

DAC_Out(wave[I])

I = I+1

SysTick ISR

Enable I=0 once at beginning

8-11

12 of 19

Other Instruments

// 6-bit 64-element bassoon wave

const uint8_t Bassoon[64] = {

33,37,37,36,35,34,34,33,31,30,29,

30,33,43,58,63,52,31,13,4,5,10,16,

23,32,40,46,48,44,38,30,23,17,12,11,

15,23,32,40,42,39,32,26,23,23,24,25,

25,26,29,30,31,32,34,37,39,37,35,34,

34,34,33,31,30};

// 6-bit 64-element guitar wave

const uint8_t Guitar[64] = {

20,20,20,19,16,12,8,4,3,5,10,17,

26,33,38,41,42,40,36,29,21,13,9,

9,14,23,34,45,52,54,51,45,38,31,

26,23,21,20,20,20,22,25,27,29,

30,29,27,22,18,13,11,10,11,13,13,

13,13,13,14,16,18,20,20,20};

Bard, Gerstlauer, Cuevas, Telang, Tiwari, Valvano, Yerraballi

8-12

13 of 19

Lab6 Data Flow Graph

Output one value to DAC

SysTick ISR

Arrows specify data flow

8-13

14 of 19

Lab6 Call Graph

Arrows represent software calling software in another module

Open Lab6 project and show how the system is organized

8-14

15 of 19

Synthesizing Digital Music

  • Nyquist’s Sampling Theorem
    • We can reproduce any bandlimited signal from its samples if we sample correctly and at a frequency, fs, that is at least twice the highest frequency component of the signal, fmax.

We are going to go 64 times faster

  • Where do we get the samples?
    • Look up in memory array
    • Compute them dynamically

Bard, Gerstlauer, Cuevas, Telang, Tiwari, Valvano, Yerraballi

8-15

16 of 19

Synthesizing Digital Music

  • What is music?
    • A short sequence of notes (e.g., midi)
    • A long sequence of raw data (e.g., wav)
      • See sound.cpp in Lab10_C++ starter files
  • What is a note?
    • Instrument or voice (sine, flute, horn etc.)
    • Volume or amplitude
    • Pitch or frequency
    • Duration
    • Envelop (amplitude vs time)

Bard, Gerstlauer, Cuevas, Telang, Tiwari, Valvano, Yerraballi

8-16

17 of 19

Tempo

Tempo defines note duration

Quarter note = 1 beat

120 beats/min => ½ s duration

Bard, Gerstlauer, Cuevas, Telang, Tiwari, Valvano, Yerraballi

8-17

18 of 19

Chord

  • Two notes at the same time
    • Superimposed waveforms
    • 262 Hz (low C) and a 392 Hz (G)

Bard, Gerstlauer, Cuevas, Telang, Tiwari, Valvano, Yerraballi

8-18

19 of 19

Instrument Characteristics

Plucked string signal with envelop

Waveform shape of a trumpet sound

Bard, Gerstlauer, Cuevas, Telang, Tiwari, Valvano, Yerraballi

8-19