PS_Fgen_FW  4da88f4073c1cc65ea45c3a652a2751e495e50db
Firmware for an Power Supply and Function Generator build from an ATX power supply
Loading...
Searching...
No Matches
PS_Channel.h
Go to the documentation of this file.
1
7
8#ifndef POWERSUPPLY_H_
9#define POWERSUPPLY_H_
10
11#include "DAC_MCP492x.h"
12#include "../Configuration.h"
13#include "Channel.h"
14
25extern const char* PsRegulationModesNames[];
26
27
28#ifdef PS_SUBSYSTEM_ENABLED
29
43extern const char* PsStatesNames[];
44
60class PS_Channel : public Channel
61{
62 private:
66
67 public:
70
73
77
81
85
86 volatile float MeasuredVoltage;
87 volatile float MeasuredCurrent;
88 volatile float MeasuredPower;
89
90 volatile uint16_t TimeCounter_OvpDelay_ms;
91 volatile uint16_t TimeCounter_OcpDelay_ms;
92 volatile uint16_t TimeCounter_OppDelay_ms;
93
111 PS_Channel(float minVolt, float maxVolt, uint8_t minOvpLevel, uint8_t maxOvpLevel, float minOvpDelay, float maxOvpDelay, float minOcpLevel, float maxOcpLevel, float minOcpDelay, float maxOcpDelay, float minOppLevel, float maxOppLevel, float minOppDelay, float maxOppDelay);
112
114 void SwitchOffOutput();
115
117 void UpdateOutput();
118
123 void DoRegulationISR();
124
128 inline void CheckProtections();
129
133 void ClearProtections();
134
140
145 inline PsStates_t GetPsState() { return PsState; }
146
152 bool SetRegulationMode(PsRegulationModes_t regulationMode);
158
164 bool SetEnabled(bool enabled);
169 inline bool GetEnabled() { return Enabled.Val; }
170
176 bool SetVoltage(float voltage);
181 inline float GetVoltage() { return Voltage.Val; }
182
188 bool SetOvpLevel(uint8_t ovpLevel);
193 inline uint8_t GetOvpLevel() { return OvpLevel.Val; }
194
200 bool SetOvpState(bool ovpState);
205 inline bool GetOvpState() { return OvpState.Val; }
206
212 bool SetOvpDelay(float ovpDelay);
217 inline float GetOvpDelay() { return OvpDelay.Val; }
218
224 bool SetOcpLevel(float ocpLevel);
229 inline float GetOcpLevel() { return OcpLevel.Val; }
230
236 bool SetOcpState(bool ocpState);
241 inline bool GetOcpState() { return OcpState.Val; }
242
248 bool SetOcpDelay(float ocpDelay);
253 inline float GetOcpDelay() { return OcpDelay.Val; }
254
260 bool SetOppLevel(float oppLevel);
265 inline float GetOppLevel() { return OppLevel.Val; }
266
272 bool SetOppState(bool oppState);
277 inline bool GetOppState() { return OppState.Val; }
278
284 bool SetOppDelay(float oppDelay);
289 inline float GetOppDelay() { return OppDelay.Val; }
290
291
296 static void PSRegulationModeChanged(void* channel);
297
302 static void PSEnabledChanged(void* channel);
303
308 static void PSVoltageChanged(void* channel);
309
314 static void PSOvpLevelChanged(void* channel);
319 static void PSOvpStateChanged(void* channel);
324 static void PSOvpDelayChanged(void* channel);
325
330 static void PSOcpLevelChanged(void* channel);
335 static void PSOcpStateChanged(void* channel);
340 static void PSOcpDelayChanged(void* channel);
341
346 static void PSOppLevelChanged(void* channel);
351 static void PSOppStateChanged(void* channel);
356 static void PSOppDelayChanged(void* channel);
357};
358
359#endif /* POWERSUPPLY_H_ */
360
361#endif /* PS_SUBSYSTEM_ENABLED */
Containing the base class for all channels.
Containing different defines for device configuration.
Containing the functions to control the MCP492x DACs.
enum PsStates PsStates_t
Available power supply states.
PsRegulationModes
Available power supply regulation modes.
Definition PS_Channel.h:20
@ PS_REG_MODE_FIX
Power supply channel is not regulated (neither constant voltage nor constant current).
Definition PS_Channel.h:21
@ NUM_PS_REG_MODE_ELEMENTS
The last element is used to determine the number of elements in the enumeration.
Definition PS_Channel.h:23
@ PS_REG_MODE_CV
Power supply channel is only constant voltage regulated (not constant current).
Definition PS_Channel.h:22
enum PsRegulationModes PsRegulationModes_t
Available power supply regulation modes.
PsStates
Available power supply states.
Definition PS_Channel.h:35
@ PS_STATE_OCP
Power supply state over current protection.
Definition PS_Channel.h:39
@ NUM_PS_STATE_ELEMENTS
The last element is used to determine the number of elements in the enumeration.
Definition PS_Channel.h:41
@ PS_STATE_OVP
Power supply state over voltage protection.
Definition PS_Channel.h:38
@ PS_STATE_OPP
Power supply state over power protection.
Definition PS_Channel.h:40
@ PS_STATE_OVL
Power supply state overload.
Definition PS_Channel.h:37
@ PS_STATE_CV
Power supply state constant voltage.
Definition PS_Channel.h:36
Channel(ChannelTypes_t channelType)
Constructor of the Channel class.
Definition Channel.h:48
bool SetRegulationMode(PsRegulationModes_t regulationMode)
Set the RegulationMode property of the PS channel.
Definition PS_Channel.cpp:194
static void PSOppLevelChanged(void *channel)
Callback function that can be used for user interface controls modifying the OppLevel property.
Definition PS_Channel.cpp:426
Parameter< float > OppDelay
Time after which the over power protection kicks in.
Definition PS_Channel.h:84
static void PSOvpStateChanged(void *channel)
Callback function that can be used for user interface controls modifying the OvpState property.
Definition PS_Channel.cpp:391
static void PSRegulationModeChanged(void *channel)
Callback function that can be used for user interface controls modifying the RegulationMode property.
Definition PS_Channel.cpp:358
bool SetOvpLevel(uint8_t ovpLevel)
Set the OvpLevel property of the PS channel.
Definition PS_Channel.cpp:232
void ClearProtections()
Clear the protections for the power supply channel and return to the CV state.
Definition PS_Channel.cpp:167
float _setVoltage
Voltage to which the output should be set.
Definition PS_Channel.h:65
static void PSOcpLevelChanged(void *channel)
Callback function that can be used for user interface controls modifying the OcpLevel property.
Definition PS_Channel.cpp:405
Parameter< bool > Enabled
Is the channel enabled or not.
Definition PS_Channel.h:71
Parameter< float > Voltage
Voltage of the power supply channel.
Definition PS_Channel.h:72
volatile uint16_t TimeCounter_OvpDelay_ms
Time counter used to measure how long the channel has an over voltage.
Definition PS_Channel.h:90
volatile PsStates_t PsState
Current state of the power supply channel.
Definition PS_Channel.h:68
bool GetOppState()
Get the OppState property of the PS channel.
Definition PS_Channel.h:277
static void PSOcpDelayChanged(void *channel)
Callback function that can be used for user interface controls modifying the OcpDelay property.
Definition PS_Channel.cpp:419
bool SetOppState(bool oppState)
Set the OppState property of the PS channel.
Definition PS_Channel.cpp:330
Parameter< uint8_t > OvpLevel
OVP trip level in percentage of the Voltage.
Definition PS_Channel.h:75
Parameter< bool > OvpState
Is the over voltage protection for the channel enabled or not.
Definition PS_Channel.h:74
static void PSVoltageChanged(void *channel)
Callback function that can be used for user interface controls modifying the Voltage property.
Definition PS_Channel.cpp:376
bool SetOcpState(bool ocpState)
Set the OcpState property of the PS channel.
Definition PS_Channel.cpp:288
Parameter< float > OcpLevel
OCP trip level in Ampere.
Definition PS_Channel.h:79
bool GetEnabled()
Get the Enabled property of the PS channel.
Definition PS_Channel.h:169
float GetOcpDelay()
Get the OcpDelay property of the PS channel.
Definition PS_Channel.h:253
bool SetOcpLevel(float ocpLevel)
Set the OcpLevel property of the PS channel.
Definition PS_Channel.cpp:274
Parameter< float > OcpDelay
Time after which the over current protection kicks in.
Definition PS_Channel.h:80
static void PSEnabledChanged(void *channel)
Callback function that can be used for user interface controls modifying the Enabled property.
Definition PS_Channel.cpp:366
Parameter< float > OppLevel
OPP trip level in Watt.
Definition PS_Channel.h:83
float GetVoltage()
Get the Voltage property of the PS channel.
Definition PS_Channel.h:181
volatile PsRegulationModes_t RegulationMode
Current regulation mode of the power supply channel.
Definition PS_Channel.h:69
bool IsProtectionActive()
Check if at least one protection is active (OVP, OCP, OPP)
Definition PS_Channel.h:139
PsRegulationModes_t GetRegulationMode()
Get the RegulationMode property of the PS channel.
Definition PS_Channel.h:157
bool SetVoltage(float voltage)
Set the Voltage property of the PS channel.
Definition PS_Channel.cpp:218
void DoRegulationISR()
This method is called periodically based on the device timer ISR (multiples of the device timer perio...
Definition PS_Channel.cpp:61
bool SetOcpDelay(float ocpDelay)
Set the OcpDelay property of the PS channel.
Definition PS_Channel.cpp:302
static void PSOppDelayChanged(void *channel)
Callback function that can be used for user interface controls modifying the OppDelay property.
Definition PS_Channel.cpp:440
PsStates_t GetPsState()
Return the current state of this channel.
Definition PS_Channel.h:145
PS_Channel(float minVolt, float maxVolt, uint8_t minOvpLevel, uint8_t maxOvpLevel, float minOvpDelay, float maxOvpDelay, float minOcpLevel, float maxOcpLevel, float minOcpDelay, float maxOcpDelay, float minOppLevel, float maxOppLevel, float minOppDelay, float maxOppDelay)
Constructor of the PS_Channel.
Definition PS_Channel.cpp:17
volatile float MeasuredVoltage
Measured Voltage for this channel.
Definition PS_Channel.h:86
static void PSOcpStateChanged(void *channel)
Callback function that can be used for user interface controls modifying the OcpState property.
Definition PS_Channel.cpp:412
bool GetOcpState()
Get the OcpState property of the PS channel.
Definition PS_Channel.h:241
bool SetEnabled(bool enabled)
Set the Enabled property of the PS channel.
Definition PS_Channel.cpp:206
void UpdateOutput()
Set the voltage at the output of this channel to the value calculated by the PID regulator if the out...
Definition PS_Channel.cpp:49
float GetOppLevel()
Get the OppLevel property of the PS channel.
Definition PS_Channel.h:265
volatile uint16_t TimeCounter_OcpDelay_ms
Time counter used to measure how long the channel has an over current.
Definition PS_Channel.h:91
uint8_t GetOvpLevel()
Get the OvpLevel property of the PS channel.
Definition PS_Channel.h:193
Parameter< bool > OppState
Is the over power protection for the channel enabled or not.
Definition PS_Channel.h:82
void SwitchOffOutput()
Set the voltage at the output of this channel to zero.
Definition PS_Channel.cpp:44
bool SetOppLevel(float oppLevel)
Set the OppLevel property of the PS channel.
Definition PS_Channel.cpp:316
float GetOppDelay()
Get the OppDelay property of the PS channel.
Definition PS_Channel.h:289
bool SetOvpDelay(float ovpDelay)
Set the OvpDelay property of the PS channel.
Definition PS_Channel.cpp:260
Parameter< float > OvpDelay
Time after which the over voltage protection kicks in.
Definition PS_Channel.h:76
static void PSOvpDelayChanged(void *channel)
Callback function that can be used for user interface controls modifying the OvpDelay property.
Definition PS_Channel.cpp:398
bool SetOvpState(bool ovpState)
Set the OvpState property of the PS channel.
Definition PS_Channel.cpp:246
volatile float MeasuredCurrent
Measured Current for this channel.
Definition PS_Channel.h:87
volatile uint16_t TimeCounter_OppDelay_ms
Time counter used to measure how long the channel has an over power.
Definition PS_Channel.h:92
bool GetOvpState()
Get the OvpState property of the PS channel.
Definition PS_Channel.h:205
bool SetOppDelay(float oppDelay)
Set the OppDelay property of the PS channel.
Definition PS_Channel.cpp:344
float _PIDVoltErrorSum
PID voltage regulator error sum.
Definition PS_Channel.h:63
float GetOcpLevel()
Get the OcpLevel property of the PS channel.
Definition PS_Channel.h:229
static void PSOppStateChanged(void *channel)
Callback function that can be used for user interface controls modifying the OppState property.
Definition PS_Channel.cpp:433
float GetOvpDelay()
Get the OvpDelay property of the PS channel.
Definition PS_Channel.h:217
volatile float MeasuredPower
Measured Power for this channel.
Definition PS_Channel.h:88
float _PIDVoltErrorLast
PID voltage regulator last error.
Definition PS_Channel.h:64
static void PSOvpLevelChanged(void *channel)
Callback function that can be used for user interface controls modifying the OvpLevel property.
Definition PS_Channel.cpp:384
void CheckProtections()
Check if one of the protections for the power supply channel is tripped and update the PsState accord...
Definition PS_Channel.cpp:127
Parameter< bool > OcpState
Is the over current protection for the channel enabled or not.
Definition PS_Channel.h:78
Class used to bundle min, max, default and the current values for parameters.
Definition Parameter.h:17