General
The semf::AnalogOut hardware abstraction in semf creates an analog signal from an integer value respectively an integer array. There are two approaches:
In the following example we use the hardware abstraction of the Stm32F7 core.
Initialization of AnalogOut
Using Stm32CubeMX
you can enable the timer with the following steps:
- Open Analog configuration and enable OUTx.
- Enable Output Buffer in Parameter Settings.
- Set Trigger to Software trigger in Parameter Settings.
- Wave generation mode is disabled.
Usage of AnalogOut
To use the semf::AnalogOut call the setValue()
and start()
methods. You can stop the semf::AnalogOut by calling the stop()
function and update the value by calling setValue()
whenever you need.
#include "semf/hardwareabstraction/stm32f7/stm32f7analogout.h"
extern DAC_HandleTypeDef hadc;
namespace msp
{
class Msp
{
public:
Msp()
:m_analogOut(hdac, 1,
semf::Stm32F7AnalogOut::Alignment::Align8BitRight)
{
}
void init()
{
m_analogOut.setValue(0x10);
m_analogOut.start();
}
{
return m_analogOut;
}
private:
semf::Stm32F7AnalogOut m_analogOut;
};
}
Interface for using DAC (Digital to Analog Converter) hardware module in interrupt mode.
Initialitation of AnalogOutDma
Using Stm32CubeMX
you can enable the timer with the following steps:
- Open Analog configuration and enable OUTx.
- Enable Output Buffer in Parameter Settings.
- Set Trigger to Software trigger in Parameter Settings.
- Wave generation mode is disabled.
- Enable the interrupt in the NVIC Settings.
- Add a DMA channel with Half Word Data Width.
- For outputting the same data cyclic enable the Circular Mode.
Usage of AnalogOutDma
To use the semf::AnalogOutDma call the setValues()
and start()
methods. You can stop the semf::AnalogOutDma by calling the stop()
function and update the value by calling setValues()
whenever you need.
#include "semf/hardwareabstraction/stm32f7/stm32f7analogoutdma.h"
extern DAC_HandleTypeDef hdac;
namespace msp
class Msp
{
public:
Msp()
:m_analogOutDma(hdac, 1,
semf::Stm32F7AnalogOut::Alignment::Alighn8BitRight)
{
}
void init()
{
static uint16_t data[16];
for (size_t i=0; i < 16; i++)
data[i] = 20 * i;
m_analogOutDma.dataWritten.connect(m_onAnalogOutDataWrittenSlot);
m_analogOutDma.setData(data, 16);
m_analogOutDma.start();
}
{
return m_analogOutDma;
}
private:
void onAnalogOutDataWritten()
{
}
SEMF_SLOT(m_onAnalogOutDataWrittenSlot, Msp, *
this, onAnalogOutDataWritten);
semf::Stm32F7AnalogOutDma m_analogOutDma;
};
}
Interface for using DAC (Digital to Analog Converter) hardware module in DMA (Direct Memory Access) m...
#define SEMF_SLOT(name, className, object, function,...)
Creates a semf slot.