@@ -49,10 +49,6 @@ ClassIdentifier TMC4671::info = {
4949TMC4671 ::TMC4671 (SPIPort& spiport,OutputPin cspin,uint8_t address) :CommandHandler(" tmc" , CLSID_MOT_TMC0 ), SPIDevice{motor_spi,cspin},Thread(" TMC" , TMC_THREAD_MEM , TMC_THREAD_PRIO ){
5050 setAddress (address);
5151 setInstance (address-1 );
52- // this->cspin = SPI1_SS1_Pin;
53- // this->csport = SPI1_SS1_GPIO_Port;
54- // this->spi = &HSPIDRV;
55-
5652 spiConfig.peripheral .Mode = SPI_MODE_MASTER ;
5753 spiConfig.peripheral .Direction = SPI_DIRECTION_2LINES ;
5854 spiConfig.peripheral .DataSize = SPI_DATASIZE_8BIT ;
@@ -233,23 +229,22 @@ bool TMC4671::initialize(){
233229 return false ;
234230 }
235231 // brake res failsafe.
236- /*
237- * Single ended input raw value
238- * 0V = 0x7fff
239- * 4.7k / (360k+4.7k) Divider on old board.
240- * 1.5k / (71.5k+1.5k) 16.121 counts 60V new. 100V VM => 2V
241- * 13106 counts/V input.
242- */
243- if (oldTMCdetected){
244- setBrakeLimits (52400 ,52800 );
245- }else {
246- setBrakeLimits (50700 ,50900 ); // Activates around 60V as last resort failsave. Check offsets from tmc leakage. ~ 1.426V
247- }
232+ // /*
233+ // * Single ended input raw value
234+ // * 0V = 0x7fff
235+ // * 4.7k / (360k+4.7k) Divider on old board.
236+ // * 1.5k / (71.5k+1.5k) 16.121 counts 60V new. 100V VM => 2V
237+ // * 13106 counts/V input.
238+ // */
239+ setBrakeLimits (this ->conf .hwconf .brakeLimLow ,this ->conf .hwconf .brakeLimHigh ); // update limit from previously loaded constants or defaults
248240
249241 // Status mask
250242 if (oldTMCdetected){
251243 setStatusMask (0 ); // ES Version status output is broken
252244 }else {
245+ /*
246+ * Enable adc clipping and pll errors
247+ */
253248 statusMask.asInt = 0 ;
254249 statusMask.flags .adc_i_clipped = 1 ;
255250 statusMask.flags .not_PLL_locked = 1 ;
@@ -319,9 +314,10 @@ void TMC4671::Run(){
319314 if (tick - lastStatTime > 2000 ){ // Every 2s
320315 lastStatTime = tick;
321316 statusCheck ();
322- // Get enable input
323- bool tmc_en = (readReg (0x76 ) >> 15 ) & 0x01 ;
324- if (!tmc_en && active){ // Hardware emergency. If tmc does not reply the enable will still read false
317+ // Get enable input. If tmc does not reply the result will read 0 or 0xffffffff (not possible normally)
318+ uint32_t pins = readReg (0x76 );
319+ bool tmc_en = ((pins >> 15 ) & 0x01 ) && pins != 0xffffffff ;
320+ if (!tmc_en && active){ // Hardware emergency.
325321 this ->estopTriggered = true ;
326322 this ->emergencyStop ();
327323 changeState (TMC_ControlState::HardError);
@@ -1834,9 +1830,10 @@ void TMC4671::setHwType(TMC_HW_Ver type){
18341830 .temperatureEnabled = true ,
18351831 .temp_limit = 90 ,
18361832 .currentScaler = 2.5 / (0x7fff * 0.1 ), // w. TMCS1100A2 sensor 100mV/A
1833+ .brakeLimLow = 50700 ,
1834+ .brakeLimHigh = 50900 ,
18371835 };
18381836 this ->conf .hwconf = newHwConf;
1839- setBrakeLimits (50700 ,50900 );
18401837 break ;
18411838 }
18421839 case TMC_HW_Ver::v1_2_1_LEM20:
@@ -1851,9 +1848,10 @@ void TMC4671::setHwType(TMC_HW_Ver type){
18511848 .temperatureEnabled = true ,
18521849 .temp_limit = 90 ,
18531850 .currentScaler = 2.5 / (0x7fff * 0.04 ), // w. LEM 20 sensor 40mV/A
1851+ .brakeLimLow = 50700 ,
1852+ .brakeLimHigh = 50900
18541853 };
18551854 this ->conf .hwconf = newHwConf;
1856- setBrakeLimits (50700 ,50900 );
18571855 break ;
18581856 }
18591857 case TMC_HW_Ver::v1_2_1:
@@ -1868,9 +1866,10 @@ void TMC4671::setHwType(TMC_HW_Ver type){
18681866 .temperatureEnabled = true ,
18691867 .temp_limit = 90 ,
18701868 .currentScaler = 2.5 / (0x7fff * 0.08 ), // w. LEM 10 sensor 80mV/A
1869+ .brakeLimLow = 50700 ,
1870+ .brakeLimHigh = 50900 ,
18711871 };
18721872 this ->conf .hwconf = newHwConf;
1873- setBrakeLimits (50700 ,50900 );
18741873 break ;
18751874 }
18761875
@@ -1885,10 +1884,11 @@ void TMC4671::setHwType(TMC_HW_Ver type){
18851884 .temperatureEnabled = true ,
18861885 .temp_limit = 90 ,
18871886 .currentScaler = 2.5 / (0x7fff * 60.0 * 0.0015 ), // w. 60x 1.5mOhm sensor
1887+ .brakeLimLow = 50700 ,
1888+ .brakeLimHigh = 50900 ,
18881889 };
18891890 this ->conf .hwconf = newHwConf;
1890- setBrakeLimits (50700 ,50900 ); // Activates around 60V as last resort failsave. Check offsets from tmc leakage. ~ 1.426V
1891-
1891+ // Activates around 60V as last resort failsave. Check offsets from tmc leakage. ~ 1.426V
18921892 break ;
18931893 }
18941894
@@ -1904,9 +1904,11 @@ void TMC4671::setHwType(TMC_HW_Ver type){
19041904 .temperatureEnabled = false ,
19051905 .temp_limit = 90 ,
19061906 .currentScaler = 2.5 / (0x7fff * 60.0 * 0.0015 ), // w. 60x 1.5mOhm sensor
1907+ .brakeLimLow = 52400 ,
1908+ .brakeLimHigh = 52800 ,
19071909 };
19081910 this ->conf .hwconf = newHwConf;
1909- setBrakeLimits ( 52400 , 52800 );
1911+
19101912 break ;
19111913 }
19121914
@@ -1922,6 +1924,7 @@ void TMC4671::setHwType(TMC_HW_Ver type){
19221924 break ;
19231925 }
19241926 }
1927+ setBrakeLimits (this ->conf .hwconf .brakeLimLow ,this ->conf .hwconf .brakeLimHigh );
19251928}
19261929
19271930void TMC4671::registerCommands (){
0 commit comments