Translate

Showing posts with label double precision. Show all posts
Showing posts with label double precision. Show all posts

Wednesday, February 19, 2025

Arduino floating point test

 

How to choose the Arduino MCU for fast and double precision data processing

Giovanni Carrera, 19/02/2025

In my case I had to convert in real time the coordinates of a GNSS RTK receiver from degrees and minutes to degrees with at least 7-8 decimal places to have a resolution lower than a centimeter. So it was necessary to use double precision calculations. To do this I initially used an Arduino Due board with a program developed with Arduino IDE. Then I used other 32-bit MCUs because the 8-bit ones accept double precision but do the calculations in single. I also discarded the development in MicroPython because, at the moment, it uses single precision.

I then wrote the following program and, with minor modifications (serial UART), ran it on several 32-bit MCUs. All of the ones listed here gave identical results, but with very different execution times.

The program is as follows:

/* program doubletest.ino

 test double precision of MCU

 Giovanni Carrera, 14/10/2019*/

 

const String Lats = "4221.0081996";

const String Longs = "01321.4740622";

 

void setup(void) {

  Serial.begin(115200);

     while (!Serial) {

    ; // wait for serial port to connect

  }

  delay(100);

  Serial.println("MCU double precision test");

  // convert Lat&Long in decimal format

  unsigned long  ti= micros();

  String minuts = Lats.substring(2);// latitude minutes

  double minutes = minuts.toFloat();// convert it to float

  double decdeg = minutes/60.0;

  String Latdegs = Lats.substring(0,2);

  double Latd = Latdegs.toFloat() + decdeg;// latitude in decimal format (double)

  minuts = Longs.substring(3);// longitude minutes

  minutes = minuts.toFloat();// convert it to float

  decdeg = minutes/60.0;

  String Longdegs = Longs.substring(0,3);

  double Longd = Longdegs.toFloat() + decdeg;// longitude in decimal format (double)

  unsigned long  tf= micros();

  Serial.print("Latitude (dec)  = ");

  Serial.println(Latd,8);

  Serial.print("Longitude (dec) = ");

  Serial.println(Longd,8);

  Serial.print("elaboration time [us] = ");

  Serial.println(tf-ti);

} // end of setup

void loop() {

}

The following table summarizes the results of my tests.

board

MCU

CPU clock [MHz]

time [µs]

Teensy 4.0

ARM Cortex-M7

600

5

STM32F401CC

ARM®Cortex®-M4

84

102

Arduino Due

Atmel SAM3X8E ARM Cortex-M3

84

141

ESP32 WROOM

Xtensa single-/dual-core 32-bit LX6

240

152

STM32F103C8T6

ARM Cortex-M3

72

157

Arduino Uno R4

ARM Cortex-M4

48

184

Arduino Zero

ATSAMD21G18

48

250

Wemos D1 mini

ESP8266EX, Tensilica L106

80

388

The graphic representation of the figure shows the differences better.