Based on the 32-bit STM32F103, the audio signal generated by the PWM is used to drive the buzzer to play the music, which realizes the application design of the music player. The player can achieve 21 scales from bass to treble and can play complete tracks based on the score. The test results show that the output frequency of the PWM is basically the same as the sound frequency corresponding to each scale, and the scheme is feasible. This method can also be used in motor control, keyboard design, etc., and has good practicability. 1.1 Scales Scales are an essential element of music and are primarily determined by the frequency of the sound. By giving the buzzer audio pulses of different frequencies, different scales can be generated. To generate an audio pulse of a certain frequency, the easiest way is to calculate the period of the audio, and then divide the period by 2 to be the half-cycle time. . The program controls the one-chip half-cycle of the single-chip to be "high" and the half-cycle is "low", and continuously alternates to generate a rectangular wave of the frequency. When the buzzer is connected, the sound of the frequency can be emitted. If you want to change the scale, you only need to change the half cycle time. Table 1 is a C-tone note frequency comparison table, according to which notes of different scales can be generated. “#†indicates a semitone, which is used to raise or lower a halftone, multiplying by 2 to raise the sound by an 8 degree scale, and halving by an 8 degree. 1.2 beats To form a music, it is not enough to have a scale, but also a beat, that is, the length of the note duration, which is generally expressed in beats. As for how many seconds is 1 shot, there is no strict regulation, as long as the beat is appropriate, the sound is sweet. If the rhythm of a song is 120 beats per minute, then 1 beat is 0.5 s, 1/4 beat is 0.125 s, and so on to get the duration of other beats. Thus, the use of different frequencies, plus the delay corresponding to the number of beats, constitutes a piece of music. The generation of the scale is related to the frequency of the sound. In order to achieve different scales, it is necessary to provide pulses of different frequencies for the buzzer. To this end, the STM32 chip is selected, and its own timer is used to generate a pulse signal through PWM. There are 11 timers in STM32, including 2 advanced control timers, 4 normal timers, 2 basic timers, and 2 watchdog timers and 1 system tick timer SysTIek. Among them, TIM1 and TIM8 are advanced timers, and the clock is generated by the output of APB2. TIM2 to TIM5 are normal timers, and TIM6 and TIM7 are basic timers. The clocks of these six timers are generated by the output of APB1. 2.1 Calculation of timing duration One of the main functions of the timer is to generate an overflow event at the specified time. The setting of this time is related to the timer clock. The prescaler is set based on the timer clock, and the count overflow size can be set. 2.1.1 System Clock Settings To ensure timing accuracy, you must first ensure that the system clock settings are what we expected. The timer clock distribution is shown in Figure 1. By programming, SYSCLK is 72 MHz, APB1 is pre-divided and PCLK1 is 36 MHz, and TIM2~TIM7 clock is obtained by TIM2~TIM7 multiplier. The clock source uses HSE (external clock source). For STM32F103, the external clock is 8 MHz, and the STM32F107 external clock is 25 MHz. Therefore, when using HSE as the clock source, these two devices generate SYSCLK frequency division and multiple times. The frequency is different and requires the user to pay attention. 2.1.2 Timer related parameter settings The parameters of the timer are defined by the structure TimeBaselnitTypeDef, which mainly includes the prescaler coefficient, clock division, counter mode, and count overflow size. For example, to generate a timing of 1 s by TIM3 (Timer 3), first, set the system clock, get TIM3CLK = 72MHz, and then set the timer. Among them, the prescaler coefficient is 35 999. At this time, the TIM3 clock is 72 MHz/36 000=2 kHz, and there is no clock division. Set the count overflow size to 1 999, which is an update event for every 2 000 counts. The output frequency is 2 kHz/2 000=1 Hz. code show as below: 2.2 STM32 PWM output Pulse Width Modulation (PWM) is a very effective technique for controlling the analog circuit by using the digital output of the microprocessor. In short, it is to control the pulse width of the output signal. Control stepper motors, etc. In addition to TIM6 and TIM7, other timers of STM32 can be used to generate PWM output. Among them, advanced timers TIM1 and TIM8 can generate 3 pairs of PWM complementary outputs, while TIM2~TIM5 can also generate 4 channels simultaneously. PWM output. 2.2.1 PWM Output Pin STM32 assigns different output pins to different timers. Considering the pin multiplexing function, STM32 also proposes a "re-image" concept, which is to set some related registers so that other non-original specified The PWM waveform can also be output on the pin, but this re-imaging is not arbitrary, and the method of reference can be referred to the reference. For example, channel 2 of TIM3, when there is no re-imaging, the designated pin is PA7. If the partial re-imaging is set, the output is mapped to PB5; if the full re-imaging is set, the output is mapped to PC7. 2.2.2 Calculation of duty cycle Duty Ratio has the following meaning: the ratio of the duration of a positive pulse to the total period of a pulse in a sequence of ideal pulse periods (such as a square wave).
ZGAR MINI
ZGAR electronic cigarette uses high-tech R&D, food grade disposable pod device and high-quality raw material. All package designs are Original IP. Our designer team is from Hong Kong. We have very high requirements for product quality, flavors taste and packaging design. The E-liquid is imported, materials are food grade, and assembly plant is medical-grade dust-free workshops.
From production to packaging, the whole system of tracking, efficient and orderly process, achieving daily efficient output. We pay attention to the details of each process control. The first class dust-free production workshop has passed the GMP food and drug production standard certification, ensuring quality and safety. We choose the products with a traceability system, which can not only effectively track and trace all kinds of data, but also ensure good product quality.
We offer best price, high quality Vape Device, E-Cigarette Vape Pen, Disposable Device Vape,Vape Pen Atomizer, Electronic cigarette to all over the world.
Much Better Vaping Experience!
E-Cigarette Vape Pen,Disposable Device Vape,Vape Pen Atomizer,Latest Disposable E-Cigarette OEM vape pen,OEM electronic cigarette,ZGAR Mini ZGAR INTERNATIONAL(HK)CO., LIMITED , https://www.zgarvapor.com
In the development of scientific research projects, sometimes you need to play ringtones, music, etc. The simple approach is to buy a dedicated music chip, but the disadvantage of this method is that the content being played is immutable and does not meet the project requirements. Generally, the music can be played by a single chip such as 89C51, and the content of the play and the number of songs can be modified at any time, which is relatively convenient to use. With the advent of the STM32 family of microprocessors, its ARM Cortex-M core-based 32-bit flash microcontrollers, up to 72 MHz, high integration, real-time, digital signal processing, low power, low voltage operation Many other features make it more and more widely used. Based on the STM32 processor, this paper creates a score for program recognition based on the music score, and uses the internal timer to generate a PWM output signal to drive the buzzer to complete the playback of the custom score. After testing, the playback effect is good.
1 Music score analysis
When TIM_Period is 1 999, if you want to get a duty cycle of 50%, TIM_Pulse should be set to (1999+1)/2=1000. The specific settings are as follows: