Question
How to use Timer6 and Timer7 at the same time?
I used Timer6 and Timer7 on STM32L433CCT6, used Timer6 for tone generation and Timer7 for tone toggle generation, the ISR is:
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim)
{
if(htim == &htim6)
{
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_0);
//TIM6->CNT = toneFreq[0];
}
else if(htim == &htim7)
{
if(flagOnOff == SET)
{
if(msTone >= toneOn[toneFreqIndex])
{
flagOnOff = RESET;
msTone = 0;
GPIOA->MODER &= ~(GPIO_MODER_MODER0); // From output to input
}
else
{
msTone++;
}
}
else // flagOnOff == RESET
{
if(msTone >= toneOff[toneFreqIndex])
{
flagOnOff = SET;
msTone = 0;
GPIOA->MODER |= GPIO_MODER_MODER0_0; // From input to output
}
else
{
msTone++;
}
}
}
else
{;}
}
the related variables are:
extern int toneFreq[] = {130, 146, 164, 174, 196, 220, 246}; // prescale value of Timer6 is 71
extern int toneOn[] = {9000, 8000, 7000, 6000, 5000, 4000, 3000}; // miliseconds, prescale value of Timer7 is 7199
extern int toneOff[] = {1000, 2000, 3000, 4000, 5000, 6000, 7000}; // 10us = 1 tick
int msTone = 0; // miliseconds
volatile bool flagOnOff = SET;
now, the tone was OK, the toggle affection was not, did I lost anything?
