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 UnitResult init();
28 virtual UnitResult 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
35protected:
36 // used to allow different pin mappings in each instance
45
46 virtual uint8_t get_pin(PINS pin_type) = 0;
47
48 // convenience members
49 virtual UnitResult set_sine_param(Parameter param, float value) = 0;
50 UnitResult set_square_param(Parameter param, float value);
51 UnitResult set_const_param(Parameter param, uint8_t index, float value);
52
53 UnitResult write_pin(PINS pin, float value, bool with_levelshift = true);
54 const char* pin_status_msg[6] = {
55 "FP DAC",
56 "FP DSLC",
57 "FP DSHC",
58 "FP DOC",
59 "FP DO0C",
60 "FP DO1C"
61 };
62
63 // implementation specific members
64 static constexpr uint8_t FUNCTION_GENERATOR_IDX = 2;
65 static constexpr uint8_t DAC_IDX = 3;
66
69 UnitResult last_status = UnitResult::ok();
70
72 static constexpr float _map_dac_levelshift(float x) {
73 return (x + 2.0f) * (0.0f - 2.5f) / (2.0f + 2.0f) + 2.5f;
74 }
75};
76
78{
79public:
80 UnitResult set_sine_param(Parameter param, float value) override
81 {
82 // determined by experimentation, assume users enter only values in [0.25, 0.75]
83 if(param == Parameter::AMPLITUDE)
84 return write_pin(PINS::DAC_AMPLITUDE_CH, (0.75f - value) / 0.5f, false);
85
86 // determined by experimentation, assume users enter only values in [-0.5, 0.5]
87 if(param == Parameter::OFFSET)
88 return write_pin(PINS::DAC_OFFSET_CH, (1.0f - 2.0f * value) * 1.25f, false);
89
90 if(param == Parameter::FREQUENCY)
91 {
92 function_generator.write_frequency(value);
93 return UnitResult::ok();
94 }
95
96 if(param == Parameter::PHASE)
97 {
98 function_generator.write_phase(value);
99 return UnitResult::ok();
100 }
101
102 return UnitResult::err("Error front-panel unknown param");
103 }
104protected:
105 virtual uint8_t get_pin(PINS pin_type)
106 {
107 return _pins[pin_type];
108 }
109
110 const uint8_t _pins[6] = {
111 0, 1, 2, 3, 4, 5
112 };
113};
114
121{
122 public:
123 UnitResult set_sine_param(Parameter param, float value) override
124 {
125 if(param == Parameter::AMPLITUDE)
126 return write_pin(PINS::DAC_AMPLITUDE_CH, (1.0f - value) * 2.5f, false);
127
128 if(param == Parameter::OFFSET)
129 return write_pin(PINS::DAC_OFFSET_CH, (1.0f - 2.0f * value) * 1.25f, false);
130
131 if(param == Parameter::FREQUENCY)
132 {
133 function_generator.write_frequency(value);
134 return UnitResult::ok();
135 }
136
137 if(param == Parameter::PHASE)
138 {
139 function_generator.write_phase(value);
140 return UnitResult::ok();
141 }
142
143 return UnitResult::err("Error front-panel unknown param");
144 }
145 protected:
146 virtual uint8_t get_pin(PINS pin_type)
147 {
148 return _pins[pin_type];
149 }
150
151 const uint8_t _pins[6] = {
152 5, 2, 1, 0, 3, 4
153 };
154};
155
156// ██████ █████ ███████ ███████ ██████ ██ █████ ███████ ███████
157// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
158// ██████ ███████ ███████ █████ ██ ██ ███████ ███████ ███████
159// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
160// ██████ ██ ██ ███████ ███████ ██████ ███████ ██ ██ ███████ ███████
161
162class FrontPlaneSignalGenerator : public SignalGenerator {
163public:
164 FrontPlaneSignalGenerator(SignalGeneratorHAL * hardware);
166 UnitResult init() override;
167
170 bool is_installed() const override { return installed; }
171
174 void set_frequency(float frequency) override;
177 void set_phase(float phase) override;
179 void set_wave_form(WaveForm wave_form) override;
182 bool set_amplitude(float amplitude) override;
185 bool set_square_voltage_levels(float low, float high) override;
188 bool set_square_voltage_low(float low) override;
191 bool set_square_voltage_high(float high) override;
194 bool set_offset(float offset) override;
195
197 float get_real_frequency() const override;
200 float get_real_phase() const override;
201
202 float get_frequency() const override;
203 float get_phase() const override;
204 WaveForm get_wave_form() const override;
205 float get_amplitude() const override;
206 float get_square_voltage_low() const override;
207 float get_square_voltage_high() const override;
208 float get_offset() const override;
209 bool get_sleep() const override;
210
211 float get_dac_out0() const override;
212 float get_dac_out1() const override;
213
216 void sleep() override;
219 void awake() override;
220
222 bool set_dac_out0(float value) override;
224 bool set_dac_out1(float value) override;
225
226 UnitResult write_to_hardware() override;
227
228private:
229 float _frequency;
230 float _phase;
231 WaveForm _wave_form;
232 float _amplitude;
233 float _square_low_voltage;
234 float _square_high_voltage;
235 float _offset;
236 float _dac_out0 = 0.0;
237 float _dac_out1 = 0.0;
238
239 bool _sleep = true;
240
241 bool installed = false;
242};
243
244} // namespace interfaces
245} // 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
UnitResult set_const_param(Parameter param, uint8_t index, float value)
UnitResult set_square_param(Parameter param, float value)
UnitResult 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 UnitResult set_parameter(WaveForm form, uint8_t index, Parameter param, float value)
virtual UnitResult set_sine_param(Parameter param, float value)=0
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 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.
UnitResult init() override
Initializes the signal generator and puts it to sleep.
UnitResult set_sine_param(Parameter param, float value) override
With version 1.2.X, the pin arrangement betweenthe DAC and all connected chips has changed,...
UnitResult set_sine_param(Parameter param, float value) override
void index(awot::Request &req, awot::Response &res)
Definition server.cpp:120