Go Down

Topic: Is built-in "heartbeat" for all Arduino boards feasible? (Read 63 times) previous topic - next topic

dlloyd

I think it would be a handy feature (as default or option) to have the board's LED indicate the performance of the main loop.

For example, if after erase, the LED defaults to 10Hz oscillation or so (iteration count to be based upon detected board), then as the user develops and tests their code it would slow down. Allow the user to adjust iteration count to suit their needs.

Of course, right now the user could add this manually.

For example, on the Arduino Due, this "clean" sketch oscillates the LED at somewhere over 10Hz:

Code: (HEARTBEAT) [Select]
unsigned long iteration;

void setup() {
  pinMode(13, OUTPUT);
}

void loop() {
  digitalWrite(13, ((iteration += 1) % 10000) > 5000);
}

robtillaart

you could add a counter in the timer overflow interrupt of the micros() timekeeping.
and after a zillion (to be determined) interrupts it toggles the led by means of direct port manipulation.

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

pYro_65

Your method is simple enough to add, why not pump out a header file people can include or add as a library which allows setting these things. Here is what I would do:

Beat.h:
Code: [Select]

#include "Arduino.h"

#ifndef ITERATIONS
  #define ITERATIONS 10000
#endif

#ifndef BEAT_PIN
  #define BEAT_PIN 13
#endif

int main(){
  static unsigned long iteration = 0;
 
  #if defined( USBCON )
    USBDevice.attach();
  #endif
   
  init();
  setup();
  pinMode( BEAT_PIN, OUTPUT );
  while( true ){
     digitalWrite( BEAT_PIN, ((iteration += 1) % ITERATIONS ) > ( ITERATIONS / 2 ) );
     loop();
  }
  return 0;
}


And it just gets included.
Code: [Select]
#include "Beat.h"

void setup() { }

void loop() { }


And for 10x speed we can override the values:
Code: [Select]
#define ITERATIONS 1000   //default of 10000
#include "Beat.h"

void setup() { }

void loop() { }


I would aim to use port manipulation though to minimize overhead. And maybe some logic to only toggle if the pin will actually change state.

Go Up