PS_Fgen_FW  4da88f4073c1cc65ea45c3a652a2751e495e50db
Firmware for an Power Supply and Function Generator build from an ATX power supply
Loading...
Searching...
No Matches
PS_Channel Class Reference

Power supply channel Class. More...

#include <PS_Channel.h>

Inheritance diagram for PS_Channel:
Channel

Public Member Functions

 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.
 
void SwitchOffOutput ()
 Set the voltage at the output of this channel to zero.
 
void UpdateOutput ()
 Set the voltage at the output of this channel to the value calculated by the PID regulator if the output is enabled and in CV state.
 
void DoRegulationISR ()
 This method is called periodically based on the device timer ISR (multiples of the device timer period) and runs in the ISR context.
 
void CheckProtections ()
 Check if one of the protections for the power supply channel is tripped and update the PsState accordingly.
 
void ClearProtections ()
 Clear the protections for the power supply channel and return to the CV state.
 
bool IsProtectionActive ()
 Check if at least one protection is active (OVP, OCP, OPP)
 
PsStates_t GetPsState ()
 Return the current state of this channel.
 
bool SetRegulationMode (PsRegulationModes_t regulationMode)
 Set the RegulationMode property of the PS channel.
 
PsRegulationModes_t GetRegulationMode ()
 Get the RegulationMode property of the PS channel.
 
bool SetEnabled (bool enabled)
 Set the Enabled property of the PS channel.
 
bool GetEnabled ()
 Get the Enabled property of the PS channel.
 
bool SetVoltage (float voltage)
 Set the Voltage property of the PS channel.
 
float GetVoltage ()
 Get the Voltage property of the PS channel.
 
bool SetOvpLevel (uint8_t ovpLevel)
 Set the OvpLevel property of the PS channel.
 
uint8_t GetOvpLevel ()
 Get the OvpLevel property of the PS channel.
 
bool SetOvpState (bool ovpState)
 Set the OvpState property of the PS channel.
 
bool GetOvpState ()
 Get the OvpState property of the PS channel.
 
bool SetOvpDelay (float ovpDelay)
 Set the OvpDelay property of the PS channel.
 
float GetOvpDelay ()
 Get the OvpDelay property of the PS channel.
 
bool SetOcpLevel (float ocpLevel)
 Set the OcpLevel property of the PS channel.
 
float GetOcpLevel ()
 Get the OcpLevel property of the PS channel.
 
bool SetOcpState (bool ocpState)
 Set the OcpState property of the PS channel.
 
bool GetOcpState ()
 Get the OcpState property of the PS channel.
 
bool SetOcpDelay (float ocpDelay)
 Set the OcpDelay property of the PS channel.
 
float GetOcpDelay ()
 Get the OcpDelay property of the PS channel.
 
bool SetOppLevel (float oppLevel)
 Set the OppLevel property of the PS channel.
 
float GetOppLevel ()
 Get the OppLevel property of the PS channel.
 
bool SetOppState (bool oppState)
 Set the OppState property of the PS channel.
 
bool GetOppState ()
 Get the OppState property of the PS channel.
 
bool SetOppDelay (float oppDelay)
 Set the OppDelay property of the PS channel.
 
float GetOppDelay ()
 Get the OppDelay property of the PS channel.
 
- Public Member Functions inherited from Channel
 Channel (ChannelTypes_t channelType)
 Constructor of the Channel class.
 
ChannelTypes_t GetChannelType ()
 Function that can be used to return the _channelType property.
 

Static Public Member Functions

static void PSRegulationModeChanged (void *channel)
 Callback function that can be used for user interface controls modifying the RegulationMode property.
 
static void PSEnabledChanged (void *channel)
 Callback function that can be used for user interface controls modifying the Enabled property.
 
static void PSVoltageChanged (void *channel)
 Callback function that can be used for user interface controls modifying the Voltage property.
 
static void PSOvpLevelChanged (void *channel)
 Callback function that can be used for user interface controls modifying the OvpLevel property.
 
static void PSOvpStateChanged (void *channel)
 Callback function that can be used for user interface controls modifying the OvpState property.
 
static void PSOvpDelayChanged (void *channel)
 Callback function that can be used for user interface controls modifying the OvpDelay property.
 
static void PSOcpLevelChanged (void *channel)
 Callback function that can be used for user interface controls modifying the OcpLevel property.
 
static void PSOcpStateChanged (void *channel)
 Callback function that can be used for user interface controls modifying the OcpState property.
 
static void PSOcpDelayChanged (void *channel)
 Callback function that can be used for user interface controls modifying the OcpDelay property.
 
static void PSOppLevelChanged (void *channel)
 Callback function that can be used for user interface controls modifying the OppLevel property.
 
static void PSOppStateChanged (void *channel)
 Callback function that can be used for user interface controls modifying the OppState property.
 
static void PSOppDelayChanged (void *channel)
 Callback function that can be used for user interface controls modifying the OppDelay property.
 

Public Attributes

volatile PsStates_t PsState
 Current state of the power supply channel.
 
volatile PsRegulationModes_t RegulationMode
 Current regulation mode of the power supply channel.
 
Parameter< bool > Enabled
 Is the channel enabled or not.
 
Parameter< float > Voltage
 Voltage of the power supply channel.
 
Parameter< bool > OvpState
 Is the over voltage protection for the channel enabled or not.
 
Parameter< uint8_t > OvpLevel
 OVP trip level in percentage of the Voltage.
 
Parameter< float > OvpDelay
 Time after which the over voltage protection kicks in.
 
Parameter< bool > OcpState
 Is the over current protection for the channel enabled or not.
 
Parameter< float > OcpLevel
 OCP trip level in Ampere.
 
Parameter< float > OcpDelay
 Time after which the over current protection kicks in.
 
Parameter< bool > OppState
 Is the over power protection for the channel enabled or not.
 
Parameter< float > OppLevel
 OPP trip level in Watt.
 
Parameter< float > OppDelay
 Time after which the over power protection kicks in.
 
volatile float MeasuredVoltage
 Measured Voltage for this channel.
 
volatile float MeasuredCurrent
 Measured Current for this channel.
 
volatile float MeasuredPower
 Measured Power for this channel.
 
volatile uint16_t TimeCounter_OvpDelay_ms
 Time counter used to measure how long the channel has an over voltage.
 
volatile uint16_t TimeCounter_OcpDelay_ms
 Time counter used to measure how long the channel has an over current.
 
volatile uint16_t TimeCounter_OppDelay_ms
 Time counter used to measure how long the channel has an over power.
 

Private Attributes

float _PIDVoltErrorSum
 PID voltage regulator error sum.
 
float _PIDVoltErrorLast
 PID voltage regulator last error.
 
float _setVoltage
 Voltage to which the output should be set.
 

Additional Inherited Members

- Protected Attributes inherited from Channel
ChannelTypes_t _channelType
 Type of the channel.
 

Detailed Description

Power supply channel Class.

This is a channel holding all parameters of a power supply implementation.

The voltage is regulated by a PID regulator.

An anti-windup provision is implemented on the PID integrator to prevent deep saturation (aka integrator windup) when the output is saturated:

  • The new control output with the latest integrator value is computed.
  • If the control output exceeds either output limit, and the latest change in the integrator is in the same direction, then the new integrator value is not saved for the next call.
  • Otherwise, the integrator is saved for the next call.
See also
https://rn-wissen.de/wiki/index.php/Regelungstechnik (for general PID regulator code)
https://tlk-energy.de/blog/pid-regler-einstellen (for PID parameter setup)
https://www.embeddedrelated.com/showcode/346.php (for PID anti-windup scheme)

Constructor & Destructor Documentation

◆ PS_Channel()

PS_Channel::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.

