cancel
Showing results for 
Search instead for 
Did you mean: 

Is my configuration right for 33KHz ?

antonius
Senior

Dear Member,

I use timer 3 for generating a tone,

is this configuration right, for generating 30KHz ?

Chip = STM32L152RE, Clock 2.097MHz

TIM_ClockConfigTypeDef sClockSourceConfig = {0};

 TIM_MasterConfigTypeDef sMasterConfig = {0};

 TIM_OC_InitTypeDef sConfigOC = {0};

 htim3.Instance = TIM3;

 htim3.Init.Prescaler = (SystemCoreClock/1000000)-1;

 htim3.Init.CounterMode = TIM_COUNTERMODE_UP;

 htim3.Init.Period = 2097000/33000;

 htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

 if (HAL_TIM_Base_Init(&htim3) != HAL_OK)

Thanks

3 REPLIES 3

Hi

No need to prescale

Prescaler=0 and Period 2097000/33000-1 =63

Period 63 gives update frequency 32765 Hz

Period 62 gives update frequency 33285 Hz

antonius
Senior

 htim3.Init.Prescaler = 0;

 htim3.Init.Period = 2097000/33000-1;

Right ?

S.Ma
Principal

Well, I used on STM32L4R the LPTIM1 to generate buzzer tone. works fine and easy to do.

SYSCLK = 48Mhz, LPTIM = 3 MHz.