semf
Dac

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:

  1. Open Analog configuration and enable OUTx.
  2. Enable Output Buffer in Parameter Settings.
  3. Set Trigger to Software trigger in Parameter Settings.
  4. 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();
}
semf::AnalogOut& analogOut()
{
return m_analogOut;
}
private:
semf::Stm32F7AnalogOut m_analogOut;
};
} // namespace msp
Interface for using DAC (Digital to Analog Converter) hardware module in interrupt mode.
Definition: analogout.h:23

Initialitation of AnalogOutDma

Using Stm32CubeMX you can enable the timer with the following steps:

  1. Open Analog configuration and enable OUTx.
  2. Enable Output Buffer in Parameter Settings.
  3. Set Trigger to Software trigger in Parameter Settings.
  4. Wave generation mode is disabled.
  5. Enable the interrupt in the NVIC Settings.
  6. Add a DMA channel with Half Word Data Width.
  7. 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;
// Connect dataWritten signal with onAnalogOutDataWritten() slot for getting into
// the slot after all data is written
m_analogOutDma.dataWritten.connect(m_onAnalogOutDataWrittenSlot);
m_analogOutDma.setData(data, 16);
m_analogOutDma.start();
}
semf::AnalogOutDma& analogOut()
{
return m_analogOutDma;
}
private:
void onAnalogOutDataWritten()
{
// do something
}
SEMF_SLOT(m_onAnalogOutDataWrittenSlot, Msp, *this, onAnalogOutDataWritten);
semf::Stm32F7AnalogOutDma m_analogOutDma;
};
} // namespace msp
Interface for using DAC (Digital to Analog Converter) hardware module in DMA (Direct Memory Access) m...
Definition: analogoutdma.h:25
#define SEMF_SLOT(name, className, object, function,...)
Creates a semf slot.
Definition: slot.h:30