REDAC HybridController
Firmware for LUCIDAC/REDAC Teensy
Loading...
Searching...
No Matches
signal_generator.h
Go to the documentation of this file.
1#pragma once
2
3#include "interfaces/signal_generator.h"
4
5#include <bus/bus.h>
6#include <entity/entity.h>
7
8namespace platform {
9class NativeSignalGenerator : public interfaces::SignalGenerator {
10public:
13 bool init() override;
14
17 bool is_installed() const override { return installed; }
18
21 void set_frequency(float frequency) override;
24 void set_phase(float phase) override;
26 void set_wave_form(WaveForm wave_form) override;
29 bool set_amplitude(float amplitude) override;
32 bool set_square_voltage_levels(float low, float high) override;
35 bool set_square_voltage_low(float low) override;
38 bool set_square_voltage_high(float high) override;
41 bool set_offset(float offset) override;
42
44 float get_real_frequency() const override;
47 float get_real_phase() const override;
48
49 float get_frequency() const override;
50 float get_phase() const override;
51 WaveForm get_wave_form() const override;
52 float get_amplitude() const override;
53 float get_square_voltage_low() const override;
54 float get_square_voltage_high() const override;
55 float get_offset() const override;
56 bool get_sleep() const override;
57
58 float get_dac_out0() const override;
59 float get_dac_out1() const override;
60
63 void sleep() override;
66 void awake() override;
67
69 bool set_dac_out0(float value) override;
71 bool set_dac_out1(float value) override;
72
73 utils::status write_to_hardware() override;
74
75private:
77 static constexpr float _map_dac_levelshift(float x) {
78 return (x + 2.0f) * (0.0f - 2.5f) / (2.0f + 2.0f) + 2.5f;
79 }
80
81 float _frequency;
82 float _phase;
83 WaveForm _wave_form;
84 float _amplitude;
85 float _square_low_voltage;
86 float _square_high_voltage;
87 float _offset;
88 float _dac_out0;
89 float _dac_out1;
90
91 bool _sleep = true;
92
93 bool installed = false;
94
95 static constexpr uint8_t FUNCTION_GENERATOR_IDX = 2;
96 static constexpr uint8_t DAC_IDX = 3;
97
98 static constexpr uint8_t DAC_AMPLITUDE_CH = 0;
99 static constexpr uint8_t DAC_SQUARE_HIGH_CH = 1;
100 static constexpr uint8_t DAC_SQUARE_LOW_CH = 2;
101 static constexpr uint8_t DAC_OFFSET_CH = 3;
102 static constexpr uint8_t DAC_OUT0_CH = 4;
103 static constexpr uint8_t DAC_OUT1_CH = 5;
104};
105
106} // namespace platform
bool set_square_voltage_low(float low) override
Sets the lower value of the square output in machine units.
void set_phase(float phase) override
Sets the phase of the frequency outputs synchronised to the reset pin.
float get_dac_out1() const override
bool set_dac_out1(float value) override
Writes the DACout1 constant voltage output. Possible values are: [-2V, 2V].
void set_wave_form(WaveForm wave_form) override
Sets the wave form of the function generator output.
bool is_installed() const override
Returns wether an signal generator module is actually installed and active.
float get_frequency() const override
WaveForm get_wave_form() const override
float get_square_voltage_low() const override
bool init() override
Initializes the signal generator and puts it to sleep.
float get_real_phase() const override
Returns the actually set phase of the function generator, containing rounding errors.
bool set_square_voltage_high(float high) override
Sets the upper value of the square output in machine units.
float get_amplitude() const override
float get_offset() const override
void sleep() override
Sets the sine / triangle output of the function generator to zero.
bool set_offset(float offset) override
Sets the constant offset of the sine or triangle output in machine units.
utils::status write_to_hardware() override
float get_square_voltage_high() const override
bool set_square_voltage_levels(float low, float high) override
Sets the lower and upper value of the square output in machine units.
void awake() override
Resumes outputs of the function generator to regular operation, according to the previously specified...
float get_dac_out0() const override
bool set_amplitude(float amplitude) override
Sets the amplitude of the sine or triangle wave in machine units.
float get_real_frequency() const override
Returns the actually set frequency of the function generator, containing rounding errors.
bool set_dac_out0(float value) override
Writes the DACout0 constant voltage output. Possible values are: [-2V, 2V].
void set_frequency(float frequency) override
Sets the frequency of the sine / triangle output in Hz.