Skip to content

Instantly share code, notes, and snippets.

@komponenrobot
Created May 28, 2019 12:34
Show Gist options
  • Save komponenrobot/180d2d82edd3e8c7bb9a9f71c04c8753 to your computer and use it in GitHub Desktop.
Save komponenrobot/180d2d82edd3e8c7bb9a9f71c04c8753 to your computer and use it in GitHub Desktop.
gabungan semua coding
#include "stm32f10x.h"
#include "stm32f10x_tim.h"
int hitung=0;
void TIM4_IRQHandler(){
if(TIM_GetITStatus(TIM4, TIM_IT_Update)){
hitung++;
// taruh sini koding untuk sampling data
TIM_ClearITPendingBit(TIM4, TIM_IT_Update);
}
}
int main(void){
// 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);
while(1){
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment