All software in this lab must be developed in C. You can debug your code in the simulator but your final code must run on the board with a DAC circuit. There are a few steps for completing this lab:...


All software in this lab must be developed in C. You can debug your code in the simulator but your final code must run on the board with a DAC circuit. There are a few steps for completing this lab:


Step 1:


Most digital music devices rely on high-speed DAC converters to create the analog waveforms required to produce high-quality sound. In this lab, you will create a very simple sound generation system that illustrates this application of the DAC. Your goal is to create an embedded system that plays three notes, representing a digital piano with three keys. The first step is to design and test a 4-bit, binary-weighted DAC; this converts four bits of digital output from the microcontroller to an analog signal. You will convert the four digital bits to an analog output using a simple resistor network. During the static testing phase, you will connect the DAC analog output to a voltmeter or theVisual Analyzer program(Links to an external site.)(Windows only)and measure resolution, range, and precision (left side of the figure below). During the dynamic testing phase you will connect the DAC output to headphones and listen to sounds created by your software (right side of the figure below).



Testing the DAC


It doesn’t matter what range the DAC is, as long as there is an approximate linear relationship between the digital data and the speaker current. You will want to focus on the sound quality rather than the sound’s loudness. The quality of the music will depend on both the hardware and software. The precision of the DAC, external noise, and the dynamic range of the speaker are some of the hardware factors. Software factors include the DAC output rate and the number of data points stored in the sound data.


Step 2:


The second step is to design a low-level device driver for the DAC. Remember, the goal of a device driver is to separate what the device does from how it works. “What it does” means the general descriptions and function prototypes ofDAC_InitandDAC_Outthat are placed inDAC.h. “How it works” means the implementations ofDAC_InitandDAC_Outthat will be placed inDAC.c.


Step 3:


The third step is to design a low-level device driver for the three keys of the piano. For example, you could create public functionsPiano_InitandPiano_In, wherePiano_Inreturns a logical key code for the pattern of keys that are pressed. You may design this driver however you wish, but the goal is to abstract the details of how it works (which port, which pin) from what it does (which key pressed).


Step 4


The fourth step is to organize the sound generation software into a device driver. You will need a data structure to store the sound waveform. You are free to design your own format, as long as it uses a formal data structure. Although you will be playing only three notes, the design should allow additional notes to be added with minimal effort. For example, you could create public functionsSound_InitandSound_Play(note), where the parameter “note” specifies the frequency (or pitch) of the sound. For example, callingSound_Play(Off)makes it silent and callingSound_Play(C)plays the note C. A background thread within the sound driver implemented with SysTick interrupts (see the provided code for this lab) will fetch data out of your music structure and send them to the DAC.


Step 5:


The last step is to write a main program that links the modules together creating the digital piano.


Lab Procedure:



Read sections 9.1, 9.2, 9.4, 9.6, 10.1, 10.2, and 10.3 in the textbook and look at the lecture on DACs, sound, and music generation.Start with the CCS project for Lab 4 for theMSP432

Download MSP432
orTiva-C

Download Tiva-C
. The textbook’s author has aninteractive website(Links to an external site.)that examines DACs and sound generation. Prof.Faller has avideo example(Links to an external site.)


of how to test your sound by usingVisual Analyzer; note, more information about how to operate a DMM (digital multi-meter) was provided in Lab 2. Use headphones to test your sound too, butbe very careful of the volume; try listening with headphones away from your ears first. You will need to complete the following parts to complete this lab:


Part A:


Decide which port pins you will use for the inputs and outputs. Avoid the pins with hardware already connected. Design the DAC converter using a simple resistor-adding technique. A 4-bit, binary-weighted DAC uses resistors in a 1/2/4/8 resistance ratio. Select values in the 1.5 kΩ to 240 kΩ range. For example, you could use 1.5 kΩ, 3 kΩ, 6 kΩ, and 12 kΩ (as shown below). Remember, you can create double/half resistance values by placing identical resistors in series/parallel.



Example DAC


Part B:


Use an ohmmeter to determine which two wires to connect on your audio jack (see the figure below). You have the option of connecting just the left, just the right, or both channels of the headphones (for one channel, connect pin 1 to ground and pin 3 to the DAC output).



