Condensed my code to the following however the issue still remains:
unsigned long period = 100000;
float area = 0.0092; // Sensing area of TSL25R device, in cm2
volatile unsigned long pulses = 0;
unsigned long lastPulseCount = 0;
unsigned long lastPulseOutputTime = 0;
void irq1()
{
pulses++;
}
///////////////////////////////////////////////////////////////////
//
// SETUP
//
void setup()
{
Serial.begin(115200);
Serial.println("START");
pinMode(2, INPUT);
digitalWrite(2, HIGH);
attachInterrupt(0, irq1, RISING);
}
///////////////////////////////////////////////////////////////////
//
// MAIN LOOP
//
void loop()
{
unsigned long elapsedTimeSincePulseCheck = micros() - lastPulseOutputTime;
if (elapsedTimeSincePulseCheck >= period)
{
lastPulseOutputTime = micros();
noInterrupts();
unsigned long pulsesCopy = pulses;
interrupts();
unsigned long frequency = (pulsesCopy- lastPulseCount) * (1000000 / elapsedTimeSincePulseCheck);
long irradiance = frequency / area; // Calculate Irradiance (uW/cm2)
Serial.println(frequency);
lastPulseCount = pulsesCopy;
}
}