Hi guys;
I worked on due a little and I am very new to Arduino community. I manage to build pulse counter or frequency reader whatever you say, however 32 b?t counter is not enough for what I want. I thought I can get some overflow flag when the counter reaches to 4294967296 (2^32) therefore I get a carry and ? can count pulses more than 4294967296.
The problem is I cannot manage to do some overflow interrupt. Here is my code so far :
#include <DueTimer.h>
#define TC_CHANNEL_0 0
#define TC_CHANNEL_1 1
#define TC_CHANNEL_2 2
#define PIN_TC0_TCLK0_ARD (22u)
volatile long unsigned int data[1000];
word i = 0;
void setup(){
pinMode(PIN_TC0_TCLK2_ARD,INPUT);
pmc_enable_periph_clk(ID_TC0);
Serial.begin(9600);
TC_Configure(TC0, TC_CHANNEL_2, TC_CMR_TCCLKS_XC0);
TC_Start(TC0, TC_CHANNEL_2);
Timer4.attachInterrupt(myHandler);
Timer4.start(1000000);
NVIC_EnableIRQ(TC0_IRQn);
}
void loop() {
}
void myHandler ()
{
data[i]= TC_ReadCV(TC0,TC_CHANNEL_2);
//REG_TC0_BCR = 0x1;
//if (i == 0){
Serial.print(i), Serial.print(" "), Serial.println(data[i]);
}
else{
Serial.print(i), Serial.print(" "), Serial.println(data[i] - data[i-1]);
}
i++;
}
GitHub - ivanseidel/DueTimer: ⏳ Timer Library fully implemented for Arduino DUE this is the link for library. however i used that to get more accurate delay. Just for your information.
So how could i do it? Any suggestions...
Thanks in advance.