User Tools

Site Tools


en-us_commands:reference:itimerset

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en-us_commands:reference:itimerset [2026/09/07 23:35] – 바깥 편집 127.0.0.1en-us_commands:reference:itimerset [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 a 1 s callback on the default hardware timer.
   ItimerStart();  // Start the configured callback timer.   ItimerStart();  // Start the configured callback timer.
 } }
Line 31: Line 33:
 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+  * A zero interval or missing callback makes configuration fail and return 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+===== Built-in Commands in the Same Category ===== 
-  * 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''.+  * [[:en-us_commands:reference:itimerstart|ItimerStart() View detailed description]] 
 +  * [[:en-us_commands:reference:itimerstop|ItimerStop() View detailed description]] 
 +  * [[:en-us_commands:reference:itimerstopall|ItimerStopAll() View detailed description]] 
 +  * [[:en-us_commands:reference:itimerstate|ItimerState() View detailed description]]
  
 [[:en-us_commands:builtin|← Built-in Command List]] [[:en-us_commands:builtin|← Built-in Command List]]
  
en-us_commands/reference/itimerset.1788791735.txt.gz · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki