Starting from:
$30

$24

Lab 5: DAC, Timers and ….. Solution

In this lab, you will learn how to use more peripherals on the STM32L475VG MCU. In particular, you will:




Learn how to use UART to enable communication with a computer.



Use Matlab to obtain an audio data from a recorded voice.



Use the audio data in your MCU to generate audio on a headset.



Utilize a timer as a source of time.









Grading




15 % Audio data generated by Matlab,



10 % Button press and LED operations,



30 % DAC output generation,



40 % Time source generation by Timer,



10% For downloading data from the serial interface, 0% if you copy/paste the array.












Intro




In this assignment, your MCU operates as an speaker. You have an array of data which is your recorded voice and this voice should be listened in your headphone connected to the MCU once the blue button is pressed. The LED should be ON during the process of generating audio signal and downloading data from PC, so the user has a better understanding on the real time operations.










Matlab and Audio Data




In this assignment you need a sample data of a recorded voice. This voice is your group number. So, you must record your voice within one to two seconds while saying your group number. You can use the uploaded Matlab code to generate an array of raw data. This file generates a .csv file (comma separated). Then you can open this file in text editors and copy this data into Keil as an array of data stored into your MCU flash or memory.




To get the full point or more in this assignment, you need to download this voice into your MCU from PC through UART. You can use Matlab or other tools. There are many resources online. If you have recorded a longer voice, you can cut into the duration you prefer. You can use any other tool to record a voice or convert it into an array of raw data.




DAC




The STM32L4 family of MCU’s come with two Digital to Analog Converters (DAC’s). You must use both channels to generate stereo sounds. In this task, you will need to use the HAL drivers to initialize the DAC and feed this block from your audio data. You are already familiar with DAC block. More attention should be paid on the voltage level you are applying on the output, supported by reasons from students. Note that you must set zero voltage to the output once your output signal generation is done.




The headphone jack has three wires. One is the common or ground which should be connected to the GND on board. The other two wires should be connected to the DAC outputs. Note that the metal on the




head of jack would be GND. Be careful of short circuits if it touches other pins or components on the board.




Timer




Your MCU has many timers, from basic to advanced modes. In this assignment, your application is the most basic usage of timers which is generating interrupts whenever the counter of the timer reaches the value you set (Period). This number is called Period in settings of the timer. You are free to choose a timer from the list of basic and general-purpose timers. By referring to the Doc-2 (reference manual) you can find the clock source of the timer you selected. Now, you need to set a value for Period to obtain the desired frequency of interrupt calls. At every interrupt call you must write an element of the audio data into your DAC channels. The speed of writing to the DAC block should match the speed of sampled audio data.




You can follow instructions to generate the base project or use the uploaded base project. Note that the uploaded base project contains only the GPIO setting. You must write a code to initialize the DAC and Timer. If you are using CubeMx, select “No” when it asks for configuring all peripherals by default.


















More products