Analysis of the design case of music buzzer based on FPGA

Publisher:SerendipityRoseLatest update time:2023-05-30 Keywords:FPGA Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

This series will bring systematic learning of FPGA, starting from the most basic digital circuit foundation, the most detailed operation steps, the most straightforward verbal description, and step-by-step "fool-proof" explanations, so that students majoring in electronics, information, and communications, newcomers to the workplace, and professional developers who plan to advance can all have the opportunity to learn systematically.


Systematically mastering technology development and related requirements has potential help for personal employment and career development. I hope it will be helpful to everyone. In the future, we will continue to update the relevant content of Xilinx's Vivado, ISE and related operating software development. While learning FPGA design methods and design ideas, practical operation combined with various operating software will make your technical learning path extremely smooth, say goodbye to technical learning small BUGs that break your brain, say goodbye to the current misleading training induction, and truly learn and apply it in practice. You will understand this kind of happiness if you try it. Without further ado, here are the goods.


Music Buzzer Design

A buzzer is an electronic sounder with an integrated structure, powered by DC voltage. It is widely used as a sound-generating device in electronic products such as computers, printers, copiers, alarms, electronic toys, automotive electronic equipment, telephones, timers, etc.

ad5b60be-ee04-11ed-90ce-dac502259ad0.png

Figure 1: Buzzer picture

Buzzers are mainly divided into two types: piezoelectric buzzers and electromagnetic buzzers.

Piezoelectric Buzzer

The piezoelectric buzzer is mainly composed of a multivibrator, a piezoelectric buzzer, an impedance matcher, a resonance box, a shell, etc. Some piezoelectric buzzers are also equipped with a light-emitting diode on the shell. The multivibrator is composed of a transistor or an integrated circuit. When the power is turned on (1.5~15V DC working voltage), the multivibrator starts to vibrate and outputs an audio signal of 1.5~2.5kHZ. The impedance matcher drives the piezoelectric buzzer to sound.


Electromagnetic buzzer

The electromagnetic buzzer consists of an oscillator, an electromagnetic coil, a magnet, a vibrating diaphragm and a shell. After the power is turned on, the audio signal current generated by the oscillator passes through the electromagnetic coil, causing the electromagnetic coil to generate a magnetic field. Under the interaction of the electromagnetic coil and the magnet, the vibrating diaphragm vibrates periodically and makes a sound.


According to whether there is an oscillation source inside, it can be divided into active buzzers and passive buzzers. Active buzzers have an oscillation source inside, so they will make a sound as long as the power is turned on; while passive buzzers do not have an oscillation source inside, so if a DC signal is used, it cannot make it buzz. It must be driven by a square wave of a certain frequency.


First, design a frequency divider, design a 1KHz square wave, drive the buzzer, and observe whether the buzzer produces sound.

This section studies how to use a buzzer to sing a song "Only Mother is Good in the World".


The picture below is the simple score of "Only Mom is Good in the World".

ad6dceca-ee04-11ed-90ce-dac502259ad0.png

Figure 2: The simple musical notation of "Only Mom is good in the world"

Simplified musical notation is a relatively simple and easy-to-learn musical notation. It is said that it was invented by the French thinker Rousseau in 1742. The first person to introduce simplified musical notation into my country was Shen Xingong, a modern Chinese music educator. Simplified musical notation should be said to be a relatively simple and easy-to-learn musical notation. Its biggest advantage is that it can record and express a myriad of musical pieces with only 7 Arabic numerals - 1234567.


In the simplified musical notation, the basic symbols used to indicate the pitch of notes and their relationships are seven Arabic numerals, namely 1, 2, 3, 4, 5, 6, and 7, which are sung as do, re, mi, fa, sol, la, and si, which is called solfeggio.

Notes: 1234567

Roll call: do re mi fa sol la si

Chinese characters: Duo Lai Mi Fa Suo La Xi

Obviously, the above seven notes alone cannot express many musical images. In actual works, there are some higher or lower notes. For example, adding a "·" above the basic note means that the note is raised by one octave, which is called a treble; adding two ":" means that the note is raised by two octaves, which is called a double treble. Adding a "·" below the basic note means that the note is lowered by one octave, which is called a bass; adding two ":" means that the note is lowered by two octaves, which is called a double bass.


