From ee0ac2871498d1845862b99da9d846b68fb608c0 Mon Sep 17 00:00:00 2001 From: Killorin Date: Thu, 24 Apr 2025 12:52:49 -0400 Subject: [PATCH] correct sampling rate (~29 pwm loops) --- audio.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/audio.c b/audio.c index 8c7cad5..2c15424 100644 --- a/audio.c +++ b/audio.c @@ -18,6 +18,8 @@ #define AUDIO_PWM_PERIOD 258 +uint32_t gSamplingRateDivider = 29; // sampling rate divider + void configure_audio() { // configure M0PWM2, at GPIO PF2, BoosterPack 1 header C1 pin 2 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); @@ -32,12 +34,13 @@ void configure_audio() { PWMGenConfigure(PWM0_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC); - PWMGenPeriodSet(PWM0_BASE, PWM_GEN_2, AUDIO_PWM_PERIOD); PWMPulseWidthSet(PWM0_BASE, PWM_OUT_5, roundf((float)AUDIO_PWM_PERIOD * 0.5f)); + gSamplingRateDivider = gSystemClock / AUDIO_PWM_PERIOD / AUDIO_SAMPLING_RATE; + PWMGenIntTrigEnable(PWM0_BASE, PWM_GEN_2, PWM_INT_CNT_ZERO); PWMOutputState(PWM0_BASE, PWM_OUT_5_BIT, true); @@ -45,7 +48,6 @@ void configure_audio() { } uint32_t gPWMSample = 0; // PWM sample counter -uint32_t gSamplingRateDivider = 20; // sampling rate divider void PWM_ISR(void) { PWMGenIntClear(PWM0_BASE, PWM_GEN_2, PWM_INT_CNT_ZERO); // clear PWM interrupt flag