Skip to content

clearFlagMilli

gicking edited this page Feb 6, 2018 · 4 revisions

back to Command Reference / Time

Description

Resets the 1ms flag for checking via flagMilli(). The flag is set in the TIM4 update ISR, checked by flagMilli(), and cleared by calling clearFlagMilli(). in your code.

This function reduces the CPU load for scheduled tasks based e.g. on millis(), see below. Basically it skips the scheduler based on a 8-bit flag, instead of computing 32-bit numbers.

Notes:

  • clearFlagMilli() is based on the 1ms clock, and requires the TIM4 interrupt to be active. For implementation see timer4.c

Inclusion

  • defined in timer4.h
  • auto-loaded in main_general.h
  • in config.h set #define USE_TIM4_UPD_ISR to enable 1ms interrupt.

Syntax

clearFlagMilli()

Parameters

  • input:

    • none
  • output:

    • none

Returns

  • Nothing

Example Code

The below code toggles pin PD0 every 500ms (non-blocking).

#include "main_general.h"
#include "timeout.h"

void setup() {
  pinMode(&PORT_D, 0, OUTPUT);
}

void loop() {
  if (flagMilli()) {          // every 1ms
    clearFlagMilli();
    if ((millis()%500) != 0) {  // every 500ms
      clearFlagMilli()
      pinOutputReg(&PORT_D, pin0) ^= 1;
    }
  }
}

Relevant Tutorial

See also

Clone this wiki locally