Parameters
minVoltMinimum allowed voltage for the PS channel
maxVoltMaximum allowed voltage for the PS channel
minOvpLevelMinimum allowed Ovp level for the PS channel
maxOvpLevelMaximum allowed Ovp level for the PS channel
minOvpDelayMinimum allowed Ovp delay for the PS channel
maxOvpDelayMaximum allowed Ovp delay for the PS channel
minOcpLevelMinimum allowed Ocp level for the PS channel
maxOcpLevelMaximum allowed Ocp level for the PS channel
minOcpDelayMinimum allowed Ocp delay for the PS channel
maxOcpDelayMaximum allowed Ocp delay for the PS channel
minOppLevelMinimum allowed Opp level for the PS channel
maxOppLevelMaximum allowed Opp level for the PS channel
minOppDelayMinimum allowed Opp delay for the PS channel
maxOppDelayMaximum allowed Opp delay for the PS channel

Member Function Documentation

◆ DoRegulationISR()

void PS_Channel::DoRegulationISR ( )

This method is called periodically based on the device timer ISR (multiples of the device timer period) and runs in the ISR context.

It is used to increment the protection timers if neccessary, to change the channel state if an protection kicks in and to calculate a new PID value.

Voltage PID regulator see: https://rn-wissen.de/wiki/index.php/Regelungstechnik

PID Integrator anti-windup see: https://www.embeddedrelated.com/showcode/346.php

◆ GetEnabled()

bool PS_Channel::GetEnabled ( )
inline

Get the Enabled property of the PS channel.

Returns
Value of the Enabled property

◆ GetOcpDelay()

float PS_Channel::GetOcpDelay ( )
inline

Get the OcpDelay property of the PS channel.

Returns
Value of the OcpDelay property

◆ GetOcpLevel()

float PS_Channel::GetOcpLevel ( )
inline

Get the OcpLevel property of the PS channel.

Returns
Value of the OcpLevel property

◆ GetOcpState()

bool PS_Channel::GetOcpState ( )
inline

Get the OcpState property of the PS channel.

Returns
Value of the OcpState property

◆ GetOppDelay()

float PS_Channel::GetOppDelay ( )
inline

Get the OppDelay property of the PS channel.

Returns
Value of the OppDelay property

◆ GetOppLevel()

float PS_Channel::GetOppLevel ( )
inline

Get the OppLevel property of the PS channel.

Returns
Value of the OppLevel property

◆ GetOppState()

bool PS_Channel::GetOppState ( )
inline

Get the OppState property of the PS channel.

Returns
Value of the OppState property

◆ GetOvpDelay()

float PS_Channel::GetOvpDelay ( )
inline

Get the OvpDelay property of the PS channel.

Returns
Value of the OvpDelay property

◆ GetOvpLevel()

uint8_t PS_Channel::GetOvpLevel ( )
inline

Get the OvpLevel property of the PS channel.

Returns
Value of the OvpLevel property

◆ GetOvpState()

bool PS_Channel::GetOvpState ( )
inline

Get the OvpState property of the PS channel.

Returns
Value of the OvpState property

◆ GetPsState()

PsStates_t PS_Channel::GetPsState ( )
inline

Return the current state of this channel.

Returns
Current power supply channel state.

◆ GetRegulationMode()

PsRegulationModes_t PS_Channel::GetRegulationMode ( )
inline

Get the RegulationMode property of the PS channel.

Returns
Value of the RegulationMode property

◆ GetVoltage()

float PS_Channel::GetVoltage ( )
inline

Get the Voltage property of the PS channel.

Returns
Value of the Voltage property

◆ IsProtectionActive()

bool PS_Channel::IsProtectionActive ( )
inline

Check if at least one protection is active (OVP, OCP, OPP)

Returns
true, if any of the OVP, OCP or OPP protections is active; otherwise false

◆ PSEnabledChanged()

void PS_Channel::PSEnabledChanged ( void * channel)
static

Callback function that can be used for user interface controls modifying the Enabled property.

Parameters
channelPointer to a PS_Channel

◆ PSOcpDelayChanged()

