遇到了一个光标变成下划线的问题:
Keil5光标变下划线,变回来的方法_keil5光标是下划线-CSDN博客
这里是用了输入捕获(IC:input capture),输出比较(OC:Output Compare)区别
学到这里是以为,首先输入捕获是捕获外界的数字信号,如果是模拟信号,可能需要加信号处理的模块,变成数字信号再加以处理计算。输出比较,是比较产生输出。
#include "stm32f10x.h" // Device header
#include "Pwm.h"
void IC_Init(void)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);//ÕâÀïÅäÖóÉÁËTIM2ÁË
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;//ÉÏÀÊäÈëδÉèÖÃ
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
TIM_InternalClockConfig(TIM3);//¶¨Ê±Æ÷δ¸ü¸ÄΪ3
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInitStructure.TIM_Period = 65536-1;//×Ô¶¯ÖØ×°¼Ä´æÆ÷£¬ARR£¬ÎÊÌâÔÚÕâÀï
TIM_TimeBaseInitStructure.TIM_Prescaler = 72-1;//Ô¤·ÖƵÆ÷£¬¶¨Ê±ÆµÂÊ=CK_PSC¡¾72M¡¿/PSC+1/ARR+1£¬¶¨Ê±Ê±¼äΪ1.
TIM_TimeBaseInitStructure.TIM_RepetitionCounter = 0;//Öظ´¼ÆÊýÆ÷µÄÖµ
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseInitStructure);
TIM_ICInitTypeDef TIM_ICInitStructure;
TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;
TIM_ICInitStructure.TIM_ICFilter = 0xF;
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
TIM_PWMIConfig(TIM3,&TIM_ICInitStructure);
// TIM_ICInit(TIM3,&TIM_ICInitStructure);
TIM_SelectInputTrigger(TIM3,TIM_TS_TI1FP1);//Ñ¡´íͨµÀÁË
TIM_SelectSlaveMode(TIM3,TIM_SlaveMode_Reset);
TIM_Cmd(TIM3,ENABLE);
}
uint32_t IC_GetFreq(void)//ÕâÀïд³ÉÁËGetcaptureÁË£¬ºóÃæÖ÷º¯ÊýÀïûÓгöÏÖGetfreq
{
return 1000000/(TIM_GetCapture1(TIM3)+1);
}
uint32_t IC_GetDuty(void)//δ¼Óvoid
{
return (TIM_GetCapture2(TIM3)+1)*100/(TIM_GetCapture1(TIM3)+1);
}
打通这些配置单元,最后两个CCR1和CCR2的单元,CCR2/CCR1就是得到的占空比,其中CCR2计数的是前一个上升沿到下一个上升沿所需要的计数,CCR1测量的是一整个周期的计数。
由0<CCR2/CCR1<1,而我们是瞬时的配置,会出现CCR缺1的情况,因而加1。
我们将其配置成两位数,乘以100得到百分比。
资料来源:江协科技[6-6] 输入捕获模式测频率&PWMI模式测频率占空比_哔哩哔哩_bilibili
标签:TimeBaseInitStructure,TIM3,12,TIM,void,单片机,GPIO,PWM,ICInitStructure From: https://blog.csdn.net/2301_77143735/article/details/140384522