Browse Source

Init pwm_thrs to 0 when HYBRID_THRESHOLD is off (#21623)

Scott Lahteine 3 years ago
parent
commit
253ee0c407
No account linked to committer's email address
2 changed files with 29 additions and 23 deletions
  1. 22
    13
      Marlin/src/feature/tmc_util.h
  2. 7
    10
      Marlin/src/module/stepper/trinamic.cpp

+ 22
- 13
Marlin/src/feature/tmc_util.h View File

120
       uint32_t get_pwm_thrs() {
120
       uint32_t get_pwm_thrs() {
121
         return _tmc_thrs(this->microsteps(), this->TPWMTHRS(), planner.settings.axis_steps_per_mm[AXIS_ID]);
121
         return _tmc_thrs(this->microsteps(), this->TPWMTHRS(), planner.settings.axis_steps_per_mm[AXIS_ID]);
122
       }
122
       }
123
-      void set_pwm_thrs(const uint32_t thrs) {
124
-        TMC::TPWMTHRS(_tmc_thrs(this->microsteps(), thrs, planner.settings.axis_steps_per_mm[AXIS_ID]));
125
-        TERN_(HAS_LCD_MENU, this->stored.hybrid_thrs = thrs);
126
-      }
127
     #endif
123
     #endif
128
 
124
 
125
+    void set_pwm_thrs(const uint32_t thrs) {
126
+      TMC::TPWMTHRS(_tmc_thrs(this->microsteps(), thrs, planner.settings.axis_steps_per_mm[AXIS_ID]));
127
+      #if BOTH(HYBRID_THRESHOLD, HAS_LCD_MENU)
128
+        this->stored.hybrid_thrs = thrs;
129
+      #endif
130
+    }
131
+
129
     #if USE_SENSORLESS
132
     #if USE_SENSORLESS
130
       inline int16_t homing_threshold() { return TMC::sgt(); }
133
       inline int16_t homing_threshold() { return TMC::sgt(); }
131
       void homing_threshold(int16_t sgt_val) {
134
       void homing_threshold(int16_t sgt_val) {
185
       inline bool toggle_stepping_mode()           { set_stealthChop(!this->stored.stealthChop_enabled); return get_stealthChop(); }
188
       inline bool toggle_stepping_mode()           { set_stealthChop(!this->stored.stealthChop_enabled); return get_stealthChop(); }
186
     #endif
189
     #endif
187
 
190
 
191
+    void set_pwm_thrs(const uint32_t thrs) {
192
+      TMC2208Stepper::TPWMTHRS(_tmc_thrs(this->microsteps(), thrs, planner.settings.axis_steps_per_mm[AXIS_ID]));
193
+      #if BOTH(HYBRID_THRESHOLD, HAS_LCD_MENU)
194
+        this->stored.hybrid_thrs = thrs;
195
+      #endif
196
+    }
197
+
188
     #if ENABLED(HYBRID_THRESHOLD)
198
     #if ENABLED(HYBRID_THRESHOLD)
189
       uint32_t get_pwm_thrs() {
199
       uint32_t get_pwm_thrs() {
190
         return _tmc_thrs(this->microsteps(), this->TPWMTHRS(), planner.settings.axis_steps_per_mm[AXIS_ID]);
200
         return _tmc_thrs(this->microsteps(), this->TPWMTHRS(), planner.settings.axis_steps_per_mm[AXIS_ID]);
191
       }
201
       }
192
-      void set_pwm_thrs(const uint32_t thrs) {
193
-        TMC2208Stepper::TPWMTHRS(_tmc_thrs(this->microsteps(), thrs, planner.settings.axis_steps_per_mm[AXIS_ID]));
194
-        TERN_(HAS_LCD_MENU, this->stored.hybrid_thrs = thrs);
195
-      }
196
     #endif
202
     #endif
197
 
203
 
198
     #if HAS_LCD_MENU
204
     #if HAS_LCD_MENU
199
       inline void refresh_stepper_current() { rms_current(this->val_mA); }
205
       inline void refresh_stepper_current() { rms_current(this->val_mA); }
200
-
201
       #if ENABLED(HYBRID_THRESHOLD)
206
       #if ENABLED(HYBRID_THRESHOLD)
202
         inline void refresh_hybrid_thrs() { set_pwm_thrs(this->stored.hybrid_thrs); }
207
         inline void refresh_hybrid_thrs() { set_pwm_thrs(this->stored.hybrid_thrs); }
203
       #endif
208
       #endif
237
       uint32_t get_pwm_thrs() {
242
       uint32_t get_pwm_thrs() {
238
         return _tmc_thrs(this->microsteps(), this->TPWMTHRS(), planner.settings.axis_steps_per_mm[AXIS_ID]);
243
         return _tmc_thrs(this->microsteps(), this->TPWMTHRS(), planner.settings.axis_steps_per_mm[AXIS_ID]);
239
       }
244
       }
240
-      void set_pwm_thrs(const uint32_t thrs) {
241
-        TMC2209Stepper::TPWMTHRS(_tmc_thrs(this->microsteps(), thrs, planner.settings.axis_steps_per_mm[AXIS_ID]));
242
-        TERN_(HAS_LCD_MENU, this->stored.hybrid_thrs = thrs);
243
-      }
244
     #endif
245
     #endif
246
+
247
+    void set_pwm_thrs(const uint32_t thrs) {
248
+      TMC2209Stepper::TPWMTHRS(_tmc_thrs(this->microsteps(), thrs, planner.settings.axis_steps_per_mm[AXIS_ID]));
249
+      #if BOTH(HYBRID_THRESHOLD, HAS_LCD_MENU)
250
+        this->stored.hybrid_thrs = thrs;
251
+      #endif
252
+    }
253
+
245
     #if USE_SENSORLESS
254
     #if USE_SENSORLESS
246
       inline int16_t homing_threshold() { return TMC2209Stepper::SGTHRS(); }
255
       inline int16_t homing_threshold() { return TMC2209Stepper::SGTHRS(); }
247
       void homing_threshold(int16_t sgt_val) {
256
       void homing_threshold(int16_t sgt_val) {

+ 7
- 10
Marlin/src/module/stepper/trinamic.cpp View File

158
     pwmconf.pwm_ampl = 180;
158
     pwmconf.pwm_ampl = 180;
159
     st.PWMCONF(pwmconf.sr);
159
     st.PWMCONF(pwmconf.sr);
160
 
160
 
161
-    TERN(HYBRID_THRESHOLD, st.set_pwm_thrs(hyb_thrs), UNUSED(hyb_thrs));
161
+    st.set_pwm_thrs(TERN0(HYBRID_THRESHOLD, hyb_thrs)); UNUSED(hyb_thrs);
162
 
162
 
163
     st.GSTAT(); // Clear GSTAT
163
     st.GSTAT(); // Clear GSTAT
164
   }
164
   }
196
     pwmconf.pwm_ofs = 36;
196
     pwmconf.pwm_ofs = 36;
197
     st.PWMCONF(pwmconf.sr);
197
     st.PWMCONF(pwmconf.sr);
198
 
198
 
199
-    TERN(HYBRID_THRESHOLD, st.set_pwm_thrs(hyb_thrs), UNUSED(hyb_thrs));
199
+    st.set_pwm_thrs(TERN0(HYBRID_THRESHOLD, hyb_thrs)); UNUSED(hyb_thrs);
200
 
200
 
201
     st.GSTAT(); // Clear GSTAT
201
     st.GSTAT(); // Clear GSTAT
202
   }
202
   }
517
     pwmconf.pwm_ofs = 36;
517
     pwmconf.pwm_ofs = 36;
518
     st.PWMCONF(pwmconf.sr);
518
     st.PWMCONF(pwmconf.sr);
519
 
519
 
520
-    TERN(HYBRID_THRESHOLD, st.set_pwm_thrs(hyb_thrs), UNUSED(hyb_thrs));
520
+    st.set_pwm_thrs(TERN0(HYBRID_THRESHOLD, hyb_thrs)); UNUSED(hyb_thrs);
521
 
521
 
522
     st.GSTAT(0b111); // Clear
522
     st.GSTAT(0b111); // Clear
523
     delay(200);
523
     delay(200);
559
     pwmconf.pwm_ofs = 36;
559
     pwmconf.pwm_ofs = 36;
560
     st.PWMCONF(pwmconf.sr);
560
     st.PWMCONF(pwmconf.sr);
561
 
561
 
562
-    TERN(HYBRID_THRESHOLD, st.set_pwm_thrs(hyb_thrs), UNUSED(hyb_thrs));
562
+    st.set_pwm_thrs(TERN0(HYBRID_THRESHOLD, hyb_thrs)); UNUSED(hyb_thrs);
563
 
563
 
564
     st.GSTAT(0b111); // Clear
564
     st.GSTAT(0b111); // Clear
565
     delay(200);
565
     delay(200);
617
     pwmconf.pwm_ampl = 180;
617
     pwmconf.pwm_ampl = 180;
618
     st.PWMCONF(pwmconf.sr);
618
     st.PWMCONF(pwmconf.sr);
619
 
619
 
620
-    TERN(HYBRID_THRESHOLD, st.set_pwm_thrs(hyb_thrs), UNUSED(hyb_thrs));
620
+    st.set_pwm_thrs(TERN0(HYBRID_THRESHOLD, hyb_thrs)); UNUSED(hyb_thrs);
621
 
621
 
622
     st.GSTAT(); // Clear GSTAT
622
     st.GSTAT(); // Clear GSTAT
623
   }
623
   }
655
     pwmconf.pwm_ofs = 36;
655
     pwmconf.pwm_ofs = 36;
656
     st.PWMCONF(pwmconf.sr);
656
     st.PWMCONF(pwmconf.sr);
657
 
657
 
658
-    #if ENABLED(HYBRID_THRESHOLD)
659
-      st.set_pwm_thrs(hyb_thrs);
660
-    #else
661
-      UNUSED(hyb_thrs);
662
-    #endif
658
+    st.set_pwm_thrs(TERN0(HYBRID_THRESHOLD, hyb_thrs)); UNUSED(hyb_thrs);
659
+
663
     st.GSTAT(); // Clear GSTAT
660
     st.GSTAT(); // Clear GSTAT
664
   }
661
   }
665
 #endif // TMC5160
662
 #endif // TMC5160

Loading…
Cancel
Save