mirror of
https://github.com/rene-dev/stmbl.git
synced 2024-12-26 02:22:25 +00:00
TIM5 pid
This commit is contained in:
parent
8a6305cd0e
commit
2f8de06e1a
22
src/setup.c
22
src/setup.c
@ -68,6 +68,7 @@ void setup(){
|
||||
|
||||
setup_pwm();
|
||||
setup_adc();
|
||||
setup_pid_timer();
|
||||
|
||||
// systick timer
|
||||
time = 0;
|
||||
@ -127,6 +128,27 @@ void setup_pwm(){
|
||||
TIM_OC4PreloadConfig(TIM4, TIM_OCPreload_Enable);
|
||||
}
|
||||
|
||||
void setup_pid_timer(){
|
||||
/* TIM5 clock enable */
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE);
|
||||
|
||||
/* pid int set up, TIM5*/
|
||||
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
|
||||
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
||||
TIM_TimeBaseStructure.TIM_Period = 420;//20kHz
|
||||
TIM_TimeBaseStructure.TIM_Prescaler = 9;
|
||||
//TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
|
||||
TIM_TimeBaseInit(TIM5, &TIM_TimeBaseStructure);
|
||||
TIM_ITConfig(TIM5, TIM_IT_Update, ENABLE);
|
||||
|
||||
/* int NVIC setup */
|
||||
NVIC_InitStructure.NVIC_IRQChannel = TIM5_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
}
|
||||
|
||||
// Setup ADC
|
||||
void setup_adc(){
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
|
||||
|
@ -40,6 +40,7 @@
|
||||
void setup();
|
||||
void setup_adc();
|
||||
void setup_pwm();
|
||||
void setup_pid_timer();
|
||||
void SysTick_Handler(void);
|
||||
|
||||
volatile int time;
|
||||
|
Loading…
Reference in New Issue
Block a user