Compare commits
2 Commits
e4bd6d2e04
...
3045b88413
| Author | SHA1 | Date | |
|---|---|---|---|
| 3045b88413 | |||
| 91a7247bee |
@@ -5,7 +5,8 @@
|
||||
/**** Private definitions ****/
|
||||
/**** Private constants ****/
|
||||
static const uint16_t def_button_hold_time = 1000;
|
||||
static const uint16_t def_min_current = 100;
|
||||
static const uint16_t def_max_voltage = 7000;
|
||||
static const uint16_t def_min_voltage = 100;
|
||||
static const uint16_t def_fuse_treshold = 6000;
|
||||
static const uint16_t def_fuse_hold_cycles = 50;
|
||||
static const uint16_t def_fuse_cooldown_cycles = 1000;
|
||||
@@ -20,8 +21,9 @@ void devices_init(void)
|
||||
btn_up.hold_time = def_button_hold_time;
|
||||
btn_down.hold_time = def_button_hold_time;
|
||||
|
||||
ccout.target = 0;
|
||||
ccout.min_out = def_min_current;
|
||||
ccout.max_voltage = def_max_voltage;
|
||||
ccout.max_current = 0;
|
||||
ccout.min_voltage = def_min_voltage;
|
||||
|
||||
sup_fuse.hold_current = def_fuse_treshold;
|
||||
sup_fuse.trip_cycles = def_fuse_hold_cycles;
|
||||
|
||||
@@ -9,8 +9,7 @@
|
||||
#include "button.h"
|
||||
#include "potentiometer.h"
|
||||
#include "display_led.h"
|
||||
#include "cv_output.h"
|
||||
#include "cc_output.h"
|
||||
#include "reg_out.h"
|
||||
#include "fuse.h"
|
||||
|
||||
static hw::Button btn_mode = hw::Button(&din1, bsp::DIN_LOW, 10, hw::BUTTON_OFF);
|
||||
@@ -25,7 +24,7 @@ static hw::Potentiometer pot = hw::Potentiometer(&ain2, 500, 4500);
|
||||
|
||||
static hw::DisplayLed display = hw::DisplayLed(&odout1, &odout2, &odout3, &odout4, &odout5, &odout6, &od_pwm);
|
||||
|
||||
static hw::CCoutput ccout = hw::CCoutput(&hbridge, &bat_u, &dccd_u, &dccd_i);
|
||||
static hw::RegOut ccout = hw::RegOut(&hbridge, &bat_u, &dccd_u, &dccd_i);
|
||||
static hw::Fuse sup_fuse = hw::Fuse(&bat_i);
|
||||
static hw::Fuse out_fuse = hw::Fuse(&dccd_i);
|
||||
|
||||
|
||||
71
firmware/src/hw/reg_out.cpp
Normal file
71
firmware/src/hw/reg_out.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
/**** Includes ****/
|
||||
#include "../utils/utils.h"
|
||||
#include "reg_out.h"
|
||||
|
||||
using namespace hw;
|
||||
|
||||
/**** Private definitions ****/
|
||||
/**** Private constants ****/
|
||||
/**** Private variables ****/
|
||||
/**** Private function declarations ****/
|
||||
|
||||
/**** Public function definitions ****/
|
||||
hw::RegOut::RegOut(bsp::Hafbridge* hbridge, bsp::AnalogIn* sup_u, bsp::AnalogIn* out_u, bsp::AnalogIn* out_i)
|
||||
{
|
||||
this->hbridge = hbridge;
|
||||
this->supply_voltage = sup_u;
|
||||
this->out_voltage = out_u;
|
||||
this->out_currnet = out_i;
|
||||
|
||||
this->max_voltage = 6750;
|
||||
this->max_current = 4500;
|
||||
this->min_voltage = 200;
|
||||
|
||||
this->set_voltage = 0;
|
||||
this->out_impedance = 0xFFFF;
|
||||
|
||||
this->hbridge->disable();
|
||||
}
|
||||
|
||||
hw::RegOut::~RegOut(void)
|
||||
{
|
||||
this->hbridge->write((uint16_t)0x0000);
|
||||
this->hbridge->disable();
|
||||
return;
|
||||
}
|
||||
|
||||
void hw::RegOut::update(void)
|
||||
{
|
||||
// Calculate output impedance
|
||||
if((this->out_currnet == 0)||(this->out_voltage->last_read == 0)) this->out_impedance = 0xFFFF;
|
||||
else this->out_impedance = util::sat_div_kilo(this->out_voltage->last_read, this->out_currnet->last_read);
|
||||
|
||||
// Recalculate output set voltage
|
||||
if((this->max_voltage==0)||(this->max_current==0)) this->set_voltage = 0;
|
||||
else this->set_voltage = util::sat_mul_kilo(this->max_current, this->out_impedance);
|
||||
|
||||
// Limit set voltage
|
||||
if(this->set_voltage > this->max_voltage) this->set_voltage = this->max_voltage;
|
||||
|
||||
if((this->set_voltage>0)&&(this->set_voltage < this->min_voltage)) this->set_voltage = this->min_voltage;
|
||||
|
||||
// Set output
|
||||
this->hbridge->write(util::sat_ratio(this->set_voltage, this->supply_voltage->last_read));
|
||||
}
|
||||
|
||||
void hw::RegOut::enable(void)
|
||||
{
|
||||
this->hbridge->enable();
|
||||
}
|
||||
|
||||
void hw::RegOut::disable(void)
|
||||
{
|
||||
this->hbridge->disable();
|
||||
}
|
||||
|
||||
uint8_t hw::RegOut::is_enabled(void)
|
||||
{
|
||||
return this->hbridge->is_enabled();
|
||||
}
|
||||
|
||||
/**** Private function definitions ****/
|
||||
45
firmware/src/hw/reg_out.h
Normal file
45
firmware/src/hw/reg_out.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#ifndef REGULATED_OUTPUT_H_
|
||||
#define REGULATED_OUTPUT_H_
|
||||
|
||||
/**** Includes ****/
|
||||
#include <stdint.h>
|
||||
#include "../bsp/ain.h"
|
||||
#include "../bsp/halfbridge.h"
|
||||
|
||||
namespace hw {
|
||||
|
||||
/**** Public definitions ****/
|
||||
|
||||
class RegOut
|
||||
{
|
||||
protected:
|
||||
bsp::Hafbridge* hbridge;
|
||||
bsp::AnalogIn* supply_voltage;
|
||||
bsp::AnalogIn* out_voltage;
|
||||
bsp::AnalogIn* out_currnet;
|
||||
|
||||
public:
|
||||
RegOut(bsp::Hafbridge* hbridge, bsp::AnalogIn* sup_u, bsp::AnalogIn* out_u, bsp::AnalogIn* out_i);
|
||||
~RegOut(void);
|
||||
|
||||
uint16_t max_voltage;
|
||||
uint16_t max_current;
|
||||
uint16_t min_voltage;
|
||||
|
||||
uint16_t set_voltage;
|
||||
uint16_t out_impedance;
|
||||
|
||||
void update(void);
|
||||
void enable(void);
|
||||
void disable(void);
|
||||
uint8_t is_enabled(void);
|
||||
};
|
||||
|
||||
/**** Public function declarations ****/
|
||||
|
||||
#ifdef TESTING
|
||||
#endif
|
||||
|
||||
} //namespace
|
||||
|
||||
#endif /* REGULATED_OUTPUT_H_ */
|
||||
@@ -14,6 +14,9 @@ static const uint16_t addr_dsp_dimm = 0x0004;
|
||||
static const uint16_t addr_brake_force = 0x0005;
|
||||
static const uint16_t addr_max_hbrake_time = 0x0006;
|
||||
static const uint16_t addr_lock_current = 0x0008;
|
||||
static const uint16_t addr_max_out_voltage = 0x000A;
|
||||
static const uint16_t addr_min_out_voltage = 0x000C;
|
||||
static const uint16_t addr_cfg_good = 0x000D;
|
||||
|
||||
static const uint8_t def_btn_force = 0;
|
||||
static const uint8_t def_pot_mode = 0;
|
||||
@@ -23,14 +26,16 @@ static const uint8_t def_brigth = 100;
|
||||
static const uint8_t def_brake_force = 100;
|
||||
static const uint16_t def_max_hbrake_time = 1000;
|
||||
static const uint16_t def_lock_current = 4500;
|
||||
|
||||
static const uint16_t max_lock_current = 6000;
|
||||
static const uint16_t def_max_out_voltage = 7000;
|
||||
static const uint16_t def_min_out_voltage = 200;
|
||||
|
||||
/**** Private variables ****/
|
||||
/**** Private function declarations ****/
|
||||
/**** Public function definitions ****/
|
||||
logic::CfgMemory::CfgMemory(void)
|
||||
{
|
||||
this->cfg_good = 0;
|
||||
|
||||
this->mem_btn_force = 0;
|
||||
this->mem_bmode = 0;
|
||||
this->mem_pot_mode = 0;
|
||||
@@ -39,6 +44,8 @@ logic::CfgMemory::CfgMemory(void)
|
||||
this->mem_brake_force = 0;
|
||||
this->mem_max_hbrake_time = 0;
|
||||
this->mem_lock_current = 0;
|
||||
this->mem_max_out_voltage = 0;
|
||||
this->mem_min_out_voltage = 0;
|
||||
|
||||
this->restore();
|
||||
}
|
||||
@@ -50,6 +57,7 @@ logic::CfgMemory::~CfgMemory(void)
|
||||
|
||||
void logic::CfgMemory::init(void)
|
||||
{
|
||||
uint8_t cfg_good_magic = mcu::eeprom_read8b(addr_cfg_good);
|
||||
this->mem_btn_force = mcu::eeprom_read8b(addr_btn_force);
|
||||
this->mem_bmode = mcu::eeprom_read8b(addr_bmode);
|
||||
this->mem_pot_mode = mcu::eeprom_read8b(addr_pot_mode);
|
||||
@@ -58,58 +66,26 @@ void logic::CfgMemory::init(void)
|
||||
this->mem_brake_force = mcu::eeprom_read8b(addr_brake_force);
|
||||
this->mem_max_hbrake_time = mcu::eeprom_read16b(addr_max_hbrake_time);
|
||||
this->mem_lock_current = mcu::eeprom_read16b(addr_lock_current);
|
||||
this->mem_max_out_voltage = mcu::eeprom_read16b(addr_max_out_voltage);
|
||||
this->mem_min_out_voltage = mcu::eeprom_read16b(addr_min_out_voltage);
|
||||
|
||||
// Validate EEPROM data
|
||||
if(this->mem_btn_force > 100)
|
||||
if(cfg_good_magic == 0x37) this->cfg_good = 1;
|
||||
else this->cfg_good = 0;
|
||||
|
||||
if(this->cfg_good != 1)
|
||||
{
|
||||
this->mem_btn_force = def_btn_force;
|
||||
mcu::eeprom_write8b(addr_btn_force, this->mem_btn_force);
|
||||
};
|
||||
|
||||
if(this->mem_bmode > 2)
|
||||
{
|
||||
this->mem_bmode = def_bmode;
|
||||
mcu::eeprom_write8b(addr_bmode, this->mem_bmode);
|
||||
};
|
||||
|
||||
if(this->mem_pot_mode > 1)
|
||||
{
|
||||
this->mem_pot_mode = def_pot_mode;
|
||||
mcu::eeprom_write8b(addr_pot_mode, this->mem_pot_mode);
|
||||
};
|
||||
|
||||
if(this->mem_dsp_brigth > 100)
|
||||
{
|
||||
this->mem_dsp_brigth = def_brigth;
|
||||
mcu::eeprom_write8b(addr_dsp_brigth, this->mem_dsp_brigth);
|
||||
};
|
||||
|
||||
if(this->mem_dsp_dimm > 100)
|
||||
{
|
||||
this->mem_dsp_dimm = def_dimm;
|
||||
mcu::eeprom_write8b(addr_dsp_dimm, this->mem_dsp_dimm);
|
||||
};
|
||||
|
||||
if(this->mem_brake_force > 100)
|
||||
{
|
||||
this->mem_brake_force = def_brake_force;
|
||||
mcu::eeprom_write8b(addr_brake_force, this->mem_brake_force);
|
||||
};
|
||||
|
||||
/*
|
||||
No wrong value
|
||||
if(this->mem_max_hbrake_time > 1000)
|
||||
{
|
||||
this->mem_max_hbrake_time = def_max_hbrake_time;
|
||||
mcu::eeprom_write16b(addr_lock_current, this->mem_max_hbrake_time);
|
||||
};
|
||||
*/
|
||||
|
||||
if(this->mem_lock_current > max_lock_current)
|
||||
{
|
||||
this->mem_lock_current = def_lock_current;
|
||||
mcu::eeprom_write16b(addr_lock_current, this->mem_lock_current);
|
||||
};
|
||||
this->mem_max_out_voltage = def_max_out_voltage;
|
||||
this->mem_min_out_voltage = def_min_out_voltage;
|
||||
}
|
||||
|
||||
this->restore();
|
||||
}
|
||||
@@ -168,6 +144,18 @@ void logic::CfgMemory::save_all(void)
|
||||
this->mem_lock_current = this->lock_current;
|
||||
mcu::eeprom_write16b(addr_lock_current, this->mem_lock_current);
|
||||
};
|
||||
|
||||
if(this->max_out_voltage != this->mem_max_out_voltage)
|
||||
{
|
||||
this->mem_max_out_voltage = this->max_out_voltage;
|
||||
mcu::eeprom_write16b(addr_max_out_voltage, this->mem_max_out_voltage);
|
||||
};
|
||||
|
||||
if(this->min_out_voltage != this->mem_min_out_voltage)
|
||||
{
|
||||
this->mem_min_out_voltage = this->min_out_voltage;
|
||||
mcu::eeprom_write16b(addr_min_out_voltage, this->mem_min_out_voltage);
|
||||
};
|
||||
}
|
||||
|
||||
void logic::CfgMemory::restore(void)
|
||||
@@ -180,6 +168,26 @@ void logic::CfgMemory::restore(void)
|
||||
this->brake_force = this->mem_brake_force;
|
||||
this->max_hbrake_time = this->mem_max_hbrake_time;
|
||||
this->lock_current = this->mem_lock_current;
|
||||
this->max_out_voltage = this->mem_max_out_voltage;
|
||||
this->min_out_voltage = this->mem_min_out_voltage;
|
||||
}
|
||||
|
||||
uint8_t logic::CfgMemory::checksum(void)
|
||||
{
|
||||
uint32_t cs = 0;
|
||||
cs += (uint32_t)this->mem_btn_force;
|
||||
cs += (uint32_t)this->mem_bmode;
|
||||
cs += (uint32_t)this->mem_pot_mode;
|
||||
cs += (uint32_t)this->mem_dsp_brigth;
|
||||
cs += (uint32_t)this->mem_dsp_dimm;
|
||||
cs += (uint32_t)this->mem_brake_force;
|
||||
cs += (uint32_t)this->mem_max_hbrake_time;
|
||||
cs += (uint32_t)this->mem_lock_current;
|
||||
cs += (uint32_t)this->mem_max_out_voltage;
|
||||
cs += (uint32_t)this->mem_min_out_voltage;
|
||||
|
||||
return (uint8_t)cs;
|
||||
}
|
||||
|
||||
|
||||
/**** Private function definitions ****/
|
||||
|
||||
@@ -20,11 +20,14 @@ class CfgMemory
|
||||
uint8_t mem_brake_force;
|
||||
uint16_t mem_max_hbrake_time;
|
||||
uint16_t mem_lock_current;
|
||||
uint16_t mem_max_out_voltage;
|
||||
uint16_t mem_min_out_voltage;
|
||||
|
||||
public:
|
||||
CfgMemory(void);
|
||||
~CfgMemory(void);
|
||||
|
||||
uint8_t cfg_good;
|
||||
uint8_t btn_force;
|
||||
uint8_t bmode;
|
||||
uint8_t pot_mode;
|
||||
@@ -33,11 +36,14 @@ class CfgMemory
|
||||
uint8_t brake_force;
|
||||
uint16_t max_hbrake_time;
|
||||
uint16_t lock_current;
|
||||
uint16_t max_out_voltage;
|
||||
uint16_t min_out_voltage;
|
||||
|
||||
void init(void);
|
||||
void save(void);
|
||||
void save_all(void);
|
||||
void restore(void);
|
||||
uint8_t checksum(void);
|
||||
};
|
||||
|
||||
/**** Public function declarations ****/
|
||||
|
||||
@@ -29,8 +29,26 @@ int main(void)
|
||||
// Read saved config
|
||||
cfg_mem.init();
|
||||
|
||||
if(cfg_mem.cfg_good !=1 )
|
||||
{
|
||||
cfg_mem.btn_force = 0;
|
||||
cfg_mem.bmode = 0;
|
||||
cfg_mem.pot_mode = 0;
|
||||
cfg_mem.dsp_brigth = 100;
|
||||
cfg_mem.dsp_dimm = 50;
|
||||
cfg_mem.brake_force = 100;
|
||||
cfg_mem.max_hbrake_time = 1000;
|
||||
cfg_mem.lock_current = 4200;
|
||||
cfg_mem.max_out_voltage = 6500;
|
||||
cfg_mem.min_out_voltage = 500;
|
||||
cfg_mem.save_all();
|
||||
};
|
||||
|
||||
uint8_t user_force = 0;
|
||||
|
||||
ccout.max_voltage = cfg_mem.max_out_voltage;
|
||||
ccout.min_voltage = cfg_mem.min_out_voltage;
|
||||
|
||||
button_force.force = cfg_mem.btn_force;
|
||||
dccd_force.brake_mode = cfg_mem.bmode;
|
||||
dccd_force.max_hbrake_time = cfg_mem.max_hbrake_time;
|
||||
@@ -56,7 +74,7 @@ int main(void)
|
||||
if((sup_fuse.fault)||(out_fuse.fault)) dccd_force.force = 0;
|
||||
|
||||
// Convert force to current
|
||||
ccout.target = util::percent_of(dccd_force.force, cfg_mem.lock_current);
|
||||
ccout.max_current = util::percent_of(dccd_force.force, cfg_mem.lock_current);
|
||||
|
||||
// Execute outputs
|
||||
ccout.update();
|
||||
|
||||
@@ -207,18 +207,6 @@
|
||||
<Compile Include="hw\button.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="hw\cc_output.cpp">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="hw\cc_output.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="hw\cv_output.cpp">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="hw\cv_output.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="hw\display_led.cpp">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
@@ -243,6 +231,12 @@
|
||||
<Compile Include="hw\potentiometer.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="hw\reg_out.cpp">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="hw\reg_out.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="logic\button_force.cpp">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
|
||||
Reference in New Issue
Block a user