2015-10-13 05:53 AM
Hi everyone,
We want to have a 600 kHz frequency timer. We use the Internal Oscillator HSI 16 Mhz.RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_PeriphCLKInitTypeDef PeriphClkInit;
__PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = 16;
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
HAL_RCC_OscConfig(&RCC_OscInitStruct);
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0);
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1;
PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
And we have this configuration for the timer6.
Presc=2
Period=6
If I well understood, we should have this frequency:
TIM_Update_Frequency(Hz) =16000000/(2*14)=571428
But we got 21,5kHZ instead.
Thanks!
2015-10-13 06:29 AM
Interrupting?
Not sure 600 KHz is viable with a processor running at 16 MHz. The TIM can output a signal at this rate, and you should double check that.2015-10-13 07:12 AM
There is no interruption.
Does it mean that my configuration of the prescaler and the period are correct? I am using stm32l02015-10-13 08:53 AM
Does it mean that my configuration of the prescaler and the period are correct?
Honestly your math looks totally wrong. Should be 16 MHz / 21 = 761.905 KHz, based on the details you provided. ((2 + 1) * (6 + 1)) = 21 Not using the L0, or HAL/Cube, don't see code setting up the timer base, or where/what you're measuring. Probably should start by confirming what frequency the thing is running at via MCO (PA8)2015-10-13 08:56 AM
Should get close to 600KHz with Prescaler = 0, Period = 26
16000000 / 27 = 592.593 KHz Want to get closer, you need to pick a processor frequency that's an integer multiple of 600000 Hz