This is the multi-page printable view of this section. Click here to print...
System Functions
- 1: millis()
- 2: delay()
- 3: delayMicroseconds()
- 4: random()
1 - millis()
uint32_t millis()
The system time is updated by TickTimer interrupts.
2 - delay()
void delay(uint32_t ms)
Performs a delay for the period specified by ms
.
Time measurement is done using the TickTimer count. When a long delay is specified, the CPU clock is reduced during the polling process.
Every approximately 5 ms after calling delay()
, the internal watchdog process of the TWELITE microcontroller is executed.
※ For example, in the case of while(1) delay(1);
, the delay()
function does not exceed 5 ms, so the watchdog process is not invoked, resulting in a reset after a certain period.
Within the setup()
and wakeup()
functions, since the TickTimer is not yet running, delays are implemented using a while-loop. In this case, the discrepancy from the specified value may be significant. The loop counter is calibrated for 32 MHz. If the CPU clock is altered within these functions, errors proportional to that clock change will occur.
If a short delay such as 1 or 2 ms is specified as a parameter, the error may be relatively large.
3 - delayMicroseconds()
void delayMicroseconds(uint32_t microsec)
Performs a delay for the duration specified by microsec
.
Time measurement is done using the TickTimer count. When a long delay is specified, the CPU clock is reduced during polling.
Within the setup()
and wakeup()
functions, since the TickTimer is not yet running, delays are implemented using a while-loop. In this case, the discrepancy from the specified value may be significant. The loop counter is calibrated for 32 MHz. If the CPU clock is altered within these functions, errors proportional to the clock change will occur.
If a short duration such as 10 microseconds or less is specified as a parameter, the error may be relatively large.
4 - random()
uint32_t random(uint32_t maxval)
uint32_t random(uint32_t minval, uint32_t maxval)
The first function returns a value in the range 0..(maxval-1)
. Note that the value of maxval is not the maximum value itself.
The second function returns a value in the range minval..maxval-1
.