Hello all,
I am trying to read some pulses of GPIO34 which is input pin for may application and when I use serial print, I am getting some errors like the name of this topic.
[Codebox]int FC_PIN = 34; // Pin for frequency measurement
void Get_Cycle_Length(void* arrow) {
for (;;) {
volatile int64_t start_time, end_time, cycle_duration;
float frequency = 0.0;
noInterrupts();
// Wait for the signal to go LOW (start of cycle)
while (digitalRead(FC_PIN) != LOW) { }
// Wait for the LOW phase to end (HIGH phase begins)
while (digitalRead(FC_PIN) == LOW) { }
// Capture start time at the beginning of the HIGH phase
start_time = esp_timer_get_time();
// Wait for the HIGH phase to end
while (digitalRead(FC_PIN) == HIGH) { }
// Wait for the LOW phase to end again (completing one full cycle)
while (digitalRead(FC_PIN) == LOW) { }
// Capture end time at the beginning of the next HIGH phase
end_time = esp_timer_get_time();
// Calculate cycle duration in microseconds
cycle_duration = end_time - start_time;
interrupts();
// Calculate frequency in Hz (1,000,000 microseconds = 1 second)
if (cycle_duration > 0) {
frequency = 1000000.0 / cycle_duration;
}
// Print the frequency on the Serial monitor
Serial.print("Frequency: ");
Serial.print(frequency, 2); // Display frequency with 2 decimal places
Serial.println(" Hz");
delay(50); // Update every 500ms
}
}
void setup() {
// Initialize serial communication
Serial.begin(115200);
// Setup the pin for input
pinMode(FC_PIN, INPUT);
// Allow system to stabilize
delay(10);
// Create a FreeRTOS task for frequency measurement
xTaskCreate(Get_Cycle_Length, "Cycle_Length", 8192, NULL, 4, NULL);
}
void loop() {
// Nothing in loop, task handles everything
}
[/Codebox]
Anyone some Ideas how to fix this?
Thanks!
Guru Meditation Error: Core 1 panic'ed
-
- Posts: 1734
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: Guru Meditation Error: Core 1 panic'ed
You could share the full error message you see.
You also should at least add some delay to loop() to yield the CPU.
You should also look into using interrupts to detect changes on the input pin instead of polling, and you should generally avoid keeping interrupts disabled while waiting for something.
You also should at least add some delay to loop() to yield the CPU.
You should also look into using interrupts to detect changes on the input pin instead of polling, and you should generally avoid keeping interrupts disabled while waiting for something.
Who is online
Users browsing this forum: No registered users and 62 guests