Arduino time reset missing?

I was trying to reset the timer using the arduino platform but I can’t find the
time_reset()
function.
In wiring.h:

unsigned long millis(void);
void delay(unsigned long);
void delayMicroseconds(unsigned int us);

the only dirty solution I found is to include in the library OrangutanTIme and remove the quoted functions to avoid linking conflicts.
Nevertheless using the AVR compiler is working:

#include <math.h>
#include <pololu/OrangutanLCD.h>
#include <pololu/OrangutanPushbuttons.h>
#include <pololu/OrangutanTime.h>

/*
 * Filter benchmark
 *
 * https://www.pololu.com/docs/0J17/5.c
 * https://www.pololu.com
 * https://forum.pololu.com
 */
  int N=2;
  float buffer[2]={0.0,0.0};
  float a[2]={0.5,0.5};

OrangutanLCD lcd;
OrangutanPushbuttons buttons;

float filter(float x, float hist[],float a[],float N) {
int i;
float sum = 0;
hist[0] = x; //history of samples
for(i=N-1;i>=0;i--)
{
sum = sum + hist[i]*a[i];
if(i != 0)
{
hist[i] = hist[i-1];
}
}
return sum;
}


void setup()                    // run once, when the sketch starts
{
    lcd.clear();
    lcd.print("Setup done!");
}

int main()                     // run over and over again
{
  setup();
  buttons.waitForPress(TOP_BUTTON);
  OrangutanTime::reset();
  //time_reset();
  
  float output=0.0;
  lcd.clear();
  for(float input=0.0;input<100.0;input=input+10.0)
  {
     output=filter(input, buffer,a,N);
  }
  lcd.print("Filtering done");
  delay(100);
  lcd.clear();
  lcd.print(millis());
  return 0;

}

I’m basically testing the code for an FIR filter.

Hello.

I believe that’s because the Arduino platform doesn’t provide the ability to reset the timer. You should avoid using OrangutanTime functions from the Arduino environment because they work differently from the Arduino timing functions. Because of this, the timer_reset() function in OrangutanTime won’t have any effect on the time returned by the Arduino millis() function. Instead of using OrangutanTime, you should write your own timer_reset() function as follows:

// these globals are declared in wiring.c
extern volatile unsigned long timer0_clock_cycles;
extern volatile unsigned long timer0_millis;

void timer_reset()
{
  unsigned char oldSREG = SREG;  // store status register
  cli();  // disable interrupts
  timer0_clock_cycles = 0;  // clear the global variables that track elapsed time
  timer0_millis = 0;
  SREG = oldSREG;  // re-enable interrupts if they were enabled to begin with
}

I haven’t tested it, but it should work.

- Ben