debugging

This commit is contained in:
Jorj Bauer 2020-07-12 11:08:46 -04:00
parent 33886eef49
commit 816c38209c
3 changed files with 19 additions and 19 deletions

View File

@ -83,8 +83,8 @@ void TeensySpeaker::maintainSpeaker()
togmutex.unlock(); togmutex.unlock();
// Now we can safely update the DAC based on the current toggleState // Now we can safely update the DAC based on the current toggleState
uint16_t v = (toggleState ? 0xFFF : 0x000); // uint16_t v = (toggleState ? 0xFFF : 0x000);
dac.write((uint8_t) ((v >> 8) & 0xFF), (uint8_t) (v & 0xFF), true); // dac.write((uint8_t) ((v >> 8) & 0xFF), (uint8_t) (v & 0xFF), true);
} }

View File

@ -4,7 +4,7 @@
#include "physicalspeaker.h" #include "physicalspeaker.h"
#include <MCP492X.h> #include <MCP492X.h>
#define SAMPLERATE 4000 #define SAMPLERATE 8000
class TeensySpeaker : public PhysicalSpeaker { class TeensySpeaker : public PhysicalSpeaker {
public: public:

View File

@ -164,6 +164,7 @@ void setup()
Serial.flush(); Serial.flush();
threads.setMicroTimer(); // use a 100uS timer instead of a 1mS timer threads.setMicroTimer(); // use a 100uS timer instead of a 1mS timer
// threads.setSliceMicros(5);
threads.addThread(runDebouncer); threads.addThread(runDebouncer);
} }
@ -225,32 +226,31 @@ void biosInterrupt()
g_keyboard->maintainKeyboard(); g_keyboard->maintainKeyboard();
} }
uint32_t spk_nextResetMillis = 0;
uint32_t spk_refreshCount = 0;
uint32_t spk_microsAtStart = micros();
uint32_t spk_microsForNext = 0;
void runSpeaker() void runSpeaker()
{ {
static uint32_t nextResetMillis = 0;
static uint32_t refreshCount = 0;
static uint32_t microsAtStart = micros();
static uint32_t microsForNext = 0;
if (1) { if (1) {
if (micros() >= microsForNext) { if (micros() >= spk_microsForNext) {
refreshCount++; spk_refreshCount++;
microsForNext = microsAtStart + ((1000000*refreshCount)/SAMPLERATE); spk_microsForNext = spk_microsAtStart + ((1000000*spk_refreshCount)/SAMPLERATE);
// ((TeensySpeaker *)g_speaker)->maintainSpeaker(); ((TeensySpeaker *)g_speaker)->maintainSpeaker();
} }
if (millis() >= nextResetMillis) { if (millis() >= spk_nextResetMillis) {
nextResetMillis = millis() + 1000; spk_nextResetMillis = millis() + 1000;
#ifdef DEBUG_TIMING #ifdef DEBUG_TIMING
static char buf[25]; static char buf[25];
float pct = (100.0 * (float)refreshCount) / (float)SAMPLERATE; float pct = (100.0 * (float)spk_refreshCount) / (float)SAMPLERATE;
sprintf(buf, "Speaker running at %f%% [%lu]", pct, refreshCount); sprintf(buf, "Speaker running at %f%% [%lu]", pct, spk_refreshCount);
println(buf); println(buf);
#endif #endif
refreshCount = 0; spk_refreshCount = 0;
microsAtStart = micros(); spk_microsAtStart = micros();
microsForNext = microsAtStart + ((1000000*refreshCount)/SAMPLERATE); spk_microsForNext = spk_microsAtStart + ((1000000*spk_refreshCount)/SAMPLERATE);
} }
} }