Audio jack schematic


Part C:


Write the device driver for the DAC interface. Include at least two functions that implement the DAC interface. For example, you could implement the functionDAC_Initto initialize the DAC, and the functionDAC_Outto send a new data value to the DAC. Place all code that accesses the DAC in a separateDAC.csource file. Add aDAC.hheader file with the prototypes for public functions. I recommend writing a description of how to use this module in the comments of the header file.


Part D:


Begin with the static testing of the DAC. You will write a simple main program to test the DAC, similar in style as the program shown below. You are free to debug this system however you wish, but you must debug the DAC module separately. You should initially debug your software in the simulator; you should closely examine the port registers in the debugger. Single step this program and compare the digitalDatato the analog voltage at the Voutwithout the speaker attached; i.e., the left side of the first figure at the beginning of this lab document.




#include
#include "DAC.h"
#include "msp432p401r.h"

void main(void) {

uint8_t Data = 0; // 0 to 15 DAC output


DAC_Init();


while(1) {

DAC_Out(Data);

Data = 0x0F & (Data+1); // 0, 1, 2, ..., 14, 15, 0, 1, 2, ...

}
}


Using Ohm’s Law and the fact that the digital output voltages will be approximately 0 and 3.3 V,make a table showing your decimal, digital outputs (0-15) and their corresponding theoretical DAC voltages; this will be similar to the 3-bit DAC example from our lecture (slide 10 of lecture 10). Use a DMM orVisual Analyzerto measure the output voltage of your DAC for all sixteen possible input combinations and report these in your lab report; this will help you debug any errors in the wiring or design of your DAC. Lastly,calculate the DAC’s resolution, range, and precision; you will put these calculations and the table of DAC values in your lab report.


Part E:


Design and write the piano keyboard device driver software. These routines facilitate the use of the three piano keys. Include at least two functions that implement the piano keyboard interface. For example, you could implement the functionPiano_Initto initialize the switch inputs, and the functionPiano_Inthat returns a logical key code for the pattern of switches that are pressed. Place all code that directly accesses the switches in a separatePiano.csource file. Add aPiano.hheader file with the prototypes for public functions. I recommend writing a description of how to use this module in the comments of the header file.


Part F:


Design and write the sound device driver software. The input to the sound driver is the pitch of the note to play. SysTick interrupts will be used to set the time in between outputs to the DAC. Include at least two functions that implement the sound output. For example, you could implement the functionSound_Initto initialize the data structures, callDAC_Init, and initialize the SysTick interrupt. You could implement a functionSound_Play(note)that starts sound output at the specified pitch. Place all code that implements the waveform generation in a separateSound.csource file. Add aSound.hheader file with the prototypes for public functions. I recommend writing a description of how to use this module in the comments of the header file.


When you wish to play a new note you should just change the SysTick reload value, changing the interrupt period, without completely reinitializing SysTick. One approach to debugging is to attempt creating a sine wave with a constant frequency. Just run SysTick periodic interrupts and output one DAC value each interrupt.For your report, show your work and calculate the SysTick load value (the SysTick interrupt period) for each note that your piano can play.


Part G:


Write a main program to implement the three-key piano. I recommend making a heartbeat connected to an LED so you can see your program is running. Clearly document the operation of the routines. The figure below shows a possible data flow graph of the music player. Debug the individual components (switch input, static DAC output, and SysTick ISR) and then combine the components together into one system on the microcontroller. When no buttons are pressed, the output will be quiet. When Button 1 is pressed, output a sine wave at one frequency. When Button 2 is pressed, output a sine wave at a second frequency. When Button 3 is pressed, output a sine wave at a third frequency. Only one button will be pressed at a time. The sound lasts until the button is released.



Dataflow graph of Lab 4


The figure below shows a possible call graph of this lab’s system. Dividing the system into modules allows for concurrent development and an easier reuse of code. Notice in the diagram that the SysTick hardware calls the SysTick ISR (you will not call the ISR yourself).



Call graph of Lab 4

Apr 08, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here