Digital sound recorder

By Zach Reiswig

Overview

Below are images of my project: the Digital Sound Recorder, which plays a binary sound file stored in memory. The first step is to load a binary sound file into the memory chip, which is done via Tera Term (software). Once it is loaded, the recorder can play back the sound file when the button is pressed. Additional parts can also be added on to the recorder (such as lights, motors, etc).

Assembly

Hardware

For my project I used a Freescale Semiconductor KL0 microcontroller (MCU Kinetics L series) to run my device's input and output functionality. It is a low price ($1.91) 32-bit core size MCU that uses an ARM Core Processor, and contains SPI, UART, and DAC. UART is used to transfer the binary sound file to SPI, which then transfers the data to memory. The sound file is then stored in the Winbond Electronics IC Flash Memory Chip W25Q40BWZPIG, which can hold up to 4M (512K x 8) in memory. The device is now ready for output. In my version of the device I use two Xbox controller motors (used, $0.50 each), a red LED light, and a small woofer (for sound output). The source of power for the device are two AA batteries.

PCB Schematic

Sound track loading into the memory chip is accomplished with an external USB-UART converter based on CP2104.

Software

The software for the device is split into two portions: code to record binary files, and code to output the sound file in memory.

Recorder

For the recorder portion, the device receives data from the binary sound file into the UART buffer (with the help of the Tera Term software), transfers it to SPI, and then stores it into memory. It is done using the following process:

  1. Initialize/configure MCU clock, low-power timer, and configuring SPI and UART modules.
  2. Looping the method SPI_transfer until the entire file is read and stored.
  3. End Program.

The SPI_transfer that occurs in software performs the following tasks: it increments a counter that contains the number of bytes that are currently in memory, reads a set number of bytes (as defined by the software), and transfers the data from the UART buffer into the SPI buffer. From there, SPI will write to the Page in memory (note, each block in the Page of memory stores up to 64KB of memory. Therefore, for binary sound files that exceed 64KB in length more than one block must be written to). After the entire file has been transferred into memory, the program will disconnect the pins and end. The data stored in memory will be in the following format: the first four bytes in memory is the file length (i.e. number of bytes in memory), and then the data for the binary sound file in memory.

Player

For the player portion, the device reads the number of bytes that are stored in memory (in my device, it is the first four bytes), sets up timer interrupts to read the data, and then reads the data when the button is pressed. It is done using the following process:

  1. Initialize/configure MCU clock, SPI, and DAC modules.
  2. Read the first four bytes from memory and save it in a register.
  3. Set a timer to provide an interrupt every 125 microseconds (in my project, I used 8 kpbs sampling rate).
  4. Read from memory whenever the button is pressed.

In the program, the first four bytes are received through the SPI Buffer and placed into a register (which will be used as a counter for reading data). Next, the program will set up the Low Power Timer (LPTMR) for 125 microsecond interrupts and configure the pins for the start of the program. Afterwards, the program will enter a loop to perform a read through of the entire sound file. In this loop, the program will read from memory through the SPI buffer, and then transfer the data to DAC Buffer. From there, it will wait for interrupt so that the data can be output. Once the entire file has been read, the program disconnects the pins and waits for the next time the button is pressed.

My program has the following feature added on (aside from reading the sound file): it will alternate between a motor on phase, a light on phase, and a pause phase according to timed intervals. These phase changes do not use another timer in the MCU to perform. Instead, the phases alternate using the same 125 microsecond interrupt/counter as a timer; using a register as a counter. I timed the time interval I wanted to use for the different phases, and converted them into their corresponding 125 microsecond values (i.e. took the time it took in seconds, converted it into microseconds, and then adjusted for the 125 microsecond value). When the value in the counter reaches zero, the program will switch the modes.

Final Thoughts

Overall, I am satisfied with the functionality of the device/program. As this is my first time programming a device, I was thrilled to see it function/work exactly like I wanted it to! I look forward to continue working on a microcontroller so that I may be able to better understand how they work.

As for the inspiration behind why I decided to build a Digital Sound Recorder, I wanted to build something that was practical to real world applications. In addition, I wanted to build something that I could finish within a timely schedule and was simple so that I could have a satisfying first experience with microcontrollers. So I decided I wanted to build a toy with a prerecorded sound in it.

Downloads


Last modified:Mon, Jan 23, 2023.

00283