void PS_Channel::PSOcpDelayChanged ( void * channel)
static

Callback function that can be used for user interface controls modifying the OcpDelay property.

Parameters
channelPointer to a PS_Channel

◆ PSOcpLevelChanged()

void PS_Channel::PSOcpLevelChanged ( void * channel)
static

Callback function that can be used for user interface controls modifying the OcpLevel property.

Parameters
channelPointer to a PS_Channel

◆ PSOcpStateChanged()

void PS_Channel::PSOcpStateChanged ( void * channel)
static

Callback function that can be used for user interface controls modifying the OcpState property.

Parameters
channelPointer to a PS_Channel

◆ PSOppDelayChanged()

void PS_Channel::PSOppDelayChanged ( void * channel)
static

Callback function that can be used for user interface controls modifying the OppDelay property.

Parameters
channelPointer to a PS_Channel

◆ PSOppLevelChanged()

void PS_Channel::PSOppLevelChanged ( void * channel)
static

Callback function that can be used for user interface controls modifying the OppLevel property.

Parameters
channelPointer to a PS_Channel

◆ PSOppStateChanged()

void PS_Channel::PSOppStateChanged ( void * channel)
static

Callback function that can be used for user interface controls modifying the OppState property.

Parameters
channelPointer to a PS_Channel

◆ PSOvpDelayChanged()

void PS_Channel::PSOvpDelayChanged ( void * channel)
static

Callback function that can be used for user interface controls modifying the OvpDelay property.

Parameters
channelPointer to a PS_Channel

◆ PSOvpLevelChanged()

void PS_Channel::PSOvpLevelChanged ( void * channel)
static

Callback function that can be used for user interface controls modifying the OvpLevel property.

Parameters
channelPointer to a PS_Channel

◆ PSOvpStateChanged()

void PS_Channel::PSOvpStateChanged ( void * channel)
static

Callback function that can be used for user interface controls modifying the OvpState property.

Parameters
channelPointer to a PS_Channel

◆ PSRegulationModeChanged()

void PS_Channel::PSRegulationModeChanged ( void * channel)
static

Callback function that can be used for user interface controls modifying the RegulationMode property.

Parameters
channelPointer to a PS_Channel

◆ PSVoltageChanged()

void PS_Channel::PSVoltageChanged ( void * channel)
static

Callback function that can be used for user interface controls modifying the Voltage property.

Parameters
channelPointer to a PS_Channel

◆ SetEnabled()

bool PS_Channel::SetEnabled ( bool enabled)

Set the Enabled property of the PS channel.

Parameters
enabledNew value for the Enabled property
Returns
true->set successful; false->value not set

◆ SetOcpDelay()

bool PS_Channel::SetOcpDelay ( float ocpDelay)

Set the OcpDelay property of the PS channel.

Parameters
ocpDelayNew value for the OcpDelay property
Returns
true->set successful; false->value not set

◆ SetOcpLevel()

bool PS_Channel::SetOcpLevel ( float ocpLevel)

Set the OcpLevel property of the PS channel.

Parameters
ocpLevelNew value for the OcpLevel property
Returns
true->set successful; false->value not set

◆ SetOcpState()

bool PS_Channel::SetOcpState ( bool ocpState)

Set the OcpState property of the PS channel.

Parameters
ocpStateNew value for the OcpState property
Returns
true->set successful; false->value not set

◆ SetOppDelay()

bool PS_Channel::SetOppDelay ( float oppDelay)

Set the OppDelay property of the PS channel.

Parameters
oppDelayNew value for the OppDelay property
Returns
true->set successful; false->value not set

◆ SetOppLevel()

bool PS_Channel::SetOppLevel ( float oppLevel)

Set the OppLevel property of the PS channel.

Parameters
oppLevelNew value for the OppLevel property
Returns
true->set successful; false->value not set

◆ SetOppState()

bool PS_Channel::SetOppState ( bool oppState)

Set the OppState property of the PS channel.

