Average rainfall 2001-2016, global tropics

Map: Average rainfall 2001-2016, global tropics

spectrolum: Digital write

Introduction

the Arduino command Digital write is comparatively slow and cause variations in the spectral scans by e.g. the Hamamatsu sensor. Nay read or write command are also affected by interrupts - code that has precedence over the sequential code execution.

Handling interrupts

To prevent any interrupts during the scanning and reading data for any spectral sensor, add the command

noInterrupts();

// critical, time-sensitive sensor operations here

interrupts();

Optimizing digitalWrite

the Arduino command digitalWrite performs a range of tasks before actually changing the state of an I/O pin:

  1. Check if the pin exist, and if not, return.
  2. Check if there is a PWM running for this pin. If yes, it will stop the PWM.
  3. Find the bit mask for the pin.
  4. Find the port associated to the pin number.
  5. Check the current pin’s state, and change the state accordingly.

This causes the process of switching state for an I/O pin to take several micro-seconds. A code for testing the speed of ditialWrite is published by The Robotics Back-End.

The ideal solution to speed up the switching of states is to find the microprocessor machine code for that and tweak your script to use a single call to the machine for switching.

Alternatively the Arduino code can be changed and other libraries used for swithing. Again see the article by The Robotics Back-End. For AVR boards you can use the library digitalwritefast.

https://forum.seeedstudio.com/t/fast-digital-write-on-xiao-nrf52840/265945