你的浏览器版本过低,可能导致网站不能正常访问!为了你能正常使用网站功能,请使用这些浏览器。
举报
zhangdaijin 发表于 2015-4-19 17:51 学习一下!!
stary666 发表于 2015-4-20 13:58 用PWM输入可以解决
dwwzl 发表于 2015-4-21 07:47 测量脉宽频率比较精细的活,我都是直接用寄存器操作的
讨论一下,可以试试一起来嘛
PWM可以获取占空比和频率,我看了,频率求解的程序是一样的,但是串口输出总是在变化,贴出中断代码
if(TIM_GetITStatus(TIM3, TIM_IT_CC2|TIM_IT_CC1) == SET)
{
/* Clear TIM3 Capture compare interrupt pending bit */
TIM_ClearITPendingBit(TIM3,TIM_IT_CC1);
TIM_ClearITPendingBit(TIM3,TIM_IT_CC2);
if(CaptureNumber == 0)
{
/* Get the Input Capture value */
IC3ReadValue1 = TIM_GetCapture2(TIM3)+TIM_GetCapture1(TIM3);
CaptureNumber = 1;
}
else if(CaptureNumber == 1)
{
/* Get the Input Capture value */
IC3ReadValue2 = TIM_GetCapture2(TIM3)+TIM_GetCapture1(TIM3);
/* Capture computation */
if (IC3ReadValue2 > IC3ReadValue1)
{
Capture = (IC3ReadValue2 - IC3ReadValue1);
}
else
{
Capture = ((0xFFFF - IC3ReadValue1) + IC3ReadValue2);
}
/* Frequency computation */
TIM3Freq = (u32) SystemCoreClock / Capture;
CaptureNumber = 0;
//printf("%d",TIM3Freq);
printf("%ld\t\t",60*TIM3Freq/64);
TIM2->CCR1+=0;
TIM2->CCR2+=0;
}
}用AB相编码器,所以开了两个通道的捕获,转一圈64个脉冲
寄存器还不是很了解,不过渐渐发现直接寄存器很有用,好吧我再看看