PWM tone generation (2014)
Since basic and lower series of STM32 processor do not have regular sound output, it is necessary to generate the sound signal “by self”. The easiest way to get a sound is to use internal timers of the processor.
The sound can be created using rectangular wave pulses (mostly with 50% duty cycle). The length of the pulse corresponds with the frequency of the output tone. The most laud noise is generated with 50% duty cycle. The duty cycle thus controls the volume of the output tone.
You must configure timing of the internal timer in order to generate proper rectangular wave. This needs to be done for each particular tone. Unlike the duty cycle which can be set for each channel separately, the timing settings affect the entire timer. The remaining channel cannot be thus reasonably used for other purposes.
This library provides all necessary settings. Moreover, it enables you to play predefined melody. You can choose particular tones, their durations and volume. In order to simplify the process of defining the melody, it is possible to import the melody from a string. The supported format for the string corresponds with notation used in older Nokia phones.
The usage of this library for generating sound is available on the following page AMP for PWM tone generation (2014) .
Source codesClick the label to show the source code
Back to Robotics STM32.