大家好! 我今天想用STM32F103C8T6的TIM1作为1KHz定时器,但是,注意到该定时器的中断频率不正确。请大家帮助一下啊,先谢谢啦 代码如下: #include "TIM1.h" /* * 函数名:TIM1_Mode_Config * 描述 :TIM1 输出PWM信号初始化,只要调用这个函数 * 输入 :无 * 输出 :无 * 调用 :外部调用 */ void TIM1_Init(void) { RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE); NVIC_TIM1_Configuration(); // TIM1_GPIO_Config(); TIM1_Configuration(); } void NVIC_TIM1_Configuration(void) { NVIC_InitTypeDef NVIC_InitStructure; //打开TIM1的全局中断,在中断中判断是更新中断还是捕捉中断 /* Enable the TIM1 global Interrupt */ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 4; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } /* * 函数名:TIM1_GPIO_Config * 描述 :配置TIM1复用输出PWM时用到的I/O * 输入 :无 * 输出 :无 * 调用 :内部调用 */ void TIM1_GPIO_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; GPIO_StructInit(&GPIO_InitStructure); /*转速输入,捕捉输入模式 用PA0配置成 */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); /* GPIO_StructInit(&GPIO_InitStructure); //转速输入,捕捉输入模式 用PA0配置成 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &GPIO_InitStructure);*/ } //转速输入捕捉, void TIM1_Configuration(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_ICInitTypeDef TIM_ICInitStructure; //TIM_ICInitTypeDef TIM_ICInitStructure; /* Time Base configuration */ TIM_DeInit(TIM1); TIM_TimeBaseStructure.TIM_Prescaler = 7200-1; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseStructure.TIM_Period = 10000-1; TIM_TimeBaseStructure.TIM_ClockDivision = 0; //TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure); /* TIM_ICInitStructure.TIM_Channel = TIM_Channel_2; TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling; TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; TIM_ICInitStructure.TIM_ICFilter = 0; TIM_ICInit(TIM1, &TIM_ICInitStructure); */ // TIM_TIxExternalClockConfig(TIM1,TIM_TIxExternalCLK1Source_TI1,TIM_ICPolarity_Rising,0);//设置为外部输入 //TIM_ETRClockMode2Config(TIM1, TIM_ExtTRGPSC_OFF, TIM_ExtTRGPolarity_NonInverted, 0); // TIM_SetCounter(TIM1, 0); // 清零计数器CNT TIM_ClearFlag(TIM1, TIM_FLAG_Update); /* 清除溢出中断标志 */ TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE); //TIM_OC4PreloadConfig(TIM4, TIM_OCPreload_Enable); TIM_ARRPreloadConfig(TIM1, ENABLE); // 使能TIM4重载寄存器ARR TIM_Cmd(TIM1,ENABLE);//使能计数 } void TIM1_Configuration1(void) //?????????? { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; //??TIMER1????? TIM_DeInit(TIM1); TIM_TimeBaseStructure.TIM_Period = 0xFFFF; TIM_TimeBaseStructure.TIM_Prescaler = 0x00; TIM_TimeBaseStructure.TIM_ClockDivision = 0x0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure); // Time base configuration TIM_ETRClockMode2Config(TIM1, TIM_ExtTRGPSC_OFF, TIM_ExtTRGPolarity_NonInverted, 0); TIM_SetCounter(TIM1, 0); // 清零计数器CNT TIM_Cmd(TIM1, ENABLE); } |
【MCU实战经验】基于STM32F103C8T6的hart总线调试器设计
求教STM32F103进入STOP模式后用外部中断唤醒的问题
基于STM32F103RCT6的无源蜂鸣器音乐播放(生日快乐歌)
STM32F103c8t6有没有DAC 功能?
STM32F103x中文数据手册
新手求教,为何在我电脑上找不到STM32F1Xx.h文件
金龙107例程汇总(STM32F107)
万利STM32F107VC 原理图
STM32F103 ADC多通道检测必须要DMA吗?
【官方例程】STM32F107以太网官方例程
7200-1----10000-1----->1HZ
7200-1----10-1--------->1000HZ
TIM_TimeBaseStructure.TIM_Period = 10-1;
评分
查看全部评分
“STM32F10x_StdPeriph_Lib_V3.1.2\Project\STM32F10x_StdPeriph_Examples\TIM\TimeBase”
你的程序不全。
评分
查看全部评分
评分
查看全部评分
按照上述的参数修改了,计时时间仍然不是1000hz,是不是时钟那里设置有问题呢?
评分
查看全部评分
评分
查看全部评分
评分
查看全部评分