semf
|
Using this class various waveforms on an output pin or LED can easily be generated. This is done by using two semf modules, namely the semf::SoftwareTimer and the semf::app::PwmOut module. The semf::SoftwareTimer module controls the sample and/or pulse’s timing while the semf::app::PwmOut class controls the amplitude of the signal. semf::app::PwmOut is a simple class which uses an implementation of the semf::Pwm interface encapsulating the HAL of the microcontroller.
This class can internally generate sinusoidal and triangular waveforms and approximate these according to a specified sampling frequency.
The waveform’s period duration and the waveform’s type can be configured using the setSine()
or setTriangle()
function.
If the purpose of the application is to flash an LED with the maximum amplitude the semf::app::LedBlinking class is better suited because less resources are required (SoftwareTimer module only). If the purpose of the application is to adjust the amplitude (or generally generate square-wave pulses), it is better to use the PwmOut class.
The first step to set up the semf::LedDimming object is to initialize a semf::app::Timer hardware module and configure one of its channels to a pwm generation mode (usually done in HW configuration, for example Stm32CubeMX). The second step is to create a HAL semf::Pwm object (e.g. Stm32f4Pwm object) referencing the timer handle and the preferred timer channel. This object is then passed to the PwmOut’s Object. Maximum and minimum values of the semf::Pwm object should be initialized via 'setMinValue()' and 'setMaxValue()' functions otherwise the default parameters are considered. This semf::app::PwmOut object and an additional semf::app::Timer object (see documentation concerning systick callback) are then passed to the semf::app::LedDimming object’s constructor.
In this example, we consider the hardware timer module TIM2 and its first channel TIM_CHANNEL_1, which has been set to pwm generation mode.