-
Notifications
You must be signed in to change notification settings - Fork 7
clearFlagMilli
gicking edited this page Feb 6, 2018
·
4 revisions
back to Command Reference / Time
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 seetimer4.c
- defined in
timer4.h
- auto-loaded in
main_general.h
- in
config.h
set#define USE_TIM4_UPD_ISR
to enable 1ms interrupt.
clearFlagMilli()
-
input:
- none
-
output:
- none
- Nothing
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;
}
}
}
-
Getting Started
-
- General Commands
- Libraries
- LCD BTHQ21605V
- poti AD5280
- poti AD5282
- freemodbus
- PetitFS SD-card (min)
- FatFS: SD card (full)
- Board Specific
-
- Universal
- Board Specific