#include "Whose_Init_.h"
#include "stm32f10x.h"
#include "sys.h"
void RCC_Init_ (void)
{
RCC_APB1PeriphClockCmd (RCC_APB1Periph_TIM3 , ENABLE);
//定时器3时钟使能
RCC_APB2PeriphClockCmd (RCC_APB2Periph_TIM1 , ENABLE);
//定时器1时钟使能
RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOE | RCC_APB2Periph_GPIOA , ENABLE);
//GPIO时钟使能
RCC_APB2PeriphClockCmd (RCC_APB2Periph_AFIO , ENABLE);
//复用时钟使能
}
void GPIO_Init_ (void)
{
GPIO_InitTypeDef GPIO_Init_GPIOC , GPIO_Init_GPIOE;
GPIO_Init_GPIOC.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init_GPIOC.GPIO_Pin = GPIO_Pin_7;
GPIO_Init_GPIOC.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init (GPIOC,&GPIO_Init_GPIOC);
//GPIOC初始化
GPIO_Init_GPIOC.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init_GPIOC.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6;
GPIO_Init_GPIOC.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init (GPIOA,&GPIO_Init_GPIOC);
PAout (5) = 1;
PAout (6) = 0;
//GPIOC初始化
GPIO_Init_GPIOE.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init_GPIOE.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_11 | GPIO_Pin_8 | GPIO_Pin_10;
GPIO_Init_GPIOE.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init (GPIOE,&GPIO_Init_GPIOE);
//GPIOE初始化
GPIO_PinRemapConfig (GPIO_FullRemap_TIM1,ENABLE);
//定时器1重映射
GPIO_PinRemapConfig (GPIO_FullRemap_TIM3,ENABLE);
//定时器3重映射
}
void TIM_Init_ (void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseInit_TIM3 , TIM_TimeBaseInit_TIM1;
TIM_TimeBaseInit_TIM1.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInit_TIM1.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit_TIM1.TIM_Period = 3599;
TIM_TimeBaseInit_TIM1.TIM_Prescaler = 0;
TIM_TimeBaseInit (TIM1,&TIM_TimeBaseInit_TIM1);
//定时器1初始化
TIM_Cmd (TIM1,ENABLE);
//使能定时器1
TIM_TimeBaseInit_TIM3.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInit_TIM3.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit_TIM3.TIM_Period = 3599;
TIM_TimeBaseInit_TIM3.TIM_Prescaler = 0;
TIM_TimeBaseInit (TIM3,&TIM_TimeBaseInit_TIM3);
//定时器3初始化
TIM_Cmd (TIM3,ENABLE);
//使能定时器3
}
void PWM_Init_ (void)
{
TIM_OCInitTypeDef TIM_OCInit_TIM3,TIM_OCInit_TIM1;
TIM_OCInit_TIM3.TIM_Pulse = 3599;
TIM_OCInit_TIM3.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInit_TIM3.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInit_TIM3.TIM_OutputState = TIM_OutputState_Enable;
TIM_OC2Init (TIM3,&TIM_OCInit_TIM3);
//定时器3PWM初始化
TIM_OC2PreloadConfig (TIM3,TIM_OCPreload_Enable);
//使能定时器3预装载寄存器
TIM_OCInit_TIM1.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInit_TIM1.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInit_TIM1.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInit_TIM1.TIM_Pulse = 3599;
TIM_OC1Init (TIM1,&TIM_OCInit_TIM1);
//定时器1通道1初始化
TIM_OC1PreloadConfig (TIM1,TIM_OCPreload_Enable);
//使能定时器1预装载寄存器
TIM_OCInit_TIM1.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInit_TIM1.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInit_TIM1.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInit_TIM1.TIM_Pulse = 0;
TIM_OC2Init (TIM1,&TIM_OCInit_TIM1);
//定时器1通道2初始化
TIM_OC2PreloadConfig (TIM1,TIM_OCPreload_Enable);
//使能定时器1预装载寄存器
TIM_ARRPreloadConfig(TIM1, ENABLE);
//使能ARR预装载寄存器
TIM_ARRPreloadConfig(TIM3, ENABLE);
//使能ARR预装载寄存器
TIM_CtrlPWMOutputs(TIM1,ENABLE);
//定时器1主通道输出使能
}
这个是我的配置,主函数只是调用这些函数而已,我尝试用L298N驱动板控制电机,定时器3作为使能接口,PA5,PA6作为IN接口,用定时器3控制PWM波率没问题,用高级定时器控制PWM就炸了。。电机连转都不会转。。求助
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>