Audio Range Frequency Generator
This is a sine wave generator that works in the range from 20 Hz to 20 KHz. The signal is generated digitally by an STM32F411 microcontroller and converted to analog by a PCM5102A DAC.
Supplies
- STM32F411 board.
- PCM5102A DAC module. The module must be able to be configured for "left justified" format.
- Rotary encoder with button.
- 8 digits numerical display using MAX7219 chip.
You will also need
- a computer running Windows or Linux.
- an STLink programmer.
- connection wires (female to female).
- a soldering iron and solder.
- USB cable
Prepare the DAC Module
Use a soldering iron to remove the connection 4-L and make the connection 4-H.
This way the DAC is configured for "left justified" format instead of "I2S".
Prepare the STM32F411 Module
Download and install STM32CubeProg from st.com
Visit page st.com
Search in "products" for "STM32CubeProg" and select the "STM32CubeProg line.
Go to the "Get Software" section and select the version that fits to your operating system.
(For more informations on installation, search in "resources" for "UM2563".)
(you have to register with an e-mail in order to download the software).
Download file "FreqGen.hex".
Use the "ST-Link V2" to flash the microcontroller.
Connect MCU board with ST-Link through GND/SWSCK/SWDIO/3V3 pins
Connect the ST-Link in a USB port
Run the STM32CubeProg
Click the "Connect" button
Click "Open File" and load the hex file.
Click "Download" and after the program is loaded, click "Disconnect"
The MCU is ready!
Downloads
Connect the Pieces
Connections between MCU and DAC
DAC------- MCU
---------------------
VIN ------- 3.3V
GND ------ GND
LRCK ----- B12
DIN -------- B15
BCK ------- B10
Connections between Rotary Encoder and MCU
Encoder ------- MCU
---------------------------
CLK -------- B5
DT ---------- B4
SW --------- B6
+ ------------ 3.3V
GND ------- GND
(Note: CLK and DT may be marked as A and B)
Connections between MCU and Display
Display ----- MCU
-----------------------
VCC ----- 5V
GND ---- GND
DIN ------ A7
CS ------- B0
CLK ----- A5
Usage
Connect an earphone at DAC's output.
Power up the MCU using a USB cable.
The initial frequency is 77.215 Hz. Use the rotary encoder to increase or decrease it. Push the encoder's button to change the state from "coarse" to "fine". Now you can use the encoder to fine-tune the frequency. Push it again to return to "coarse".
(Note: the accuracy of the frequency depends on the accuracy of the crystal used by the MCU board. An additional 0.02% frequency error is introduced from the conversion of the crystal frequency to the DAC's clock)
Enjoy!