First step of unifying different ports connected to one bus. At a later step, also the load and charger classes should inherit from PowerPort class to make overall charge controller structure more clean.
66 lines
1.6 KiB
C++
66 lines
1.6 KiB
C++
/*
|
|
* Copyright (c) 2018 Martin Jäger / Libre Solar
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#ifndef PWM_SWITCH_H
|
|
#define PWM_SWITCH_H
|
|
|
|
/** @file
|
|
*
|
|
* @brief PWM charger MOSFET switch control functions
|
|
*/
|
|
|
|
#include <stdbool.h>
|
|
#include <time.h>
|
|
|
|
#include "power_port.h"
|
|
|
|
/** PWM charger type
|
|
*
|
|
* Contains all data belonging to the PWM switching sub-component.
|
|
*/
|
|
class PwmSwitch : public PowerPort
|
|
{
|
|
public:
|
|
PwmSwitch(DcBus *dc_bus);
|
|
|
|
/** Main control function for the PWM switching algorithm
|
|
*/
|
|
void control();
|
|
|
|
/** Fast emergency stop function
|
|
*
|
|
* May be called from an ISR which detected overvoltage / overcurrent conditions
|
|
*/
|
|
void emergency_stop();
|
|
|
|
/** Read the general on/off status of PWM switching
|
|
*
|
|
* @returns true if on
|
|
*/
|
|
bool active();
|
|
|
|
/** Read the current high or low state of the PWM signal
|
|
*
|
|
* @returns true if high, false if low
|
|
*/
|
|
bool signal_high();
|
|
|
|
/** Read the currently set duty cycle
|
|
*
|
|
* @returns Duty cycle between 0.0 and 1.0
|
|
*/
|
|
float get_duty_cycle();
|
|
|
|
float ext_voltage; ///< Voltage measurement at terminal (external)
|
|
|
|
bool enable; ///< Can be used to disable the PWM power stage
|
|
float offset_voltage_start; ///< Offset voltage of solar panel vs. battery to start charging (V)
|
|
int restart_interval; ///< Interval to wait before retrying charging after low solar power cut-off (s)
|
|
time_t off_timestamp; ///< Time when charger was switched off last time
|
|
};
|
|
|
|
#endif /* PWM_SWITCH_H */
|