2015-12-09 01:22 AM
Hello everyone, i'm having some problems giving the right clock to timer 6..
I should be geting an interrupt(toggle pin) every 1 msec, instead i get a toggle every 546 usec ... This is my codevoid SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
__PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 25; // i'm using 25 MHz crystal
RCC_OscInitStruct.PLL.PLLN = 192;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; // ((25/M)*N)/P = 96 MHz
RCC_OscInitStruct.PLL.PLLQ = 4;
HAL_RCC_OscConfig(&RCC_OscInitStruct);
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1
|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3);
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}
void MX_TIM6_Init(void)
{
htim6.Instance = TIM6;
htim6.Init.Prescaler = 12; // prescale to 2MHz
htim6.Init.ClockDivision = 0;
htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
htim6.Init.Period = 2000; // 2000*0.5usec=1000 usec time
HAL_TIM_Base_Init(&htim6);
HAL_TIM_Base_Start_IT(&htim6);
}
void TIM6_DAC_IRQHandler(void)
{
HAL_GPIO_TogglePin(GPIOA,RE_Pin); // toggle
HAL_TIM_IRQHandler(&htim6);
2015-12-09 05:15 AM
htim6.Instance = TIM6; // APB1 24MHz, TIMCLK 48Mhz
htim6.Init.Prescaler = 24-1; // prescale to 2MHz (48/24)
htim6.Init.ClockDivision = 0;
htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
htim6.Init.Period = 2000-1; // 2000*0.5usec=1000 usec time
HAL_TIM_Base_Init(&htim6);
2015-12-11 06:12 AM
Thanks clive, a figured out later that it is minus 1