Compare commits
2 Commits
f1edc6e15a
...
5bb3ebe1bf
| Author | SHA1 | Date | |
|---|---|---|---|
| 5bb3ebe1bf | |||
| 22ac8240a2 |
67
firmware/src/hw/fuse.cpp
Normal file
67
firmware/src/hw/fuse.cpp
Normal 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
40
firmware/src/hw/fuse.h
Normal 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_ */
|
||||
@@ -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>
|
||||
|
||||
@@ -57,7 +57,6 @@ uint16_t util::sat_subtract(uint16_t x, uint16_t y)
|
||||
if(z > x) return 0;
|
||||
else return z;
|
||||
}
|
||||
|
||||
uint32_t util::sat_subtract(uint32_t x, uint32_t y)
|
||||
{
|
||||
uint32_t z = x - y;
|
||||
@@ -66,6 +65,25 @@ uint32_t util::sat_subtract(uint32_t x, uint32_t y)
|
||||
else return z;
|
||||
}
|
||||
|
||||
uint8_t util::abs_subtract(uint8_t x, uint8_t y)
|
||||
{
|
||||
if(x > y) return x - y;
|
||||
else return y-x;
|
||||
}
|
||||
|
||||
uint16_t util::abs_subtract(uint16_t x, uint16_t y)
|
||||
{
|
||||
if(x > y) return x - y;
|
||||
else return y-x;
|
||||
}
|
||||
|
||||
uint32_t util::abs_subtract(uint32_t x, uint32_t y)
|
||||
{
|
||||
if(x > y) return x - y;
|
||||
else return y-x;
|
||||
}
|
||||
|
||||
|
||||
uint16_t util::sat_cast(uint32_t x)
|
||||
{
|
||||
if(x > 0x0000FFFF) return 0xFFFF;
|
||||
|
||||
@@ -27,6 +27,10 @@ uint8_t sat_subtract(uint8_t x, uint8_t y);
|
||||
uint16_t sat_subtract(uint16_t x, uint16_t y);
|
||||
uint32_t sat_subtract(uint32_t x, uint32_t y);
|
||||
|
||||
uint8_t abs_subtract(uint8_t x, uint8_t y);
|
||||
uint16_t abs_subtract(uint16_t x, uint16_t y);
|
||||
uint32_t abs_subtract(uint32_t x, uint32_t y);
|
||||
|
||||
uint16_t interpolate_1d(uint16_t x, uint16_t* x_axis, uint16_t* y_values, uint8_t len_axis);
|
||||
uint16_t interpolate_2d(uint16_t x, uint16_t y, uint16_t* x_axis, uint8_t len_x_axis, uint16_t* y_axis, uint8_t len_y_axis, uint16_t* z_values);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user