Article Directory
1. Use STM32F103 to output a PWM waveform
1. Relevant resource preparation
Link: https://pan.baidu.com/s/13bnrB-S8Y6JDRdXBbzzbjA
Extraction code: pmf1
1): Follow the path in the figure below to find "1-Book supporting routines-F103VE guide" and download it
2): Unzip after downloading (32- TIM—Universal Timer- >2-TIM—Universal Timer-4 PWM Output)
2. Use keil to directly view the PWM waveform
1): Open the project
2): Related configuration changes
Magic wand->debug->Use Simulaor
3): Debug after compiling,
open the analysis window,
click setup,
enter GPIOA_IDR.6, select bit
4): Run to view the waveform (if you can’t see it) Scroll to view)
Two, STM32F103 DAC practice
1. Relevant resource preparation
Decompress "38-DAC—Sine Wave Output" in the supporting materials downloaded above, and download Au (I use Adobe_Audition_CS6), UltraEdit and WavToC converter on the Internet.
2. Convert and save audio files
1): Use music software to download your favorite music (preferably an mp3 file
) and convert it on Au.
Select the starting position. In the lower right corner, we set the duration to 2s, and the interval is automatically generated
2): Digital audio file generation.
Right-click the interval -> click the storage selection area to
change the sampling type.
Sampling 8khz, quantization 16bit, single channel
Save when you are done
3): Sine wave file generation
New audio file
sampling 8khz, quantization 16bit, single channel
Choose to generate the basic tone in the effect and
set it as shown in the figure
After zooming in, you can see the waveform as shown in the figure
Save
3. Use WavToC to convert audio files into c language code
1): Open WavToC, open the file,
select the file,
generate the code,
you can listen to it yourself, and then click to save the code, remember the number of output bytes here
The same is true for sine waves
4. Write the code and display the output with an oscilloscope
1). Convert digital audio song data to analog audio waveform output
Use Notepad to open the music audio code
Crtl+A and select all, copy and
open the previously unzipped "38-DAC—Sine Wave Output" project.
Change bsp—dac.c to
modify the code as shown in the figure:
Compile and generate hex file. After
burning, connect the board to the oscilloscope and you can see the output waveform
2). Output a sine wave with a period of 2khz
Copy the code
Modify the bsp-dac.c code as shown in the figure.
Compile and generate a hex file.
Here I forgot to use the oscilloscope to display the waveform, so there is no waveform.