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 <bus/bus.h>
4#include <entity/entity.h>
5#include <interfaces/signal_generator.h>
6
7#include <chips/AD9834.h>
8#include <chips/DAC60508.h>
9#include <chips/SR74HCT595.h>
10
11namespace platform {
12namespace interfaces {
13
14
15// ██ ██ █████ ██
16// ██ ██ ██ ██ ██
17// ███████ ███████ ██
18// ██ ██ ██ ██ ██
19// ██ ██ ██ ██ ███████
20
21
22class FrontPlaneSignalGeneratorHAL_Common : public SignalGeneratorHAL
23{
24public:
26
27 virtual bool init();
28 virtual bool set_parameter(WaveForm form, uint8_t index, Parameter param, float value);
29 virtual float get_parameter(WaveForm form, Parameter param);
30
31 // note: it is not guaranteed that one can toggle each wave form independently;
32 // if that's not the case, enable is understood as a global flag
33 virtual bool toggle(bool enable, WaveForm form);
34 utils::status status() { return last_status; }
35
36protected:
37 // used to allow different pin mappings in each instance
46
47 virtual uint8_t get_pin(PINS pin_type) = 0;
48
49 // convenience members
50 virtual bool set_sine_param(Parameter param, float value) = 0;
51 bool set_square_param(Parameter param, float value);
52 bool set_const_param(Parameter param, uint8_t index, float value);
53
54 utils::status write_pin(PINS pin, float value, bool with_levelshift = true);
55 const char* pin_status_msg[6] = {
56 "FP DAC",
57 "FP DSLC",
58 "FP DSHC",
59 "FP DOC",
60 "FP DO0C",
61 "FP DO1C"
62 };
63
64 // implementation specific members
65 static constexpr uint8_t FUNCTION_GENERATOR_IDX = 2;
66 static constexpr uint8_t DAC_IDX = 3;
67
70 utils::status last_status = utils::status::success();
71
73 static constexpr float _map_dac_levelshift(float x) {
74 return (x + 2.0f) * (0.0f - 2.5f) / (2.0f + 2.0f) + 2.5f;
75 }
76};
77
79{
80public:
81 bool set_sine_param(Parameter param, float value) override
82 {
83 // determined by experimentation, assume users enter only values in [0.25, 0.75]
84 if(param == Parameter::AMPLITUDE)
85 return (last_status = write_pin(PINS::DAC_AMPLITUDE_CH, (0.75f - value) / 0.5f, false)).is_ok();
86
87 // determined by experimentation, assume users enter only values in [-0.5, 0.5]
88 if(param == Parameter::OFFSET)
89 return (last_status = write_pin(PINS::DAC_OFFSET_CH, (1.0f - 2.0f * value) * 1.25f, false)).is_ok();
90
91 if(param == Parameter::FREQUENCY)
92 {
93 function_generator.write_frequency(value);
94 return true;
95 }
96
97 if(param == Parameter::PHASE)
98 {
99 function_generator.write_phase(value);
100 return true;
101 }
102
103 return false;
104 }
105protected:
106 virtual uint8_t get_pin(PINS pin_type)
107 {
108 return _pins[pin_type];
109 }
110
111 const uint8_t _pins[6] = {
112 0, 1, 2, 3, 4, 5
113 };
114};
115
122{
123 public:
124 bool set_sine_param(Parameter param, float value) override
125 {
126 if(param == Parameter::AMPLITUDE)
127 return (last_status = write_pin(PINS::DAC_AMPLITUDE_CH, (1.0f - value) * 2.5f, false)).is_ok();
128
129 if(param == Parameter::OFFSET)
130 return (last_status = write_pin(PINS::DAC_OFFSET_CH, (1.0f - 2.0f * value) * 1.25f, false)).is_ok();
131
132 if(param == Parameter::FREQUENCY)
133 {
134 function_generator.write_frequency(value);
135 return true;
136 }
137
138 if(param == Parameter::PHASE)
139 {
140 function_generator.write_phase(value);
141 return true;
142 }
143
144 return false;
145 }
146 protected:
147 virtual uint8_t get_pin(PINS pin_type)
148 {
149 return _pins[pin_type];
150 }
151
152 const uint8_t _pins[6] = {
153 5, 2, 1, 0, 3, 4
154 };
155};
156
157// ██████ █████ ███████ ███████ ██████ ██ █████ ███████ ███████
158// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
159// ██████ ███████ ███████ █████ ██ ██ ███████ ███████ ███████
160// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
161// ██████ ██ ██ ███████ ███████ ██████ ███████ ██ ██ ███████ ███████
162
163class FrontPlaneSignalGenerator : public SignalGenerator {
164public:
165 FrontPlaneSignalGenerator(SignalGeneratorHAL * hardware);
167 bool init() override;
168
171 bool is_installed() const override { return installed; }
172
175 void set_frequency(float frequency) override;
178 void set_phase(float phase) override;
180 void set_wave_form(WaveForm wave_form) override;
183 bool set_amplitude(float amplitude) override;
186 bool set_square_voltage_levels(float low, float high) override;
189 bool set_square_voltage_low(float low) override;
192 bool set_square_voltage_high(float high) override;
195 bool set_offset(float offset) override;
196
198 float get_real_frequency() const override;
201 float get_real_phase() const override;
202
203 float get_frequency() const override;
204 float get_phase() const override;
205 WaveForm get_wave_form() const override;
206 float get_amplitude() const override;
207 float get_square_voltage_low() const override;
208 float get_square_voltage_high() const override;
209 float get_offset() const override;
210 bool get_sleep() const override;
211
212 float get_dac_out0() const override;
213 float get_dac_out1() const override;
214
217 void sleep() override;
220 void awake() override;
221
223 bool set_dac_out0(float value) override;
225 bool set_dac_out1(float value) override;
226
227 utils::status write_to_hardware() override;
228
229private:
230 float _frequency;
231 float _phase;
232 WaveForm _wave_form;
233 float _amplitude;
234 float _square_low_voltage;
235 float _square_high_voltage;
236 float _offset;
237 float _dac_out0 = 0.0;
238 float _dac_out1 = 0.0;
239
240 bool _sleep = true;
241
242 bool installed = false;
243};
244
245} // namespace interfaces
246} // namespace platform
The DAC60508 is the 12-Bit 8-channel DAC, used in the MInt-Block for the initial conditions and for c...
Definition DAC60508.h:17
virtual bool set_sine_param(Parameter param, float value)=0
virtual bool set_parameter(WaveForm form, uint8_t index, Parameter param, float value)
bool set_const_param(Parameter param, uint8_t index, float value)
utils::status write_pin(PINS pin, float value, bool with_levelshift=true)
static constexpr float _map_dac_levelshift(float x)
Remapping for the built in levelshift on some dac outputs.
virtual float get_parameter(WaveForm form, Parameter param)
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...
void set_wave_form(WaveForm wave_form) override
Sets the wave form of the function generator output.
void set_frequency(float frequency) override
Sets the frequency of the sine / triangle output in Hz.
bool set_square_voltage_high(float high) override
Sets the upper value of the square output in machine units.
bool set_dac_out0(float value) override
Writes the DACout0 constant voltage output. Possible values are: [-2V, 2V].
bool set_square_voltage_low(float low) override
Sets the lower value of the square output in machine units.
bool set_offset(float offset) override
Sets the constant offset of the sine or triangle output in machine units.
bool init() override
Initializes the signal generator and puts it to sleep.
bool set_dac_out1(float value) override
Writes the DACout1 constant voltage output. Possible values are: [-2V, 2V].
bool set_amplitude(float amplitude) override
Sets the amplitude of the sine or triangle wave in machine units.
bool is_installed() const override
Returns wether an signal generator module is actually installed and active.
float get_real_frequency() const override
Returns the actually set frequency of the function generator, containing rounding errors.
void set_phase(float phase) override
Sets the phase of the frequency outputs synchronised to the reset pin.
FrontPlaneSignalGenerator(SignalGeneratorHAL *hardware)
FrontPlaneSignalGenerator.
float get_real_phase() const override
Returns the actually set phase of the function generator, containing rounding errors.
void sleep() override
Sets the sine / triangle output of the function generator to zero.
bool set_sine_param(Parameter param, float value) override
With version 1.2.X, the pin arrangement betweenthe DAC and all connected chips has changed,...
bool set_sine_param(Parameter param, float value) override
void index(awot::Request &req, awot::Response &res)
Definition server.cpp:120