Code: Select all
int j;
for (j = 0; j < 26000; j++ ) {
dacWrite(25, sample[j]);
}
Code: Select all
int j;
for (j = 0; j < 26000; j++ ) {
dacWrite(25, sample[j]);
}
Code: Select all
const unsigned char sample[] = {
// here a lot of numbers - audio data
};
hw_timer_t * timer = NULL;
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
volatile uint32_t isrCounter = 0;
volatile uint32_t lastIsrAt = 0;
void IRAM_ATTR onTimer(){
// Increment the counter and set the time of ISR
portENTER_CRITICAL_ISR(&timerMux);
isrCounter++;
lastIsrAt = millis();
portEXIT_CRITICAL_ISR(&timerMux);
// It is safe to use digitalRead/Write here if you want to toggle an output
if (isrCounter > 25000) { // hardcoded end...
if (timer) {
// Stop and free timer
timerEnd(timer);
timer = NULL;
}
}
dacWrite(25, sample[isrCounter]);
}
void setup() {
// Use 1st timer of 4 (counted from zero).
// Set 80 divider for prescaler (see ESP32 Technical Reference Manual for more
// info).
timer = timerBegin(0, 80, true);
// Attach onTimer function to our timer.
timerAttachInterrupt(timer, &onTimer, true);
// Set alarm to call onTimer function every second (value in microseconds).
// Repeat the alarm (third parameter)
timerAlarmWrite(timer, 125, true);
// Start an alarm
timerAlarmEnable(timer);
}
void loop() {
}
Users browsing this forum: No registered users and 55 guests