User Tools

Site Tools


en-us_commands:reference:itimerstate

This is an old revision of the document!


ItimerState()

ItimerState() returns the running state of the default or specified callback timer.

ItimerState command operation flow

bool ItimerState()
bool ItimerState(uint8_t timerNumber)

Commands

Command Arguments Return Value Operation
ItimerState() None bool Returns the running state of the default or specified callback timer.

Example

const uint8_t CALLBACK_TIMER = 3;
volatile bool sampleDue = false;
 
void sampleTask() {
  sampleDue = true;
}
 
void setup() {
  Serial.begin(115200);
  if (!ItimerSet(CALLBACK_TIMER, 100, sampleTask)) {  // Set the interval and callback function, or select the hardware timer to use.
    Serial.println(F("timer setup failed"));
    return;
  }
  ItimerStart(CALLBACK_TIMER);  // Start the configured callback timer.
}
 
void loop() {
  if (sampleDue) {
    noInterrupts();
    sampleDue = false;
    interrupts();
    Serial.println(analogRead(A0));  // Read the raw analog value of the specified channel.
  }
 
  const bool pause = IdigitalRead(0, 5);  // Read the input repeatedly and update only if all samples match. If HIGH and LOW are mixed, retain the previous stable state.
  if (pause && ItimerState(CALLBACK_TIMER)) ItimerStop(CALLBACK_TIMER);  // Return the running state of the default or specified callback timer. / Stop the default or specified callback timer.
  if (!pause && !ItimerState(CALLBACK_TIMER)) ItimerStart(CALLBACK_TIMER);  // Start the configured callback timer. / Return the running state of the default or specified callback timer.
  if (IdigitalRead(1, 5)) ItimerStopAll();  // Stop all running callback timers. / Read the input repeatedly and update only if all samples match. If HIGH and LOW are mixed, retain the previous stable state.
}

Precautions

  • Timer interrupt callbacks run inside an ISR. For safety, change only flags in the callback and perform actual control processing in loop().
  • Do not use slow or interrupt-dependent code such as delay(), Serial, I2C or SPI in callbacks.
  • 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().
  • Do not use the default ItimerSet() together with tone() using Timer2 or analogWrite() on Timer2 PWM pins.
  • Explicitly using Timer1, Timer3, 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

en-us_commands/reference/itimerstate.1788796403.txt.gz · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki