Finished const voltage output
This commit is contained in:
@@ -1,40 +0,0 @@
|
||||
/**** Includes ****/
|
||||
#include "../utils/utils.h"
|
||||
#include "cv_driver.h"
|
||||
|
||||
using namespace hw;
|
||||
|
||||
/**** Private definitions ****/
|
||||
/**** Private constants ****/
|
||||
/**** Private variables ****/
|
||||
/**** Private function declarations ****/
|
||||
|
||||
/**** Public function definitions ****/
|
||||
hw::CVdriver::CVdriver(board::AnalogIn* sup_voltage, board::AnalogIn* out_voltage, board::Hafbridge* hbridge)
|
||||
{
|
||||
this->sup_voltage = sup_voltage;
|
||||
this->hbridge = hbridge;
|
||||
this->target = 0;
|
||||
this->off = 1;
|
||||
}
|
||||
|
||||
hw::CVdriver::~CVdriver(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void hw::CVdriver::update(void)
|
||||
{
|
||||
// Update all inputs
|
||||
this->sup_voltage->read();
|
||||
|
||||
// Calculate ratio
|
||||
uint16_t ratio = util::sat_ratio(this->target, this->sup_voltage->last_read);
|
||||
|
||||
// Set output
|
||||
this->hbridge->write(ratio);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**** Private function definitions ****/
|
||||
@@ -1,37 +0,0 @@
|
||||
#ifndef CONST_VOLTAGE_DRIVER_H_
|
||||
#define CONST_VOLTAGE_DRIVER_H_
|
||||
|
||||
/**** Includes ****/
|
||||
#include <stdint.h>
|
||||
#include "../board/ain.h"
|
||||
#include "../board/halfbridge.h"
|
||||
|
||||
namespace hw {
|
||||
|
||||
/**** Public definitions ****/
|
||||
|
||||
class CVdriver
|
||||
{
|
||||
protected:
|
||||
board::AnalogIn* sup_voltage;
|
||||
|
||||
board::Hafbridge* hbridge;
|
||||
|
||||
public:
|
||||
CVdriver(board::AnalogIn* sup_voltage, board::Hafbridge* hbridge);
|
||||
~CVdriver(void);
|
||||
|
||||
uint16_t target = 0;
|
||||
uint8_t off = 0;
|
||||
|
||||
void process(void);
|
||||
};
|
||||
|
||||
/**** Public function declarations ****/
|
||||
|
||||
#ifdef TESTING
|
||||
#endif
|
||||
|
||||
} //namespace
|
||||
|
||||
#endif /* CONST_VOLTAGE_DRIVER_H_ */
|
||||
52
firmware/src/hw/cv_otput.cpp
Normal file
52
firmware/src/hw/cv_otput.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
/**** Includes ****/
|
||||
#include "../utils/utils.h"
|
||||
#include "cv_output.h"
|
||||
|
||||
using namespace hw;
|
||||
|
||||
/**** Private definitions ****/
|
||||
/**** Private constants ****/
|
||||
/**** Private variables ****/
|
||||
/**** Private function declarations ****/
|
||||
|
||||
/**** Public function definitions ****/
|
||||
hw::CVoutput::CVoutput(board::Hafbridge* hbridge)
|
||||
{
|
||||
this->hbridge = hbridge;
|
||||
this->target = 0;
|
||||
this->min_out = 0;
|
||||
this->hbridge->disable();
|
||||
}
|
||||
|
||||
hw::CVoutput::~CVoutput(void)
|
||||
{
|
||||
this->hbridge->write((uint16_t)0);
|
||||
this->hbridge->disable();
|
||||
return;
|
||||
}
|
||||
|
||||
void hw::CVoutput::update(uint16_t supply_mv)
|
||||
{
|
||||
// Check target
|
||||
if((this->target < this->min_out)&&(this->target > 0)) this->target = this->min_out;
|
||||
|
||||
// Set output
|
||||
this->hbridge->write(util::sat_ratio(this->target, supply_mv));
|
||||
}
|
||||
|
||||
void hw::CVoutput::enable(void)
|
||||
{
|
||||
this->hbridge->enable();
|
||||
}
|
||||
|
||||
void hw::CVoutput::disable(void)
|
||||
{
|
||||
this->hbridge->disable();
|
||||
}
|
||||
|
||||
uint8_t hw::CVoutput::is_enabled(void)
|
||||
{
|
||||
return this->hbridge->is_enabled();
|
||||
}
|
||||
|
||||
/**** Private function definitions ****/
|
||||
38
firmware/src/hw/cv_output.h
Normal file
38
firmware/src/hw/cv_output.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#ifndef CONST_VOLTAGE_OUTPUT_H_
|
||||
#define CONST_VOLTAGE_OUTPUT_H_
|
||||
|
||||
/**** Includes ****/
|
||||
#include <stdint.h>
|
||||
#include "../board/ain.h"
|
||||
#include "../board/halfbridge.h"
|
||||
|
||||
namespace hw {
|
||||
|
||||
/**** Public definitions ****/
|
||||
|
||||
class CVoutput
|
||||
{
|
||||
protected:
|
||||
board::Hafbridge* hbridge;
|
||||
|
||||
public:
|
||||
CVoutput(board::Hafbridge* hbridge);
|
||||
~CVoutput(void);
|
||||
|
||||
uint16_t target;
|
||||
uint16_t min_out;
|
||||
|
||||
void update(uint16_t supply_mv);
|
||||
void enable(void);
|
||||
void disable(void);
|
||||
uint8_t is_enabled(void);
|
||||
};
|
||||
|
||||
/**** Public function declarations ****/
|
||||
|
||||
#ifdef TESTING
|
||||
#endif
|
||||
|
||||
} //namespace
|
||||
|
||||
#endif /* CONST_VOLTAGE_OUTPUT_H_ */
|
||||
Reference in New Issue
Block a user