Fixed timer, maybe. I have no way to try this
This commit is contained in:
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
#include "esp32-hal-timer.h";
|
#include "esp32-hal-timer.h";
|
||||||
|
|
||||||
#define ESP32_F_CPU 80000000 // the speed of the processor
|
#define ESP32_F_CPU 1000000 // the speed of the processor
|
||||||
#define AUDIO_INTERRUPT_PRESCALER 80
|
#define AUDIO_INTERRUPT_PRESCALER 80
|
||||||
#define SOUND_TIMER_NO 0
|
#define SOUND_TIMER_NO 0
|
||||||
//#define AUDIO_PIN 25
|
//#define AUDIO_PIN 25
|
||||||
@@ -38,7 +38,6 @@ void IRAM_ATTR onSoundTimer()
|
|||||||
if (sound_on) {
|
if (sound_on) {
|
||||||
dacWrite(dac_pin, (sound_wave_high?sound_volume:0));
|
dacWrite(dac_pin, (sound_wave_high?sound_volume:0));
|
||||||
sound_wave_high = ! sound_wave_high;
|
sound_wave_high = ! sound_wave_high;
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
dacWrite(dac_pin, 0);
|
dacWrite(dac_pin, 0);
|
||||||
@@ -50,10 +49,18 @@ void sound_init(int pin){ // pin must be a DAC pin number !! (typically 25 or 2
|
|||||||
pinMode(dac_pin, OUTPUT);
|
pinMode(dac_pin, OUTPUT);
|
||||||
sound_volume = 0;
|
sound_volume = 0;
|
||||||
|
|
||||||
|
#ifdef OLD_CODE
|
||||||
sndTimer = timerBegin(SOUND_TIMER_NO, AUDIO_INTERRUPT_PRESCALER, true);
|
sndTimer = timerBegin(SOUND_TIMER_NO, AUDIO_INTERRUPT_PRESCALER, true);
|
||||||
timerAttachInterrupt(sndTimer, &onSoundTimer, true);
|
timerAttachInterrupt(sndTimer, &onSoundTimer, true);
|
||||||
timerAlarmWrite(sndTimer, ESP32_F_CPU/AUDIO_INTERRUPT_PRESCALER/MIN_FREQ, true); // lower timer freq
|
timerAlarmWrite(sndTimer, ESP32_F_CPU/AUDIO_INTERRUPT_PRESCALER/MIN_FREQ, true); // lower timer freq
|
||||||
timerAlarmEnable(sndTimer);
|
timerAlarmEnable(sndTimer);
|
||||||
|
#else
|
||||||
|
//void RH_INTERRUPT_ATTR esp32_timer_interrupt_handler(); // Forward declaration
|
||||||
|
sndTimer = timerBegin(ESP32_F_CPU);
|
||||||
|
timerAttachInterrupt(sndTimer, &onSoundTimer);
|
||||||
|
timerAlarm(sndTimer, ESP32_F_CPU/AUDIO_INTERRUPT_PRESCALER/MIN_FREQ, true, 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void sound_pause() // this prevents the interrupt from firing ... use during eeprom write
|
void sound_pause() // this prevents the interrupt from firing ... use during eeprom write
|
||||||
@@ -78,14 +85,17 @@ bool sound(uint16_t freq, uint8_t volume){
|
|||||||
}
|
}
|
||||||
sound_on = true;
|
sound_on = true;
|
||||||
sound_volume = volume;
|
sound_volume = volume;
|
||||||
timerAlarmWrite(sndTimer, ESP32_F_CPU/AUDIO_INTERRUPT_PRESCALER/(freq * 2), true);
|
//timerAlarmWrite(sndTimer, ESP32_F_CPU/AUDIO_INTERRUPT_PRESCALER/(freq * 2), true);
|
||||||
|
timerAlarm(sndTimer, ESP32_F_CPU/AUDIO_INTERRUPT_PRESCALER/(freq * 2), true, 0);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void soundOff(){
|
void soundOff(){
|
||||||
sound_on = false;
|
sound_on = false;
|
||||||
sound_volume = 0;
|
sound_volume = 0;
|
||||||
timerAlarmWrite(sndTimer, ESP32_F_CPU/AUDIO_INTERRUPT_PRESCALER/(MIN_FREQ), true); // lower timer freq
|
//timerAlarmWrite(sndTimer, ESP32_F_CPU/AUDIO_INTERRUPT_PRESCALER/(MIN_FREQ), true); // lower timer freq
|
||||||
|
timerAlarm(sndTimer, ESP32_F_CPU/AUDIO_INTERRUPT_PRESCALER/(MIN_FREQ), true, 0);
|
||||||
|
//timerAlarm(hw_timer_t *timer, uint64_t alarm_value, bool autoreload, uint64_t reload_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user