Comparing the current output with the last one

hello every one
i want to compare two outputs from interrupt but when i save the last one in a parameter " f " the current one "Tx " stop changing and "m" won't increase.

#include "tc_lib.h"

using namespace arduino_due;

#define CAPTURE_TIME_WINDOW 2500000 // usecs
#define ANALOG_PIN 7
#define ANALOG_VALUE 127 // values in the interval [0,255] 

auto& capture_pin2=capture_tc0;
volatile float Tx = 0 ;

volatile float f = 0 ;

volatile float t = 0 ;
volatile int m = 0 ;

void setup() {

attachInterrupt(digitalPinToInterrupt(2), measure , LOW );


 void measure (){
  uint32_t status,duty,period;

 t = (static_cast<double>(duty)/static_cast<double>(capture_pin2.ticks_per_usec()) );
  if ( (t > 1400) && (t < 1600))
{  Tx = t ;}

void loop() {

if (Tx - f > 1)
 f = Tx;


this is the interrupt output and i want to count the number of spikes


any little help would be greatly appreciated in advance.

What happens if you declare duty and period as static global variables instead of declaring them within the ISR ?

this error is shown while i wanted to compile :

exit status 1
no matching function for call to 'arduino_due::tc_lib::capture<(arduino_due::tc_lib::timer_ids)0u>::get_duty_and_period(volatile uint32_t&, volatile uint32_t&)'

Hi @hatam_mn

Why are Tx, f and t defined as a float?
What happens if I use long?

RV mineirin

Look at this link the part of " variables "
They are defined perfectly

The question is why are they floats ?

Because i want to capture the time of event that they have some digit after point like 1508.437 . i'm in favor of increasing the precision of measuring so i need to define them in to a float variables.
By the way i have found the solution and it was so easy and infront of my eyes and it was the line i defined the "f = Tx".
It must be out of brackets of if .

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.