Videos
Hello,
I am working on a project in IDF with FreeRTOS. Among all the tasks, the project has one task that needs to run every day at midnight (00:00 UTC). To do this, I have an external RTC with which I calculate how many seconds are left until midnight (I have verified that the calculation is correct). From there, I convert it to milliseconds and calculate the number of ticks to wait using pdMS_TO_TICKS(), passing this tick number to vTaskDelay(). However, the task runs much earlier. Does anyone know why this might be? The Tick rate (Hz) is 1000.
On the other hand, I have verified that when I convert X milliseconds to ticks using pdMS_TO_TICKS() and then calculate how many milliseconds those ticks are with pdTICKS_TO_MS(), the milliseconds value does not match the initial one. Does anyone know why this might be? Here's an example:
43200 seconds to milliseconds: 43200000 43200 seconds to ticks: 250327 43200000 milliseconds to ticks: 250327 250327 ticks to milliseconds: 250327
Thank you very much in advance.
Hi guys,
I'm trying to implement something that will generate two triggers at regular intervals where the two triggers are separated by a configurable delay. The delay has to be configurable to sub microsecond resolution. Ideally, 500ns or less.
I chose the ESP32 because of its 240MHz clock, but it still seems to be having trouble.
I'm messing around with the following code:
#define cyclespermicro 240
#define microcycles(n) (n*cyclespermicro)
uint32_t startCounter, counter, cpu_cycles;
int cyclediff, totalcycles, corrected;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
startCounter = ESP.getCycleCount();
totalcycles = startCounter + microcycles(2);
//delayMicroseconds(1);
while (ESP.getCycleCount() < totalcycles) {
__asm__ __volatile__ ("nop");
}
counter = ESP.getCycleCount();
cpu_cycles = counter - startCounter;
corrected = cpu_cycles - 262;
Serial.print("StartCounter: ");
Serial.print(startCounter);
Serial.print(" counter: ");
Serial.print(counter);
Serial.print(" cpu_cycles: ");
Serial.print(cpu_cycles);
Serial.print(" corrected: ");
Serial.println(corrected);
}
void loop() {
}The problem is that I get the same number of clock cycles for 1 us as I do for 2 us. I'm guessing this is because the while loop overhead is overwhelming the 1 us delay.
The problem is I need to have the amount of delay configurable and I don't know the best way to do this. Anyone have any ideas how to efficiently create configurable sub-microsecond delays?
EDIT: I am also noticing, when I get rid of the while loop entirely, and just straight up copy in NOP lines, it works as expected for like 3 NOPs, but once I hit 5 NOPS, the overhead jumps to like 500 cycles. What is going on here?
Do I have to write instructions in assembly? Im using Arduino IDE and im trying to sample a signal at 44.1khz. I come from a PIC Micro background where I would just use a TMR. Whats the play here in Arduino Land?