坛里有人用nano100 timer0做过输入捕获吗?
GCR->PA_H_MFP = GCR->PA_H_MFP & ~(PA12_MFP_MASK) | PA12_MFP_TMR0_CAP;
TIMER_Init(TIMER0, 11, 1000000, TIMER_CTL_MODESEL_PERIODIC);
TIMER_EnableCaptureMode(TIMER0,TIMER_CTL_CAPCNTMOD_TRIGGER_CNT,TIMER_CTL_TCAPEDGE_RR);
TIMER_EnableInt(TIMER0, TIMER_IER_TCAPIE); //TIMER_IER_TMRIE|
TIMER_Start(TIMER0);
void TMR0_IRQHandler(void)
{
//
// TIMER0->ISR = 3;
if(TIMER_GetIntFlag(TIMER0)==TIMER_ISR_TCAPIS) //输入捕获中断
{
TIMER0->ISR=TIMER_ISR_TCAPIS;
if(g_CaptureIdx>=MAX_CAPTURE_TIMES)
{
g_CaptureIdx=0;
}
if(g_CaptureCount<MAX_CAPTURE_TIMES)
{
g_CaptureCount++;
}
Frequency=12000000/TIMER_GetCaptureData(TIMER0);
if(Frequency>MAX_FREQUENCY)
{
Frequency=MAX_FREQUENCY;
}
g_CaptureBuffer[g_CaptureIdx]=Frequency;
g_CaptureIdx++;
}
if(TIMER_GetIntFlag(TIMER0)==TIMER_ISR_TMRIS) //定时器中断
{
TIMER0->ISR=TIMER_ISR_TMRIS;
}
}
我用PA12做输入捕获,timer0的TC0捕捉输入,以下是我的代码,烦请大家帮忙看看。或者大家有Nano100系列的参考代码,请分享一下,万分感谢。
看了PWM的捕获DEMO,发现好像不是我需要的,所以就改成上面那段代码了。 |