Basically what I am trying to do is create an audio tone using a small speaker on a pin using a timer and then stop/disable the timer when the tone should be off so as to have the micro use as little power as possible for when I enter Deep Sleep. The code below works great for creating the audio tone and using little power. My question is what exactly happens when I call the following function and is there any undesired consequences of calling this function as I have? MAP_TimerConfigure(AUDIO_TIMER_BASE, 0); I'm wondering if the pin may get set to the wrong state randomly and use more power than expected at times or that some other unsafe operation may result.
Without using this function above, we see the power used by the micro increase to a higher than expected value after entering/exiting Deep Sleep 1-4 times. The first 1-4 times, the power usage is as expected, but then the pin will get stuck in a high state (and thus use more power) whenever we enter deep sleep without this function in the code. Any explanation of why this happens would be great as well.
I am using PC6 with WTMR1 and CCP0 on a LM4F112C4QC.
Let me know if any further details are needed. Thank you
//***This section initialized upon powering the micro***
// Compute the PWM period based on the system clock and ideal frequency of speaker
ulPeriod = MAP_SysCtlClockGet() / AUDIO_FREQUENCY;
//
// Enable the peripherals used by the audio.
//
MAP_SysCtlPeripheralEnable(AUDIO_TIMER_PERIPH);
MAP_GPIOPinConfigure(AUDIO_PWM_PIN);
MAP_GPIOPinTypeTimer(MAC_GET_BASE_ADDRESS(AUDIO_PIN), MAC_GET_PIN(AUDIO_PIN));
//
// Configure the timers.
//
MAP_TimerConfigure(AUDIO_TIMER_BASE, TIMER_CFG_SPLIT_PAIR | AUDIO_TIMER_PWM);
MAP_TimerLoadSet(AUDIO_TIMER_BASE, AUDIO_TIMER_AB, ulPeriod-1);
//***This section called every 10 ms***
MAP_GPIODirModeSet(MAC_GET_BASE_ADDRESS(AUDIO_PIN), MAC_GET_PIN(AUDIO_PIN), GPIO_DIR_MODE_HW); //Set the direction as HW/Peripheral
if(msAudio > 0 //Check if audio timer is expired
&& volume != VOLUME_OFF_CUCHAR)
{
MAP_TimerConfigure(AUDIO_TIMER_BASE, TIMER_CFG_SPLIT_PAIR | AUDIO_TIMER_PWM); //Configure timer to be a PWM Split Pair Type
MAP_TimerEnable(AUDIO_TIMER_BASE, AUDIO_TIMER_AB); //Enable the Audio timer for audible tones
}
else //If it is, turn off the audio
{
common_audiodr_setVolume_void(VOLUME_OFF_CUCHAR); //Set volume to be OFF
MAP_TimerControlLevel(AUDIO_TIMER_BASE, AUDIO_TIMER_AB, 1); //When true, timer's output is made active low
MAP_TimerDisable(AUDIO_TIMER_BASE, AUDIO_TIMER_AB); //Disable the Audio timer after setting the volume to off
MAP_TimerConfigure(AUDIO_TIMER_BASE, 0); //Un-configure the timer so that it doesn't work with no audio tone and cause extra power usage
}
if(msAudio > 0) //If audio timer is not 0
{
msAudio -= 10; //Decrement timer
}