Skip to content

Commit

Permalink
add some checks to current-sense init
Browse files Browse the repository at this point in the history
  • Loading branch information
runger1101001 committed Sep 12, 2023
1 parent 7677c85 commit 5ef4d9d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/current_sense/GenericCurrentSense.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ int GenericCurrentSense::driverAlign(float voltage){
int exit_flag = 1;
if(skip_align) return exit_flag;

if (!initialized) return 0;

// // set phase A active and phases B and C down
// driver->setPwm(voltage, 0, 0);
// _delay(200);
Expand Down
8 changes: 8 additions & 0 deletions src/current_sense/InlineCurrentSense.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "InlineCurrentSense.h"
#include "communication/SimpleFOCDebug.h"
// InlineCurrentSensor constructor
// - shunt_resistor - shunt resistor value
// - gain - current-sense op-amp gain
Expand Down Expand Up @@ -93,6 +94,13 @@ int InlineCurrentSense::driverAlign(float voltage){
int exit_flag = 1;
if(skip_align) return exit_flag;

if (driver==nullptr) {
SIMPLEFOC_DEBUG("CUR: No driver linked!");
return 0;
}

if (!initialized) return 0;

if(_isset(pinA)){
// set phase A active and phases B and C down
driver->setPwm(voltage, 0, 0);
Expand Down
11 changes: 10 additions & 1 deletion src/current_sense/LowsideCurrentSense.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "LowsideCurrentSense.h"
#include "communication/SimpleFOCDebug.h"
// LowsideCurrentSensor constructor
// - shunt_resistor - shunt resistor value
// - gain - current-sense op-amp gain
Expand Down Expand Up @@ -35,6 +36,12 @@ LowsideCurrentSense::LowsideCurrentSense(float _mVpA, int _pinA, int _pinB, int

// Lowside sensor init function
int LowsideCurrentSense::init(){

if (driver==nullptr) {
SIMPLEFOC_DEBUG("CUR: Driver not linked!");
return 0;
}

// configure ADC variables
params = _configureADCLowSide(driver->params,pinA,pinB,pinC);
// if init failed return fail
Expand Down Expand Up @@ -89,10 +96,12 @@ PhaseCurrent_s LowsideCurrentSense::getPhaseCurrents(){
// 3 - success but gains inverted
// 4 - success but pins reconfigured and gains inverted
int LowsideCurrentSense::driverAlign(float voltage){

int exit_flag = 1;
if(skip_align) return exit_flag;

if (!initialized) return 0;

if(_isset(pinA)){
// set phase A active and phases B and C down
driver->setPwm(voltage, 0, 0);
Expand Down

0 comments on commit 5ef4d9d

Please sign in to comment.