Created current fuse logic

This commit is contained in:
2024-04-12 11:51:21 +03:00
parent 22ac8240a2
commit 5bb3ebe1bf
3 changed files with 113 additions and 0 deletions

67
firmware/src/hw/fuse.cpp Normal file
View File

@@ -0,0 +1,67 @@
/**** Includes ****/
#include "../utils/utils.h"
#include "../utils/interpolate.h"
#include "fuse.h"
using namespace hw;
/**** Private definitions ****/
/**** Private constants ****/
/**** Private variables ****/
/**** Private function declarations ****/
/**** Public function definitions ****/
hw::Fuse::Fuse(bsp::AnalogIn* ain_ch)
{
this->hold_current = 0;
this->trip_cycles = 0;
this->warning = 0;
this->fault = 0;
this->cooldown_counter = 0;
this->cooldown_cycles = 0;
this->retry_cnt = 0;
}
hw::Fuse::~Fuse(void)
{
return;
}
void hw::Fuse::update(void)
{
// Under threshold
if(this->ain_ch->last_read <= this->hold_current)
{
// Clear warning flag
this->warning = 0;
// OC energy counter
if(this->oc_counter > 0) this->oc_counter--;
// Cool down fuse
if(this->cooldown_counter > 0) this->cooldown_counter--;
// Auto reset logic
if((this->fault)&&(this->cooldown_counter==0))
{
this->fault = 0;
this->retry_cnt = util::sat_add(this->retry_cnt, 1);
};
return;
};
// Over current condition
this->warning = 1;
// PC energy counter
this->oc_counter = util::sat_add(this->oc_counter, 1);
// Check for trip threshold
if(this->oc_counter < this->trip_cycles) return;
// Trip fuse
this->fault = 1;
this->cooldown_counter = this->cooldown_cycles;
}
/**** Private function definitions ****/

40
firmware/src/hw/fuse.h Normal file
View File

@@ -0,0 +1,40 @@
#ifndef FUSE_H_
#define FUSE_H_
/**** Includes ****/
#include <stdint.h>
#include "../bsp/ain.h"
namespace hw {
/**** Public definitions ****/
class Fuse
{
protected:
bsp::AnalogIn* ain_ch;
uint16_t oc_counter;
uint16_t cooldown_counter;
public:
Fuse(bsp::AnalogIn* ain_ch);
~Fuse(void);
uint16_t hold_current;
uint16_t trip_cycles;
uint8_t warning;
uint8_t fault;
uint16_t cooldown_cycles;
uint8_t retry_cnt;
void update(void);
};
/**** Public function declarations ****/
#ifdef TESTING
#endif
} //namespace
#endif /* POTENTIOMETER_H_ */

View File

@@ -213,6 +213,12 @@
<Compile Include="hw\display_led.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="hw\fuse.cpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="hw\fuse.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="hw\potentiometer.cpp">
<SubType>compile</SubType>
</Compile>