Electronic Load 1.0 Programmable Constant Current Sink

Functions | Variables
config.c File Reference

Routines for handling Configuration Data. More...

Include dependency graph for config.c:

## Functions
static void | DefaultConfig (void)
| Loads default config values into conf-struct and stores it in non volatile Memory. More...
void | DumpConfig (void)
| Lists the current configuration values. More...
void | ReadConfig (void)
| Reads the Config-Struct from EEPROM into config. More...
double | SOAGetImax (double v)
| Calculate maximum allowable Current at a given Voltage. More...
void | WriteConfig (void)
| Writes the Config-Struct to EEPROM. More...

## Variables
confStruct_t | config
| The Configuration. It is read on startup from the EEPROM. More...
bool | configDirty =false
| Set to true by routines affecting configuration if config memory needs to be saved to the EEPROM. More...
confStruct_t EEMEM | eepConfig
| This struct will be stored in the EEPROM and is contained in the Production File. More...
volatileConfStruct_t | volatileConfig
| Configuration Values that can be calculated. More...

## Detailed Description

Routines for handling Configuration Data.

Author
  Robert Loos rober.nosp@m.t.lo.nosp@m.os@lo.nosp@m.oswe.nosp@m.b.de

Copyright
  Copyright (C) 2014 Robert Loos http://www.loosweb.de

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

The routines here define the configuration memory and setting up the default configuration.

## Function Documentation

## ◆ DefaultConfig()

static void DefaultConfig | ( | void |  | ) |
| static

Loads default config values into conf-struct and stores it in non volatile Memory.

This function is mostly useful during development but I recommend to leave it functional. You can omit this routine if you want to save about 300 bytes of flash but it is quite useful if you change the config struct and change CONF_MAGIC. It will reprogram the EEPROM with default values then. Especially in devices already in the field it would lead to unpredictable results if the configuration memory format would not be compatible with the current version.

Note
  Keep the values here in sync with the values in defaultConfig if you don't like surprises!

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ ReadConfig()

void ReadConfig | ( | void |  | ) |

Reads the Config-Struct from EEPROM into config.

Only the config-struct in RAM will be used. Changes in config will only become permanent if you use a write-command. There is a configDirty-flag that is set by every routine that changes config and is used to remind the user to execute a write-command.

Here is the call graph for this function:

## ◆ WriteConfig()

void WriteConfig | ( | void |  | ) |

Writes the Config-Struct to EEPROM.

Here is the call graph for this function:

## ◆ SOAGetImax()

double SOAGetImax | ( | double | v | ) |

Calculate maximum allowable Current at a given Voltage.

Parameters

  v | The Voltage currently applied

Returns
  The maximum allowable Current to stay within the SOA

## ◆ DumpConfig()

void DumpConfig | ( | void |  | ) |

Lists the current configuration values.

Prints a verbose explanation of the configuration data to the host. This function relies on hprintf_P() which does the work and knows where the host is...

Note
  This function evaluates to nothing if SAVE_MEMORY is defined.

Here is the call graph for this function:

## Variable Documentation

## ◆ config

confStruct_t config

The Configuration. It is read on startup from the EEPROM.

## ◆ volatileConfig

volatileConfStruct_t volatileConfig

Configuration Values that can be calculated.

## ◆ eepConfig

confStruct_t EEMEM eepConfig

Initial value:
=
{
.magic=CONF_MAGIC,
.LCDV0=45,
.LCDBright=255,
.P5VoltsPerLSB=ADCVoltsPerLSB/dividerP5,
.P12VoltsPerLSB=ADCVoltsPerLSB/dividerP12,
.backlightAlwaysOn=true,
.backlightOnTime=5,
.preset= { PRESET0, PRESET1, PRESET2, PRESET3, PRESET4, PRESET5, PRESET6, PRESET7, PRESET8, PRESET9 },
.ADCLowAmpsPerLSB=SPILOWAMPSPERLSB,
.ADCHighAmpsPerLSB=SPIHIGHAMPSPERLSB,
.ADCDiffVoltsPerLSB=SPIDIFFVOLTSPERLSB,
.DACLowAmpsPerLSB=SPILOWAMPSPERLSB,
.DACHighAmpsPerLSB=SPIHIGHAMPSPERLSB,
.soa.iMax=SOA_IMAX,
.soa.pMax=SOA_PMAX,
.soa.i2=SOA_I2,
.soa.v2=SOA_V2,
.soa.i3=SOA_I3,
.soa.tempMax=TEMP_MAX,
}
SPIHIGHAMPSPERLSB
#define SPIHIGHAMPSPERLSB
Amperes per LSB in High Current Range.
Definition: config.h:40
PRESET8
#define PRESET8
Definition: config.h:52
CONF_MAGIC
#define CONF_MAGIC
Increment this value if confStruct_t becomes incompatible to previous versions!
Definition: config.h:27
PRESET2
#define PRESET2
Definition: config.h:46
PRESET9
#define PRESET9
Definition: config.h:53
SOA_V2
#define SOA_V2
The Voltage at the upper Margin of const Pv.
Definition: config.h:61
SOA_I2
#define SOA_I2
The Current at the upper Margin of const Pv.
Definition: config.h:63
PRESET4
#define PRESET4
Definition: config.h:48
SPILOWAMPSPERLSB
#define SPILOWAMPSPERLSB
Amperes per LSB in Low Current Range.
Definition: config.h:41
SOA_IMAX
#define SOA_IMAX
The absolute maximum Current.
Definition: config.h:62
ADCVoltsPerLSB
#define ADCVoltsPerLSB
Voltage step for one LSB of the AD converter.
Definition: Eload.h:20
PRESET3
#define PRESET3
Definition: config.h:47
dividerP5
#define dividerP5
Resistor divider for P5. Gives 7.03V FSR or 6.86mV/LSB.
Definition: Eload.h:21
SOA_I3
#define SOA_I3
The allowable Current at 60V.
Definition: config.h:64
PRESET1
#define PRESET1
Definition: config.h:45
dividerP12
#define dividerP12
Resistor divider for Unreg. Gives 39.6V FSR or 38.7mV/LSB.
Definition: Eload.h:22
SOA_PMAX
#define SOA_PMAX
The maximum allowable Power Dissipation.
Definition: config.h:60
PRESET5
#define PRESET5
Definition: config.h:49
SPIDIFFVOLTSPERLSB
#define SPIDIFFVOLTSPERLSB
Volts per LSB for the differential Voltage Sensor.
Definition: config.h:39
PRESET7
#define PRESET7
Definition: config.h:51
PRESET0
#define PRESET0
Definition: config.h:44
PRESET6
#define PRESET6
Definition: config.h:50
TEMP_MAX
#define TEMP_MAX
Maximum sink temperature before Eload switches off.
Definition: config.h:65

This struct will be stored in the EEPROM and is contained in the Production File.

'New' devices are programmed using the production file which also can write the default EEPROM content and the fuses.

## ◆ configDirty

bool configDirty =false

Set to true by routines affecting configuration if config memory needs to be saved to the EEPROM.