In general songs, it is rare to add two or more "·" notes above or below the basic note.


In the simplified musical notation, the seven basic notes 1, 2, 3, 4, 5, 6, and 7 not only indicate the pitch of the sound, but also are the basic units for indicating the length of time, called quarter notes. Other notes are represented by adding a short dash "-" and a dot "·" on the basis of the quarter note.


Adding a short horizontal line to the right of the basic note indicates that the duration of the note is increased by one quarter note. This type of short horizontal line added to the right of the note to increase the duration of the note is called an augmented time line. The more augmented time lines there are, the longer the duration of the note.


Adding a short horizontal line under the basic note indicates that the original note value is shortened by half. This type of short horizontal line added under the note to shorten the note value is called a time reduction line. The more time reduction lines there are, the shorter the note value.


In simplified musical notation, the small dot "·" added to the right side of a simple note to increase the note value is called a dot. The note with a dot is called a dotted note. The dot itself has no fixed length, and its length is determined by the previous simple note. The meaning of the dot is to increase the original note value by half, and it is often used after a quarter note and various notes shorter than a quarter note.


In the simple score of "Only Mom Is Good in the World", the duration between each two vertical lines is 2 seconds. There are 4 notes between each two vertical lines, but most of them are half a note long. This design uses 1/4 second as the basic unit.


The buzzer can produce seven basic notes, 1, 2, 3, 4, 5, 6, and 7, at different frequencies.

ad84e7fe-ee04-11ed-90ce-dac502259ad0.png

Figure 3: The frequencies corresponding to the notes

This module is named music_beep, clk is the 50MHz clock, rst_n is the low-level effective reset, and beep is the driving signal of the buzzer.

ada24948-ee04-11ed-90ce-dac502259ad0.png

Figure 4: music_beep model

When designing, first store the notes in the musical notation; use a counter to generate a pulse with a period of 1/4 second, and under the drive of this pulse, output the previously stored notes one by one; calculate the frequency division ratio according to the value of the note; and generate a waveform of the corresponding frequency according to the frequency division ratio. Then output this waveform.

adb3eec8-ee04-11ed-90ce-dac502259ad0.png

Figure 5: Architecture diagram

When designing multiple modules, you can only design the ports for each module, and then design each module separately after the architecture is completed.


There are 8 four-beats in the simple score of "Only Mom Is Good in the World", and we use 8 notes to represent each four-beat, totaling 64 notes. In speed_ctrl, the output cnt is 6 bits, which can represent 64 states.

In speed_ctrl, just increase cnt by 1 every 1/8 second.


The design code of the speed_ctrl module is as follows:

adc52648-ee04-11ed-90ce-dac502259ad0.png

The notes are stored in music_mem. The storage method is that the bass is represented by 1 to 7, the middle is represented by 8 to 14, and the treble is represented by 15 to 21. The music is 5 bits wide.

The design code of the music_mem module is as follows:

addb4c5c-ee04-11ed-90ce-dac502259ad0.png

According to the relationship between frequency and note, the frequency value corresponding to the note is taken out, and the frequency division ratio is calculated according to the frequency value. The driving clock is 50MHz, so the frequency division ratio is 50MHz divided by the frequency.

The design code of the cal_divmum module is as follows:

adf2218e-ee04-11ed-90ce-dac502259ad0.png

After knowing the frequency division number, you can use any frequency division method to generate the correct waveform.

The design code of the wave_gen module is as follows:

ae089b6c-ee04-11ed-90ce-dac502259ad0.png

After designing the above four modules, connect them using the connection method of the previously designed architecture.

The design code of the music_beep top-level module is as follows:

ae188dc4-ee04-11ed-90ce-dac502259ad0.png

The RTL view is as follows, which is the same as the designed architecture.

ae35feb8-ee04-11ed-90ce-dac502259ad0.png

Figure 11: RTL View

In testbench , change T_250ms in the speed_ctrl_inst module to 10.

defpa ram can redefine parameters.

The testbench code is as follows:

ae4c8f0c-ee04-11ed-90ce-dac502259ad0.png

Since the output frequencies are low, the simulation time is very long.

Reducing the parameter will only speed up the frequency of switching output notes. Since the wave_gen module and the frequency division module are the same, we will not verify them. Just check whether the frequency division number is correct in the RTL view.

