Created
May 28, 2019 12:30
-
-
Save komponenrobot/4572df05e7d8995ff548d0beef99a32b to your computer and use it in GitHub Desktop.
settingTimer pada STM32
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// enable TIM4 | |
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); | |
// mengatur timer 40ms = 0,04s (25Hz) | |
// clock / (prescale +1) | |
// 72.000.000/ (7199+1) = 10.000 | |
// Periode = (10.000 / 25 )-1=400-1=399 | |
TIM_TimeBaseInitTypeDef ST; | |
ST.TIM_Prescaler = 7199; | |
ST.TIM_Period = 399; | |
ST.TIM_ClockDivision = TIM_CKD_DIV1; | |
ST.TIM_CounterMode = TIM_CounterMode_Up; | |
TIM_TimeBaseInit(TIM4, &ST); | |
//enable interupt | |
TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE); | |
// mulai tim4 | |
TIM_Cmd(TIM4, ENABLE); | |
NVIC_InitTypeDef NVIC_InitStruct; | |
// Nested vectored interrupt settings | |
NVIC_InitStruct.NVIC_IRQChannel = TIM4_IRQn; | |
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0x00; | |
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0x00; | |
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE; | |
NVIC_Init(&NVIC_InitStruct); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment