Could be working version
This commit is contained in:
@@ -25,6 +25,8 @@ hw::Button::Button(bsp::DigitalIn* din_ch, uint8_t act_lvl, uint8_t dbnc_lim, ui
|
||||
|
||||
this->time = 0;
|
||||
this->is_new = 0;
|
||||
|
||||
this->hold_time = 0;
|
||||
}
|
||||
|
||||
hw::Button::~Button(void)
|
||||
@@ -40,6 +42,13 @@ uint8_t hw::Button::update(void)
|
||||
// Increase state counter
|
||||
this->time = util::sat_add(this->time, 1);
|
||||
|
||||
// Repeat new flag after hold time
|
||||
if((this->state == BUTTON_ON)&&(this->time > this->hold_time)&&(this->hold_time > 0))
|
||||
{
|
||||
this->time = 0;
|
||||
this->is_new = 1;
|
||||
};
|
||||
|
||||
// Determine next state
|
||||
uint8_t next_state = BUTTON_OFF;
|
||||
if(lvl==this->act_lvl) next_state = BUTTON_ON;
|
||||
|
||||
@@ -26,6 +26,7 @@ class Button
|
||||
uint16_t time;
|
||||
uint8_t dbnc_lim;
|
||||
uint8_t is_new;
|
||||
uint16_t hold_time;
|
||||
|
||||
uint8_t update(void);
|
||||
uint8_t force_update(void);
|
||||
|
||||
41
firmware/src/hw/cc_output.cpp
Normal file
41
firmware/src/hw/cc_output.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
/**** Includes ****/
|
||||
#include "../utils/utils.h"
|
||||
#include "cc_output.h"
|
||||
|
||||
using namespace hw;
|
||||
|
||||
/**** Private definitions ****/
|
||||
/**** Private constants ****/
|
||||
/**** Private variables ****/
|
||||
/**** Private function declarations ****/
|
||||
|
||||
/**** Public function definitions ****/
|
||||
hw::CCoutput::CCoutput(bsp::Hafbridge* hbridge, bsp::AnalogIn* supply_u, bsp::AnalogIn* out_u, bsp::AnalogIn* out_i) : CVoutput(hbridge, supply_u)
|
||||
{
|
||||
this->out_voltage = out_u;
|
||||
this->out_currnet = out_i;
|
||||
|
||||
this->out_impedance = 0xFFFF;
|
||||
this->target_voltage = 0;
|
||||
}
|
||||
|
||||
void hw::CCoutput::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);
|
||||
}
|
||||
|
||||
// Check target
|
||||
if((this->target < this->min_out)&&(this->target > 0)) this->target = this->min_out;
|
||||
|
||||
// Convert target current to voltage
|
||||
this->target_voltage = util::sat_mul_kilo(this->target, this->out_impedance);
|
||||
|
||||
// Set output
|
||||
this->hbridge->write(util::sat_ratio(this->target_voltage, this->supply->last_read));
|
||||
}
|
||||
|
||||
/**** Private function definitions ****/
|
||||
35
firmware/src/hw/cc_output.h
Normal file
35
firmware/src/hw/cc_output.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef CONST_CURRENT_OUTPUT_H_
|
||||
#define CONST_CURRENT_OUTPUT_H_
|
||||
|
||||
/**** Includes ****/
|
||||
#include <stdint.h>
|
||||
#include "../bsp/ain.h"
|
||||
#include "cv_output.h"
|
||||
|
||||
namespace hw {
|
||||
|
||||
/**** Public definitions ****/
|
||||
|
||||
class CCoutput : public CVoutput
|
||||
{
|
||||
protected:
|
||||
bsp::AnalogIn* out_voltage;
|
||||
bsp::AnalogIn* out_currnet;
|
||||
|
||||
public:
|
||||
CCoutput(bsp::Hafbridge* hbridge, bsp::AnalogIn* supply_u, bsp::AnalogIn* out_u, bsp::AnalogIn* out_i);
|
||||
|
||||
void update(void);
|
||||
|
||||
uint16_t out_impedance;
|
||||
uint16_t target_voltage;
|
||||
};
|
||||
|
||||
/**** Public function declarations ****/
|
||||
|
||||
#ifdef TESTING
|
||||
#endif
|
||||
|
||||
} //namespace
|
||||
|
||||
#endif /* CONST_VOLTAGE_OUTPUT_H_ */
|
||||
59
firmware/src/hw/devices.cpp
Normal file
59
firmware/src/hw/devices.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
/**** Includes ****/
|
||||
#include "../utils/utils.h"
|
||||
#include "devices.h"
|
||||
|
||||
/**** Private definitions ****/
|
||||
/**** Private constants ****/
|
||||
/**** Private variables ****/
|
||||
/**** Private function declarations ****/
|
||||
|
||||
/**** Public function definitions ****/
|
||||
void devices_init(void)
|
||||
{
|
||||
board_init();
|
||||
|
||||
btn_up.hold_time = 1000;
|
||||
btn_down.hold_time = 1000;
|
||||
|
||||
ccout.target = 0;
|
||||
ccout.min_out = 100;
|
||||
|
||||
sup_fuse.hold_current = 6000;
|
||||
sup_fuse.trip_cycles = 50;
|
||||
sup_fuse.cooldown_cycles = 1000;
|
||||
|
||||
out_fuse.hold_current = 6000;
|
||||
out_fuse.trip_cycles = 100;
|
||||
out_fuse.cooldown_cycles = 1000;
|
||||
|
||||
hvdin3_pull.write(bsp::DOUT_HIGH);
|
||||
|
||||
devices_update_inputs();
|
||||
|
||||
display.write(0x00);
|
||||
display.set_brigthness(100);
|
||||
|
||||
ccout.target = 0;
|
||||
ccout.update();
|
||||
ccout.enable();
|
||||
}
|
||||
|
||||
void devices_update_inputs(void)
|
||||
{
|
||||
board_read();
|
||||
|
||||
pot.update();
|
||||
|
||||
btn_mode.update();
|
||||
btn_up.update();
|
||||
btn_down.update();
|
||||
|
||||
sw_dimm.update();
|
||||
sw_brakes.update();
|
||||
sw_hbrake.update();
|
||||
|
||||
sup_fuse.update();
|
||||
out_fuse.update();
|
||||
}
|
||||
|
||||
/**** Private function definitions ****/
|
||||
35
firmware/src/hw/devices.h
Normal file
35
firmware/src/hw/devices.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef HW_DEVICES_H_
|
||||
#define HW_DEVICES_H_
|
||||
|
||||
/**** Includes ****/
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../bsp/board.h"
|
||||
|
||||
#include "button.h"
|
||||
#include "potentiometer.h"
|
||||
#include "display_led.h"
|
||||
#include "cv_output.h"
|
||||
#include "cc_output.h"
|
||||
#include "fuse.h"
|
||||
|
||||
static hw::Button btn_mode = hw::Button(&din1, bsp::DIN_LOW, 10, hw::BUTTON_OFF);
|
||||
static hw::Button btn_up = hw::Button(&din4, bsp::DIN_LOW, 10, hw::BUTTON_OFF);
|
||||
static hw::Button btn_down = hw::Button(&din3, bsp::DIN_LOW, 10, hw::BUTTON_OFF);
|
||||
|
||||
static hw::Button sw_dimm = hw::Button(&hvdin1, bsp::DIN_HIGH, 10, hw::BUTTON_OFF);
|
||||
static hw::Button sw_brakes = hw::Button(&hvdin2, bsp::DIN_HIGH, 10, hw::BUTTON_OFF);
|
||||
static hw::Button sw_hbrake = hw::Button(&hvdin3, bsp::DIN_LOW, 10, hw::BUTTON_OFF);
|
||||
|
||||
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::Fuse sup_fuse = hw::Fuse(&bat_i);
|
||||
static hw::Fuse out_fuse = hw::Fuse(&dccd_i);
|
||||
|
||||
void devices_init(void);
|
||||
void devices_update_inputs(void);
|
||||
|
||||
#endif /* BSP_BOARD_H_ */
|
||||
@@ -1,6 +1,5 @@
|
||||
/**** Includes ****/
|
||||
#include "../utils/utils.h"
|
||||
#include "../utils/interpolate.h"
|
||||
#include "fuse.h"
|
||||
|
||||
using namespace hw;
|
||||
|
||||
Reference in New Issue
Block a user