Parameters
oppStateNew value for the OppState property
Returns
true->set successful; false->value not set

◆ SetOvpDelay()

bool PS_Channel::SetOvpDelay ( float ovpDelay)

Set the OvpDelay property of the PS channel.

Parameters
ovpDelayNew value for the OvpDelay property
Returns
true->set successful; false->value not set

◆ SetOvpLevel()

bool PS_Channel::SetOvpLevel ( uint8_t ovpLevel)

Set the OvpLevel property of the PS channel.

Parameters
ovpLevelNew value for the OvpLevel property
Returns
true->set successful; false->value not set

◆ SetOvpState()

bool PS_Channel::SetOvpState ( bool ovpState)

Set the OvpState property of the PS channel.

Parameters
ovpStateNew value for the OvpState property
Returns
true->set successful; false->value not set

◆ SetRegulationMode()

bool PS_Channel::SetRegulationMode ( PsRegulationModes_t regulationMode)

Set the RegulationMode property of the PS channel.

Parameters
regulationModeNew value for the RegulationMode property
Returns
true->set successful; false->value not set

◆ SetVoltage()

bool PS_Channel::SetVoltage ( float voltage)

Set the Voltage property of the PS channel.

Parameters
voltageNew value for the Voltage property
Returns
true->set successful; false->value not set

◆ UpdateOutput()

void PS_Channel::UpdateOutput ( )

Set the voltage at the output of this channel to the value calculated by the PID regulator if the output is enabled and in CV state.

Otherwise switch off the output.

Member Data Documentation

◆ _setVoltage

float PS_Channel::_setVoltage
private

Voltage to which the output should be set.

This value is calculated by the PID voltage regulator.

◆ Enabled

Parameter<bool> PS_Channel::Enabled

Is the channel enabled or not.

If enabled, the voltage is available at the output.

◆ MeasuredCurrent

volatile float PS_Channel::MeasuredCurrent

Measured Current for this channel.

This value is used for PID regulation of the output current in CC state.

◆ MeasuredPower

volatile float PS_Channel::MeasuredPower

Measured Power for this channel.

This value is calculated from the MeasuredVoltage and MeasuredCurrent.

◆ MeasuredVoltage

volatile float PS_Channel::MeasuredVoltage

Measured Voltage for this channel.

This value is used for PID regulation of the output voltage in CV state.

◆ OcpState

Parameter<bool> PS_Channel::OcpState

Is the over current protection for the channel enabled or not.

If disabled, the OcpLevel and OcpDelay parameters have not effect.

◆ OppState

Parameter<bool> PS_Channel::OppState

Is the over power protection for the channel enabled or not.

If disabled, the OppLevel and OppDelay parameters have not effect.

◆ OvpState

Parameter<bool> PS_Channel::OvpState

Is the over voltage protection for the channel enabled or not.

If disabled, the OvpLevel and OvpDelay parameters have not effect.

◆ RegulationMode

volatile PsRegulationModes_t PS_Channel::RegulationMode

Current regulation mode of the power supply channel.

For more details about the options see the enumeration values.

◆ TimeCounter_OcpDelay_ms

volatile uint16_t PS_Channel::TimeCounter_OcpDelay_ms

Time counter used to measure how long the channel has an over current.

If this value exceeds the OcpDelay, the over current protection kicks in.

◆ TimeCounter_OppDelay_ms

volatile uint16_t PS_Channel::TimeCounter_OppDelay_ms

Time counter used to measure how long the channel has an over power.

If this value exceeds the OppDelay, the over power protection kicks in.

◆ TimeCounter_OvpDelay_ms

volatile uint16_t PS_Channel::TimeCounter_OvpDelay_ms

Time counter used to measure how long the channel has an over voltage.

If this value exceeds the OvpDelay, the over voltage protection kicks in.

◆ Voltage

Parameter<float> PS_Channel::Voltage

Voltage of the power supply channel.

This is the voltage that the PID regulator tries to produce on the output in CV state.


The documentation for this class was generated from the following files: