-
Notifications
You must be signed in to change notification settings - Fork 7
sw_delay
back to Command Reference / Time
Pauses the program for the amount of time (in milliseconds) specified as parameter. There are 1000 milliseconds in a second.
Notes:
-
sw_delay()
uses loops andNOP
s (in contrast todelay()
). It therefore does not require the TIM4 interrupt to be active. - since
sw_delay()
does not use the 1ms interrupt, it becomes inaccurate if a high interrupt load is present
- defined in
sw_delay.h
- auto-loaded in
main_general.h
- no
#define
required
sw_delay(ms)
-
input:
- ms: the number of milliseconds to pause (unsigned long)
-
output:
- none
- Nothing
The below code toggles pin PD0 every 500ms.
#include "main_general.h"
void setup() {
pinMode(&PORT_D, 0, OUTPUT);
}
void loop() {
pinOutputReg(&PORT_D, pin0) ^= 1;
sw_delay(500);
}
- tbd
While it is easy to create a blinking LED with the sw_delay()
function, and many sketches use short delays for
such tasks as switch debouncing, the use of sw_delay()
in a sketch has significant drawbacks. No other reading
of sensors, mathematical calculations, or pin manipulation can go on during the delay function, so in effect,
it brings most other activity to a halt. For alternative approaches to controlling timing see the millis()
or setTimeout() functions. More knowledgeable programmers usually avoid the use of sw_delay()
for timing of events longer than 10’s of milliseconds unless the sketch is very simple.
Certain things do go on while the sw_delay()
function is controlling the STM8 however, namely interrupt handling and
automatic hardware functions. For example, interrupt-diven serial communication and timer-based PWM output are
maintained. However, at high interrupt load, sw_delay()
becomes inaccurate.
-
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