change setPwm function in FOCDriver to accept 3 args, with a default value for the 3rd Change stepper driver classes to use 3 arg setPwm, ignoring 3rd arg. created InlineCurrentSenseSync class in lib/currentsense. fixed timer bug in calibrate encoder, in main defined a label for serialusb, to make it easier to swap out.
76 lines
2.5 KiB
C++
76 lines
2.5 KiB
C++
#ifndef INLINE_CS_SYNC_LIB_H
|
|
#define INLINE_CS_SYNC_LIB_H
|
|
|
|
#include "Arduino.h"
|
|
#include "SimpleFOC.h"
|
|
#include "common/foc_utils.h"
|
|
#include "common/time_utils.h"
|
|
#include "common/defaults.h"
|
|
#include "common/base_classes/CurrentSense.h"
|
|
#include "common/lowpass_filter.h"
|
|
// #include "current_sense/hardware_api.h"
|
|
#include "utils.h"
|
|
|
|
|
|
class InlineCurrentSenseSync: public CurrentSense{
|
|
public:
|
|
/**
|
|
InlineCurrentSense class constructor
|
|
@param shunt_resistor shunt resistor value
|
|
@param gain current-sense op-amp gain
|
|
@param phA A phase adc pin
|
|
@param phB B phase adc pin
|
|
@param phC C phase adc pin (optional)
|
|
*/
|
|
InlineCurrentSenseSync(float shunt_resistor, float gain, int pinA, int pinB, int pinC = NOT_SET);
|
|
/**
|
|
InlineCurrentSense class constructor
|
|
@param mVpA mV per Amp ratio
|
|
@param phA A phase adc pin
|
|
@param phB B phase adc pin
|
|
@param phC C phase adc pin (optional)
|
|
*/
|
|
InlineCurrentSenseSync(float mVpA, int pinA, int pinB, int pinC = NOT_SET);
|
|
|
|
// CurrentSense interface implementing functions
|
|
int init() override;
|
|
PhaseCurrent_s getPhaseCurrents() override;
|
|
int driverAlign(float align_voltage) override;
|
|
|
|
// ADC measuremnet gain for each phase
|
|
// support for different gains for different phases of more commonly - inverted phase currents
|
|
// this should be automated later
|
|
float gain_a; //!< phase A gain
|
|
float gain_b; //!< phase B gain
|
|
float gain_c; //!< phase C gain
|
|
|
|
// // per phase low pass fileters
|
|
// LowPassFilter lpf_a{DEF_LPF_PER_PHASE_CURRENT_SENSE_Tf}; //!< current A low pass filter
|
|
// LowPassFilter lpf_b{DEF_LPF_PER_PHASE_CURRENT_SENSE_Tf}; //!< current B low pass filter
|
|
// LowPassFilter lpf_c{DEF_LPF_PER_PHASE_CURRENT_SENSE_Tf}; //!< current C low pass filter
|
|
|
|
float offset_ia; //!< zero current A voltage value (center of the adc reading)
|
|
float offset_ib; //!< zero current B voltage value (center of the adc reading)
|
|
float offset_ic; //!< zero current C voltage value (center of the adc reading)
|
|
|
|
private:
|
|
|
|
// hardware variables
|
|
int pinA; //!< pin A analog pin for current measurement
|
|
int pinB; //!< pin B analog pin for current measurement
|
|
int pinC; //!< pin C analog pin for current measurement
|
|
|
|
// gain variables
|
|
float shunt_resistor; //!< Shunt resistor value
|
|
float amp_gain; //!< amp gain value
|
|
float volts_to_amps_ratio; //!< Volts to amps ratio
|
|
|
|
/**
|
|
* Function finding zero offsets of the ADC
|
|
*/
|
|
void calibrateOffsets();
|
|
|
|
};
|
|
|
|
#endif
|