From 9d1e54e685476dba757fbf8142c5916881913cb2 Mon Sep 17 00:00:00 2001 From: Voinea Dragos Date: Sun, 30 May 2021 11:48:28 +0300 Subject: [PATCH] Tmc2130 use ShortTimer instead of custom timer implementation --- Firmware/tmc2130.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Firmware/tmc2130.cpp b/Firmware/tmc2130.cpp index 71f2f44fb..66ac59632 100755 --- a/Firmware/tmc2130.cpp +++ b/Firmware/tmc2130.cpp @@ -8,6 +8,7 @@ #include "ultralcd.h" #include "language.h" #include "spi.h" +#include "Timer.h" #define TMC2130_GCONF_NORMAL 0x00000000 // spreadCycle #define TMC2130_GCONF_SGSENS 0x00003180 // spreadCycle with stallguard (stall activates DIAG0 and DIAG1 [pushpull]) @@ -71,6 +72,9 @@ uint16_t tmc2130_sg_cnt[4] = {0, 0, 0, 0}; bool tmc2130_sg_change = false; #endif +//used for triggering a periodic check (1s) of the overtemperature pre-warning flag at ~120C (+-20C) +ShortTimer tmc2130_overtemp_timer; + #define DBG(args...) //printf_P(args) #ifndef _n @@ -392,11 +396,9 @@ bool tmc2130_wait_standstill_xy(int timeout) return standstill; } - void tmc2130_check_overtemp() { - static uint32_t checktime = 0; - if (_millis() - checktime > 1000 ) + if (tmc2130_overtemp_timer.expired(1000) || !tmc2130_overtemp_timer.running()) { for (uint_least8_t i = 0; i < 4; i++) { @@ -412,7 +414,7 @@ void tmc2130_check_overtemp() } } - checktime = _millis(); + tmc2130_overtemp_timer.start(); #ifdef DEBUG_CRASHDET_COUNTERS tmc2130_sg_change = true; #endif