Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add MT6701 I2C sensor configuration #398

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/current_sense/hardware_specific/teensy/teensy4_mcu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// - Teensy 4.1
#if defined(__arm__) && defined(CORE_TEENSY) && ( defined(__IMXRT1062__) || defined(ARDUINO_TEENSY40) || defined(ARDUINO_TEENSY41) || defined(ARDUINO_TEENSY_MICROMOD) )

// #define TEENSY4_ADC_INTERRUPT_DEBUG
// #define SIMPLEFOC_TEENSY4_ADC_INTERRUPT_DEBUG


volatile uint32_t val0, val1, val2;
Expand All @@ -28,7 +28,7 @@ void read_currents(uint32_t *a, uint32_t*b, uint32_t *c=nullptr){
// interrupt service routine for the ADC_ETC0
// reading the ADC values and clearing the interrupt
void adcetc0_isr() {
#ifdef TEENSY4_ADC_INTERRUPT_DEBUG
#ifdef SIMPLEFOC_TEENSY4_ADC_INTERRUPT_DEBUG
digitalWrite(30,HIGH);
#endif
// page 3509 , section 66.5.1.3.3
Expand All @@ -37,21 +37,21 @@ void adcetc0_isr() {
val0 = (ADC_ETC_TRIG0_RESULT_1_0 & 4095);
// val1 = lp2((ADC_ETC_TRIG0_RESULT_1_0 >> 16) & 4095);
val1 = (ADC_ETC_TRIG0_RESULT_1_0 >> 16) & 4095;
#ifdef TEENSY4_ADC_INTERRUPT_DEBUG
#ifdef SIMPLEFOC_TEENSY4_ADC_INTERRUPT_DEBUG
digitalWrite(30,LOW);
#endif
}


void adcetc1_isr() {
#ifdef TEENSY4_ADC_INTERRUPT_DEBUG
#ifdef SIMPLEFOC_TEENSY4_ADC_INTERRUPT_DEBUG
digitalWrite(30,HIGH);
#endif
// page 3509 , section 66.5.1.3.3
ADC_ETC_DONE0_1_IRQ |= 1 << 16; // clear Done1 for trg0 at 16th bit
val2 = ADC_ETC_TRIG0_RESULT_3_2 & 4095;
// val2 = lp3( ADC_ETC_TRIG0_RESULT_3_2 & 4095);
#ifdef TEENSY4_ADC_INTERRUPT_DEBUG
#ifdef SIMPLEFOC_TEENSY4_ADC_INTERRUPT_DEBUG
digitalWrite(30,LOW);
#endif
}
Expand Down Expand Up @@ -167,7 +167,7 @@ void* _configureADCLowSide(const void* driver_params, const int pinA,const int p

SIMPLEFOC_DEBUG("TEENSY-CS: Configuring low side current sense!");

#ifdef TEENSY4_ADC_INTERRUPT_DEBUG
#ifdef SIMPLEFOC_TEENSY4_ADC_INTERRUPT_DEBUG
pinMode(30,OUTPUT);
#endif

Expand Down Expand Up @@ -228,7 +228,7 @@ void _driverSyncLowSide(void* driver_params, void* cs_params){
// flexpwm->SM[submodule].VAL4 = int(flexpwm->SM[submodule].VAL1*(1.0f - 2.5e-6*par->pwm_frequency)) ; // 2.5us before center


#ifdef TEENSY4_ADC_INTERRUPT_DEBUG
#ifdef SIMPLEFOC_TEENSY4_ADC_INTERRUPT_DEBUG
// pin 4 observes out trigger line for 'scope
xbar_connect (xbar_trig_pwm, XBARA1_OUT_IOMUX_XBAR_INOUT08) ;
IOMUXC_GPR_GPR6 |= IOMUXC_GPR_GPR6_IOMUXC_XBAR_DIR_SEL_8 ; // select output mode for INOUT8
Expand All @@ -241,4 +241,4 @@ void _driverSyncLowSide(void* driver_params, void* cs_params){
}


#endif
#endif
6 changes: 3 additions & 3 deletions src/drivers/hardware_specific/teensy/teensy4_mcu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#pragma message("SimpleFOC: compiling for Teensy 4.x")
#pragma message("")

// #define TEENSY4_FORCE_CENTER_ALIGNED_3PWM
// #define SIMPLEFOC_TEENSY4_FORCE_CENTER_ALIGNED_3PWM


// function finding the TRIG event given the flexpwm timer and the submodule
Expand Down Expand Up @@ -569,7 +569,7 @@ void write_pwm_on_pin(IMXRT_FLEXPWM_t *p, unsigned int submodule, uint8_t channe
p->MCTRL |= FLEXPWM_MCTRL_LDOK(mask);
}

#ifdef TEENSY4_FORCE_CENTER_ALIGNED_3PWM
#ifdef SIMPLEFOC_TEENSY4_FORCE_CENTER_ALIGNED_3PWM

// function setting the high pwm frequency to the supplied pins
// - BLDC motor - 3PWM setting
Expand Down Expand Up @@ -663,4 +663,4 @@ void _writeCenterAligned3PMW(float dc_a, float dc_b, float dc_c, void* params){

#endif

#endif
#endif
10 changes: 10 additions & 0 deletions src/sensors/MagneticSensorI2C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ MagneticSensorI2CConfig_s AS5048_I2C = {
.data_start_bit = 15
};

/** Typical configuration for the 12bit MT6701 magnetic sensor over I2C interface */
MagneticSensorI2CConfig_s MT6701_I2C = {
.chip_address = 0x06,
.bit_resolution = 14,
.angle_register = 0x03,
.data_start_bit = 15
};


// MagneticSensorI2C(uint8_t _chip_address, float _cpr, uint8_t _angle_register_msb)
// @param _chip_address I2C chip address
Expand All @@ -34,6 +42,7 @@ MagneticSensorI2C::MagneticSensorI2C(uint8_t _chip_address, int _bit_resolution,
// LSB and MSB register used bits
// AS5600 uses 0..7 LSB and 8..11 MSB
// AS5048 uses 0..5 LSB and 6..13 MSB
// MT6701 uses 0..5 LSB and 6..13 MSB
// used bits in LSB
lsb_used = _bit_resolution - _bits_used_msb;
// extraction masks
Expand Down Expand Up @@ -111,6 +120,7 @@ int MagneticSensorI2C::read(uint8_t angle_reg_msb) {
// LSB and MSB register used bits
// AS5600 uses 0..7 LSB and 8..11 MSB
// AS5048 uses 0..5 LSB and 6..13 MSB
// MT6701 uses 0..5 LSB and 6..13 MSB
readValue = ( readArray[1] & lsb_mask );
readValue += ( ( readArray[0] & msb_mask ) << lsb_used );
return readValue;
Expand Down
Loading