Audio Range Frequency Generator

by AntonX2 in Circuits > Audio

798 Views, 1 Favorites, 0 Comments

Audio Range Frequency Generator

IMG_20211025_195236.jpg

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

IMG_20211025_195616.jpg
PCM5102-2.jpg
IMG_20211025_194550.jpg
IMG_20211025_194208.jpg
  • 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

PCM5102-1.jpg
PCM5102-2.jpg

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

IMG_20211025_195348.jpg

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!