Determine frequency of a square wave

HI Guys,

I'm trying to determine the frequency of a square wave (in the range 1Hz to about 2kHz) using an Arduino Due.

I have been searching for a few days now and still not managed to get anywhere really. I'm not a software or hardware guy at all really (fluid mechanical guy here) so all help is appreciated!

I have managed to get the rising edge of the wave to trigger an interupt, but I'm at a loss what to do now...

What i would like to do is be able to do is determine the frequency of the square wave and write it out to the serial monitor for now. This is all i have that works...

const byte ledPin = 13;
const byte interruptPin = 10;


void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(interruptPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(interruptPin), RiseEdge, RISING);

  
  Serial.begin(9600);  //open serial port at 9600 Baud
}


void loop() {

//Not sure what to do here

}

void RiseEdge() {

  // Or here....
 
  }

Hello

Maybe the code below could work (I didn't try):

const byte interruptPin = 10;

volatile uint32_t t=0;
void setup() {
  
  pinMode(interruptPin, INPUT);
  attachInterrupt(digitalPinToInterrupt(interruptPin), RisingEdge, RISING);

  Serial.begin(9600);  
}


void loop() {

Serial.print("Frequency = "); Serial.print((1/t)*1000000); Serial.println(" Hz");
delay (1000);
}

void RisingEdge() {
static uint32_t temp;
  
  t = micros() - temp;
  temp = micros();
  }

Thanks for the reply. With a little more googling I discovered tc_lib which uses the hardware timers to measure both duty and period which gives me what i want.

I just thought i would reply with that here for future reference if anyone is looking.