3 Implementation
Setup and Main Loop
When the program is started, the setup of the external memory and
internal peripherals is initiated. This involves the setup of the SPI for data
storage device interfacing, ADC for sampling of the microphone, DAC for output to
the speaker, PORT settings for buttons, a timer for correct sampling and playback
frequency, and event system for signaling the ADC. Separate buttons are set up to
trigger the record, playback, and erase subroutines. This functionality is depicted
in the figure below.
Record
After the record button is pressed, the routine depicted in the figure
below is initiated. The flowchart on the left indicates functionality in software,
and the one on the right indicates hardware. ADC is triggered to start a conversion
when the sampling timer overflows. An ISR is triggered when the conversion result is
ready, which stores the result in a buffer. When the buffer is full, it is sent to
the external memory by the software routine (signaling from the ISR to the software
routine is made via a globally defined flag). Two alternating buffers are used to
avoid loss of data.
Playback
When the playback button is pressed, the routine depicted in the figure
below is initiated. As stated before, the flowcharts on the left and right reflect
functionality in software and hardware, respectively. The sample timer overflow ISR
updates the DAC data register in order to change the output at the same rate as the
samples were taken. This results in a reconstructed signal, which is as accurate as
possible.
Erase
When the erase button is pressed, the routine depicted in the figure
below is initiated. This routine erases the external memory between the start of
memory and the last write location.