完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
程序为求出输入波形的占空比而设计,所用资源为time3的1通道和2通道
当我在管脚输入1个周期为2.2ms,占空为0.5ms左右的波形时,捕获到的数据却为198和78 原理来算应该为 时钟分频为 :71 计数频率为 :72M/(72+1) = 1us 每计数一次时间为:1us 2.2ms计数应该为:2200 0.5ms计数应该为:500 不知道我推理的对吗????我写的代码有错误吗????请求帮助?????? //初始化捕获 void Study_Init(void) { NVIC_InitTypeDef NVIC_InitStructure; TIM_ICInitTypeDef TIM_ICInitStructure; GPIO_InitTypeDef GPIO_InitStructure; RCC_ClocksTypeDef RCC_Clocks; RCC_APB1PeriphClockCmd(RF_TIM_RCC ,ENABLE); //////////时钟选始能 NVIC_InitStructure.NVIC_IRQChannel = RF_TIM_IRQChannel; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); ////中断配置 RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO|RF_GPIO_RCC ,ENABLE); GPIO_PinRemapConfig(GPIO_PartialRemap_TIM3,ENABLE); GPIO_InitStructure.GPIO_Pin = RF_GPIO_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(RF_GPIO, &GPIO_InitStructure); //////输入管脚配置 /* RF_TIM configuration: PWM Input mode ------------------------ The external signal is connected to RF_TIM CH2 pin (PA.01), The Rising edge is used as active edge, The RF_TIM CCR2 is used to compute the frequency value The RF_TIM CCR1 is used to compute the duty cycle value ------------------------------------------------------------ */ RCC_GetClocksFreq(&RCC_Clocks);/////////////////////系统时钟为72M TIM_TimeBaseInitTypeDef tim_base; tim_base.TIM_Prescaler = (RCC_Clocks.PCLK2_Frequency/1000000 - 1);////分频系数 71 tim_base.TIM_CounterMode= TIM_CounterMode_Up; tim_base.TIM_Period = 0xffff; ////ARR 自动装载寄存器 tim_base.TIM_ClockDivision = 0; ////CR1中CDK[1:0]时钟分频因子为0 tim_base.TIM_RepetitionCounter = 0; TIM_TimeBaseInit(RF_TIM, &tim_base); TIM_ICInitStructure.TIM_Channel = TIM_Channel_1; TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; TIM_ICInitStructure.TIM_ICFilter = 0x3; TIM_PWMIConfig(RF_TIM, &TIM_ICInitStructure); /* Select the RF_TIM Input Trigger: TI1FP1 */ TIM_SelectInputTrigger(RF_TIM, TIM_TS_TI1FP1); /* Select the slave Mode: Reset Mode */ TIM_SelectSlaveMode(RF_TIM, TIM_SlaveMode_Reset); /* Enable the Master/Slave Mode */ TIM_SelectMasterSlaveMode(RF_TIM, TIM_MasterSlaveMode_Enable); /* TIM enable counter */ TIM_Cmd(RF_TIM, ENABLE); /* Enable the CC2 Interrupt Request */ TIM_ITConfig(RF_TIM, TIM_IT_CC1, ENABLE); } |
|
相关推荐
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
非科班也能玩转Android应用,体验QT跨平台能力-迅为RK3568开发板
465 浏览 0 评论
飞凌嵌入式-ELFBOARD-ELF 2硬件分享之最小系统原理
691 浏览 0 评论
1767 浏览 0 评论
Cortex-A55 处理器到底什么来头?创龙教仪一文带您了解
1030 浏览 0 评论
RK3568 + OpenCV 会碰撞出什么火花?案例详解:2-1 基于OpenCV的画线实验
756 浏览 0 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-12 22:33 , Processed in 0.551166 second(s), Total 74, Slave 57 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号