ae63a3ea-ee04-11ed-90ce-dac502259ad0.png

Figure 13: RTL View

In the RTL view, we can also see that cnt increases by 1 every 10 cycles, and then the corresponding note is output. The note derives the frequency, and the frequency division number is obtained based on the frequency. After verification, the data is correct.

Assign pins, compile and generate Download file, and you can listen to the song "Only Mom Is Good in the World" after downloading the board.

By changing the speed of the control note in speed_crtl, you can control the playback speed. If the speed is controlled to 1/2 second, the song you hear will be slower. If the speed is controlled to 1/8 second, the song you hear will be faster.

[1] [2]
Keywords:FPGA Reference address:Analysis of the design case of music buzzer based on FPGA

Previous article:What conditions are needed to move from intelligence to super intelligence?
Next article:SGM3715 high-fidelity analog switch opens the door to wonderful audio

Recommended ReadingLatest update time:2024-11-16 11:46

Xilinx CTO: Adaptive computing will continue the spirit of Moore's Law
Author: Ivo Bolsens, CTO of Xilinx The evolution of chip architectures is accelerating, so having the right tools for the right job is critical. The world is getting smarter. From the smartphones in our pockets to today’s smart cities managing traffic and transportation systems, AI is pervasive in nearly every in
[Embedded]
Xilinx CTO: Adaptive computing will continue the spirit of Moore's Law
Intel releases new programmable acceleration card D5005, which has been adopted by HPE
Intel today announced the launch of the D5005 Programmable Acceleration Card based on the Stratix 10 SX FPGA, which has been used in the HPE ProLiant DL3809 Gen10 server. Intel announced the launch of the Programmable Acceleration Card in 2017 as a comprehensive platform for using FPGAs in the data center, with the f
[Embedded]
Intel releases new programmable acceleration card D5005, which has been adopted by HPE
Xilinx wins first place in MLPerf for Resnet-50 test
Recently, the MLPerf organization announced a series of test results. NVIDIA won all tests in all six application areas for data centers and edge computing systems in the second version of MLPerf Inference. Among them, Inspur AI server NF5488A5 supports 8 third-generation NVlink fully interconnected NVIDIA A100 GPUs,
[Embedded]
Xilinx wins first place in MLPerf for Resnet-50 test
Implementation of FPGA Embedded System Based on ARM
ARM (Advanced RISC Machines) can be considered a company, a general term for a type of microprocessor, or a technology. Microprocessor applications based on ARM technology account for more than 75% of the market share of 32-bit RISC microprocessors, and ARM technology is gradually penetrating into every aspect of peop
[Microcontroller]
Implementation of FPGA Embedded System Based on ARM
NI Integrates High-Performance Instruments and FPGAs for Optimal WLAN Measurements
  The NI PXIe-5644R is the industry's first vector signal transceiver (VST). The VST features up to 80 MHz of real-time bandwidth and up to 6 GHz center frequency. The instrument also includes a programmable FPGA that can be used to increase test speed or implement various real-time algorithms such as fast Fourier tran
[Test Measurement]
NI Integrates High-Performance Instruments and FPGAs for Optimal WLAN Measurements
Analysis of FPGA low power design
  In the early stage of project design, based on the design considerations of the hardware power module, it is essential to estimate the power consumption in FPGA design. I have experienced a project where the power consumption of the entire system reached 100W, while the power consumption of a single FPGA was estimat
[Power Management]
Analysis of FPGA low power design
Talk about simulation and testing of FPGA systems
I. Overview of FPGA simulation methods: (1) Interactive simulation method: Use the simulator of the EDA tool for simulation, which is easy to use, but the input and output are not easy to record and file, and it is not easy to observe and compare when the input amount is large. (2) Test platform method: The simulat
[Test Measurement]
STM32 MCU key debounce and FPGA key debounce
Written in front: STM32 MCU key debounce and FPGA key debounce Key debounce: From the above figure, we can see that there is a difference between the ideal waveform and the actual waveform. The actual waveform has jitter at the moment of pressing and releasing. The length of the jitter time is related to the mec
[Microcontroller]
STM32 MCU key debounce and FPGA key debounce
Latest Embedded Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号