correct sampling rate (~29 pwm loops)
This commit is contained in:
parent
f9125357d0
commit
ee0ac28714
1 changed files with 4 additions and 2 deletions
6
audio.c
6
audio.c
|
@ -18,6 +18,8 @@
|
||||||
|
|
||||||
#define AUDIO_PWM_PERIOD 258
|
#define AUDIO_PWM_PERIOD 258
|
||||||
|
|
||||||
|
uint32_t gSamplingRateDivider = 29; // sampling rate divider
|
||||||
|
|
||||||
void configure_audio() {
|
void configure_audio() {
|
||||||
// configure M0PWM2, at GPIO PF2, BoosterPack 1 header C1 pin 2
|
// configure M0PWM2, at GPIO PF2, BoosterPack 1 header C1 pin 2
|
||||||
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
|
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
|
||||||
|
@ -32,12 +34,13 @@ void configure_audio() {
|
||||||
PWMGenConfigure(PWM0_BASE, PWM_GEN_2,
|
PWMGenConfigure(PWM0_BASE, PWM_GEN_2,
|
||||||
PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
|
PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
|
||||||
|
|
||||||
|
|
||||||
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_2,
|
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_2,
|
||||||
AUDIO_PWM_PERIOD);
|
AUDIO_PWM_PERIOD);
|
||||||
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_5,
|
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_5,
|
||||||
roundf((float)AUDIO_PWM_PERIOD * 0.5f));
|
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);
|
PWMGenIntTrigEnable(PWM0_BASE, PWM_GEN_2, PWM_INT_CNT_ZERO);
|
||||||
|
|
||||||
PWMOutputState(PWM0_BASE, PWM_OUT_5_BIT, true);
|
PWMOutputState(PWM0_BASE, PWM_OUT_5_BIT, true);
|
||||||
|
@ -45,7 +48,6 @@ void configure_audio() {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t gPWMSample = 0; // PWM sample counter
|
uint32_t gPWMSample = 0; // PWM sample counter
|
||||||
uint32_t gSamplingRateDivider = 20; // sampling rate divider
|
|
||||||
void PWM_ISR(void)
|
void PWM_ISR(void)
|
||||||
{
|
{
|
||||||
PWMGenIntClear(PWM0_BASE, PWM_GEN_2, PWM_INT_CNT_ZERO); // clear PWM interrupt flag
|
PWMGenIntClear(PWM0_BASE, PWM_GEN_2, PWM_INT_CNT_ZERO); // clear PWM interrupt flag
|
||||||
|
|
Loading…
Reference in a new issue