在使用一个定时器捕获两路PWM的频率时,中断函数应该如何配置呢?? 我采用如下的方式去获取,但得到的PWM信号的占空比其中有一路为200,一路为50, __IO uint16_t IC2Value = 0; __IO uint16_t IC1Value = 0; __IO float DutyCycle = 0; __IO float Frequency = 0; /* * 如果是第一个上升沿中断,计数器会被复位,锁存到CCR1寄存器的值是0,CCR2寄存器的值也是0 * 无法计算频率和占空比。当第二次上升沿到来的时候,CCR1和CCR2捕获到的才是有效的值。其中 * CCR1对应的是周期,CCR2对应的是占空比。 */ void ADVANCE_TIM_IRQHandler(void) { if(TIM_GetITStatus(ADVANCE_TIM,TIM_IT_CC1)==SET ) { /* 清除中断标志位 */ TIM_ClearITPendingBit(ADVANCE_TIM, TIM_IT_CC1); /* 获取输入捕获值 */ IC1Value = TIM_GetCapture1(ADVANCE_TIM); IC2Value = TIM_GetCapture2(ADVANCE_TIM); // 注意:捕获寄存器CCR1和CCR2的值在计算占空比和频率的时候必须加1 if (IC1Value != 0) { /* 占空比计算 */ DutyCycle = (float)((IC2Value+1) * 100) / (IC1Value+1); /* 频率计算 */ Frequency = (72000000/(ADVANCE_TIM_PSC+1))/(float)(IC1Value+1); printf("占空比:%0.2f%% 频率:%0.2fHz\n",DutyCycle,Frequency); } } else if(TIM_GetITStatus(ADVANCE_TIM,TIM_IT_CC2)==SET ) { /* 清除中断标志位 */ TIM_ClearITPendingBit(ADVANCE_TIM, TIM_IT_CC2); /* 获取输入捕获值 */ IC1Value = TIM_GetCapture1(ADVANCE_TIM); IC2Value = TIM_GetCapture2(ADVANCE_TIM); // 注意:捕获寄存器CCR1和CCR2的值在计算占空比和频率的时候必须加1 if (IC1Value != 0) { /* 占空比计算 */ DutyCycle = (float)((IC2Value+1) * 100) / (IC1Value+1); /* 频率计算 */ Frequency = (72000000/(ADVANCE_TIM_PSC+1))/(float)(IC1Value+1); printf("占空比:%0.2f%% 频率:%0.2fHz\n",DutyCycle,Frequency); } } } |
stm32进入stop模式被莫名其妙唤醒(应该是systick)但是无法被WKUP引脚唤醒。
头文件找不到
软件为keil5,头文件未找到
通过FATFS文件系统读写SD卡创建文件可以了,但加入MSC,一直显示一个没有格式化的U盘盘符,也不能格式化,这是什么问题导致的
stm32f103汇编求助
cubemx 生成的freertos代码 在keil ac6下不能编译,有什么解决的方法吗
报错Could not determine GDB version using command: arm-none-eabi-gdb --version
stm32f107vct6配RTL8201例程
STM32F103VGT6 能代替 STM32F103VFT6 吗?
STM32 读取DHT20,跑的官方的例程一直读取失败,初学者,各位大佬能指点一下不
我在使用一个定时器捕获2路PWM信号的时候,信号也没有超出去,但我在初始化的过程中使用如下的初始化,可是为什么我只能捕获第2个通道的值,第一个通道的值会被覆盖,即GENERAL1_TIM_IC1_CHANEL这里的被替代,麻烦你指导一下。(我这里使用了TIM3的通道1和通道2来捕获PWM信号)
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 = 0x0;
TIM_PWMIConfig(TIM3, &TIM_ICInitStructure);
TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
TIM_PWMIConfig(TIM3, &TIM_ICInitStructure);
TIM_SelectInputTrigger(TIM3, TIM_TS_TI1FP1);
TIM_SelectInputTrigger(TIM3, TIM_TS_TI2FP2);
TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Reset);
TIM_SelectMasterSlaveMode(TIM3, TIM_MasterSlaveMode_Enable);
TIM_Cmd(TIM3, ENABLE);
TIM_ITConfig(TIM3, TIM_IT_CC1, ENABLE);
TIM_ITConfig(TIM3, TIM_IT_CC2, ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
我在使用一个定时器捕获2路PWM信号的时候,,但我在初始化的过程中使用如下的初始化,可是为什么我只能捕获第2个通道的值,第一个通道的值会被覆盖,即TIM_Channel_1通道这里的被替代,麻烦你指导一下我这个初始化捕获2路是否可以?。(我这里使用了TIM3的通道1和通道2来捕获PWM信号)
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 = 0x0;
TIM_PWMIConfig(TIM3, &TIM_ICInitStructure);
TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
TIM_PWMIConfig(TIM3, &TIM_ICInitStructure);
TIM_SelectInputTrigger(TIM3, TIM_TS_TI1FP1);
TIM_SelectInputTrigger(TIM3, TIM_TS_TI2FP2);
TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Reset);
TIM_SelectMasterSlaveMode(TIM3, TIM_MasterSlaveMode_Enable);
TIM_Cmd(TIM3, ENABLE);
TIM_ITConfig(TIM3, TIM_IT_CC1, ENABLE);
TIM_ITConfig(TIM3, TIM_IT_CC2, ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);