Skip to content

Commit 94f4fb5

Browse files
committed
added support for center aligned 3pwm at least for one motor + low-side current sensing
1 parent 0588d38 commit 94f4fb5

File tree

6 files changed

+896
-61
lines changed

6 files changed

+896
-61
lines changed

src/current_sense/hardware_specific/teensy/teensy4_mcu.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "../../../drivers/hardware_specific/teensy/teensy4_mcu.h"
33
// #include "../../../common/lowpass_filter.h"
44
#include "../../../common/foc_utils.h"
5+
#include "../../../communication/SimpleFOCDebug.h"
56

67
// if defined
78
// - Teensy 4.0
@@ -158,7 +159,13 @@ float _readADCVoltageLowSide(const int pinA, const void* cs_params){
158159
// Configure low side for generic mcu
159160
// cannot do much but
160161
void* _configureADCLowSide(const void* driver_params, const int pinA,const int pinB,const int pinC){
161-
_UNUSED(driver_params);
162+
Teensy4DriverParams* par = (Teensy4DriverParams*) ((TeensyDriverParams*)driver_params)->additional_params;
163+
if(par == nullptr){
164+
SIMPLEFOC_DEBUG("TEENSY-CS: Low side current sense failed, driver not supported!");
165+
return SIMPLEFOC_CURRENT_SENSE_INIT_FAILED;
166+
}
167+
168+
SIMPLEFOC_DEBUG("TEENSY-CS: Configuring low side current sense!");
162169

163170
#ifdef TEENSY4_ADC_INTERRUPT_DEBUG
164171
pinMode(30,OUTPUT);
@@ -191,10 +198,15 @@ void* _configureADCLowSide(const void* driver_params, const int pinA,const int p
191198

192199
// sync driver and the adc
193200
void _driverSyncLowSide(void* driver_params, void* cs_params){
194-
Teensy4DriverParams* par = (Teensy4DriverParams*) driver_params;
201+
Teensy4DriverParams* par = (Teensy4DriverParams*) ((TeensyDriverParams*)driver_params)->additional_params;
195202
IMXRT_FLEXPWM_t* flexpwm = par->flextimers[0];
196203
int submodule = par->submodules[0];
197204

205+
SIMPLEFOC_DEBUG("TEENSY-CS: Syncing low side current sense!");
206+
char buff[50];
207+
sprintf(buff, "TEENSY-CS: Syncing to FlexPWM: %d, Submodule: %d", flexpwm_to_index(flexpwm), submodule);
208+
SIMPLEFOC_DEBUG(buff);
209+
198210
// find the xbar trigger for the flexpwm
199211
int xbar_trig_pwm = flexpwm_submodule_to_trig(flexpwm, submodule);
200212
if(xbar_trig_pwm<0) return;

0 commit comments

Comments
 (0)