feat-hal-2 #4

Merged
andis merged 35 commits from feat-hal-2 into develop 2024-07-31 16:15:36 +00:00
7 changed files with 110 additions and 90 deletions
Showing only changes of commit 8bac1f4787 - Show all commits

View File

@@ -16,8 +16,10 @@ board::Hafbridge::Hafbridge(uint8_t hs_pwm_ch, uint8_t ls_gpio_ch, uint8_t max_d
this->pwm_ch = hs_pwm_ch;
this->gpio_ch = ls_gpio_ch;
if(max_dc>100) this->max_dc = 100;
else this->max_dc = max_dc;
if(max_dc>100) max_dc = 100;
this->max_dc = util::percent_to_16b(max_dc);
this->disable();
}
@@ -27,18 +29,22 @@ board::Hafbridge::~Hafbridge(void)
this->disable();
}
void board::Hafbridge::write(uint8_t duty)
void board::Hafbridge::write(uint16_t dividend)
{
// Limit duty
if(duty > this->max_dc) duty = this->max_dc;
this->last_duty = duty;
if(dividend > this->max_dc) dividend = this->max_dc;
this->last_duty = dividend;
if(this->enabled == 0) return;
// Convert percent to 16b duty cycle
uint16_t dc = util::percent_to_16b(duty);
// Set PWM
mcu::pwm_write(this->pwm_ch, dc);
mcu::pwm_write(this->pwm_ch, dividend);
}
void board::Hafbridge::write(uint8_t percent)
{
// Convert to dividend/0xFFFF
this->write(util::percent_to_16b(percent));
}
void board::Hafbridge::enable(void)

View File

@@ -12,15 +12,16 @@ class Hafbridge
protected:
uint8_t pwm_ch;
uint8_t gpio_ch;
uint8_t last_duty;
uint16_t last_duty;
uint8_t enabled;
uint8_t max_dc;
uint16_t max_dc;
public:
Hafbridge(uint8_t hs_pwm_ch, uint8_t ls_gpio_ch, uint8_t max_dc);
~Hafbridge(void);
void write(uint8_t duty);
void write(uint16_t dividend);
void write(uint8_t percent);
void enable(void);
void disable(void);
uint8_t get_set_duty(void);

View File

@@ -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 ****/

View File

@@ -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_ */

View 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 ****/

View 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_ */

View File

@@ -204,10 +204,10 @@
<Compile Include="hw\button.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="hw\cv_driver.cpp">
<Compile Include="hw\cv_otput.cpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="hw\cv_driver.h">
<Compile Include="hw\cv_output.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="hw\display_led.cpp">