User Tools

Site Tools


en-us_commands:reference:itimerstart

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
en-us_commands:reference:itimerstart [2026/09/08 00:53] – 바깥 편집 127.0.0.1en-us_commands:reference:itimerstart [2026/09/12 22:54] (current) – 바깥 편집 127.0.0.1
Line 15: Line 15:
  
 ===== Example ===== ===== Example =====
 +
 +This uses the default callback timer (Timer2). The callback changes only a flag; serial output runs in ''loop()''.
  
 <code cpp> <code cpp>
Line 24: Line 26:
  
 void setup() { void setup() {
-  pinMode(13, OUTPUT); +  Serial.begin(115200); 
-  ItimerSet(1000, onTimer);  // Set the interval and callback function, or select the hardware timer to use+  if (!ItimerSet(1000, onTimer)) return;  // Configure the callback and interval first
-  ItimerStart();  // Start the configured callback timer.+  if (!ItimerStart()) return;  // Start the configured default callback timer.
 } }
  
 void loop() { void loop() {
   if (tick) {   if (tick) {
 +    noInterrupts();
     tick = false;     tick = false;
-    digitalWrite(13, !digitalRead(13));+    interrupts(); 
 +    Serial.println(F("tick"));
   }   }
 } }
Line 39: Line 43:
 ===== Precautions ===== ===== Precautions =====
  
-  * Timer interrupt callbacks run inside an ISRFor safety, change only flags in the callback and perform actual control processing in ''loop()''+  * The callback runs in an interrupt. Change only a flag there; do not call ''delay()'', ''Serial'', I2C or SPI in it
-  * Do not use slow or interrupt-dependent code such as ''delay()'', ''Serial'', I2C or SPI in callbacks+  * The callback timer without a timer number uses Timer2. Do not use it together with ''tone()'' or PWM output that uses Timer2. 
-  * Normally, call ''ImodbusRTU()'' repeatedly in ''loop()''. Call it from a timer interrupt with a sufficient interval only when long ''delay()'' calls or debug output slow down ''loop()''. +  * When specifying another hardware timercheck for conflicts with PWM, analog output and high-speed counter functions using it
-  * Do not use the default ''ItimerSet()'' together with ''tone()'' using Timer2 or ''analogWrite()'' on Timer2 PWM pins+  * Starting before ''ItimerSet()'' has configured the timer returns false.
-  * Explicitly using Timer1Timer3, Timer4 or Timer5 may conflict with PWM, analog output or high-speed counter functions using that timer+
-  * Configure only one ''Itimer'' callback per hardware timer. +
-  * Defining an ISR for the same timer directly in the sketch may conflict with ''Itimer'' operation. +
-  * ''ItimerStopAll()'' stops only hardware interrupt timers. It does not reset PLC-style timer states such as ''Iton'', ''Itof'' or ''Itmr''.+
  
 ===== Built-in Commands in the Same Category ===== ===== Built-in Commands in the Same Category =====
en-us_commands/reference/itimerstart.1788796403.txt.gz · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki