- const int interruptPin = 27; // GPIO pin where the interrupt will be configured //
- bool start_gate=1; //
- uint32_t tik_new,tik_old; //
- uint64_t tik,tik_start; //
- uint64_t time_new,time_old; //
- uint64_t N_int; //
- volatile uint64_t N=0,M=0; //
- //----------------------------------------------------------------------------------------------------//
- void IRAM_ATTR buttonTick() //
- { //
- tik_new = esp_cpu_get_cycle_count(); //
- tik = tik+tik_new-tik_old; //
- if (tik_new<tik_old) tik=tik+4294967296; //
- tik_old=tik_new; //
- N_int=N_int+1; //
- if (start_gate==1 ) {tik_start=tik;N_int=0;start_gate=0; } //
- if ((tik-tik_start)>=240000000) {N=N_int;M=tik-tik_start;start_gate=1;} //
- } //
- //----------------------------------------------------------------------------------------------------//
- void setup() //
- { //
- Serial.begin(115200); //
- pinMode(interruptPin, INPUT); // Configure the pin as an input with an internal pull-up resistor //
- attachInterrupt(interruptPin, buttonTick, RISING); // Configure the interrup //
- } //
- //----------------------------------------------------------------------------------------------------//
- void loop() //
- { //
- time_new = esp_timer_get_time(); //
- if ((time_new-time_old)>=1000000) //
- { //
- Serial.print(" N= ");Serial.print(N);Serial.print(" M= ");Serial.println(M); //
- time_old=time_new; //
- } //
- } //
I am sending a stable signal with a frequency of 10000 Hz from a quartz oscillator. The variable M must be stable and in the range from M=240013970 - 240013971.But the variable M varies over a larger range. I think other interrupts may have a higher priority and calling my interrupt is waiting for the other interrupts to end. Please help me.
N= 10001 M= 240013875
N= 10001 M= 240013848
N= 10001 M= 240014067
N= 10001 M= 240014070
N= 10001 M= 240014229
N= 10001 M= 240014145
N= 10001 M= 240013806
N= 10001 M= 240013839
N= 10001 M= 240014007
N= 10001 M= 240013806
N= 10001 M= 240014157