<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>S12 / MagniV Microcontrollers中的主题 About input capture question</title>
    <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/About-input-capture-question/m-p/827130#M15931</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;&amp;nbsp; &amp;nbsp; I,m using S12ZVC64 for capture square wave's frequency and duty。&lt;/SPAN&gt;&lt;SPAN style="color: #222222; background-color: #f5f5f5; border: 0px;"&gt;&amp;nbsp;The input frequency is between 10Hz and 3000Hz&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;。&lt;/SPAN&gt;but it not work.just use PT5 as single input , when &lt;SPAN&gt;&amp;nbsp;The input frequency is 1000Hz,&lt;/SPAN&gt;&amp;nbsp;if dubug the code，it just join in the interrupt one time.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#include &amp;lt;hidef.h&amp;gt; /* for EnableInterrupts macro */&lt;BR /&gt;#include "derivative.h" /* include peripheral declarations */&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;#define TIMER_PRESCALER 1 // 1,2,4,8,16,32,64,128&lt;BR /&gt;#define MAX_OVERFLOWS 1000L // max. allowed number of TIM overflows&lt;BR /&gt;#define NEW_VALUE_PREPARED Flags.bit.f0 // info for sending data&lt;BR /&gt;#define FREQUENCY_TOO_LOW Flags.bit.f1 // mesured frequency is lower thannot measurablelower than&lt;BR /&gt;#define FIRST_EDGE 1&lt;BR /&gt;#define SECOND_EDGE 0&lt;BR /&gt;#define STOP_MEASUREMENT 3&lt;BR /&gt;#define TIM0_Channel5_VEC_OFF 0x1B8&lt;BR /&gt;#define TIM0_Overflow_VEC_OFF 0x1AC&lt;/P&gt;&lt;P&gt;#define SET_INTERRUPT_PRIORITY(vec_off, priority) \&lt;BR /&gt; INT_CFADDR= (vec_off/4) &amp;amp; 0xF8; \&lt;BR /&gt; INT_CFDATA_ARR[(vec_off/4) &amp;amp; 0x03]= (priority)&lt;/P&gt;&lt;P&gt;//----- DEPENDENT DEFINITIONS -----&lt;BR /&gt;#if TIMER_PRESCALER==1&lt;BR /&gt;#define PRESCALER 0&lt;BR /&gt;#endif&lt;BR /&gt;#if TIMER_PRESCALER==2&lt;BR /&gt;#define PRESCALER 1&lt;BR /&gt;#endif&lt;BR /&gt;#if TIMER_PRESCALER==4&lt;BR /&gt;#define PRESCALER 2&lt;BR /&gt;#endif&lt;BR /&gt;#if TIMER_PRESCALER==8&lt;BR /&gt;#define PRESCALER 3&lt;BR /&gt;#endif&lt;BR /&gt;#if TIMER_PRESCALER==16&lt;BR /&gt;#define PRESCALER 4&lt;BR /&gt;#endif&lt;BR /&gt;#if TIMER_PRESCALER==32&lt;BR /&gt;#define PRESCALER 5&lt;BR /&gt;#endif&lt;BR /&gt;#if TIMER_PRESCALER==64&lt;BR /&gt;#define PRESCALER 6&lt;BR /&gt;#endif&lt;BR /&gt;#if TIMER_PRESCALER==128&lt;BR /&gt;#define PRESCALER 7&lt;BR /&gt;#endif&lt;BR /&gt;//&lt;/P&gt;&lt;P&gt;/*******************************************************************************&lt;BR /&gt; * Local types&lt;BR /&gt; ******************************************************************************/&lt;BR /&gt;typedef unsigned char UBYTE;&lt;BR /&gt;typedef char SBYTE;&lt;BR /&gt;typedef unsigned int UWORD;&lt;BR /&gt;typedef int SWORD;&lt;BR /&gt;typedef unsigned long ULONG;&lt;BR /&gt;typedef long SLONG;&lt;BR /&gt;typedef union Flags&lt;BR /&gt;{&lt;BR /&gt; UBYTE byte;&lt;BR /&gt; struct&lt;BR /&gt; {&lt;BR /&gt; UBYTE f0 :1;&lt;BR /&gt; UBYTE f1 :1;&lt;BR /&gt; UBYTE f2 :1;&lt;BR /&gt; UBYTE f3 :1;&lt;BR /&gt; UBYTE f4 :1;&lt;BR /&gt; UBYTE f5 :1;&lt;BR /&gt; UBYTE f6 :1;&lt;BR /&gt; UBYTE f7 :1;&lt;BR /&gt; } bit;&lt;BR /&gt;} FLAGS;&lt;BR /&gt;static void IOC5_Init(void);&lt;BR /&gt;static void PLL_Init(void);&lt;BR /&gt;void GPIO_Init(void);&lt;BR /&gt;/*******************************************************************************&lt;BR /&gt; * Local variables&lt;BR /&gt; ******************************************************************************/&lt;BR /&gt;static ULONG period; // calcualted period between two rising edges&lt;BR /&gt;static UWORD ch0ovfCnt; // the number of main timer overflows between&lt;/P&gt;&lt;P&gt;volatile FLAGS Flags; // general purpose flags &lt;BR /&gt;// rising edges&lt;BR /&gt;static UWORD tFirstEdge = 0; // value of the timer when period starts&lt;BR /&gt;static UWORD tSecondEdge= 0; // value of the timer when period finishes&lt;BR /&gt;//static UBYTE mPhase;&lt;BR /&gt;static UBYTE mPhase = STOP_MEASUREMENT;&lt;BR /&gt;static UWORD Fre;&lt;/P&gt;&lt;P&gt;static void PLL_Init(void){&lt;BR /&gt; //USE External Power 0x06 not use:0x05&lt;BR /&gt; CPMUVREGCTL = 0x06; //Internal voltage regulator for VDDX domain&lt;BR /&gt; //CPMUVREGCTL = 0x05; //Internal voltage regulator for VDDX domain&lt;BR /&gt; &lt;BR /&gt; CPMUCLKS_PLLSEL = 1; //FBUS = FPLL/2. FBUS = 16MHz, &lt;BR /&gt; CPMUREFDIV_REFFRQ = 0x00; //Reference clock between 2MHZ and 6MHZ. &lt;BR /&gt; CPMUREFDIV_REFDIV = 0x3; //FREF=8/(1+3) = 2MHZ &lt;BR /&gt; //00: 32MHz &amp;lt;= fVCO &amp;lt;= 48MHz&lt;BR /&gt; //01: 48MHz &amp;lt; fVCO &amp;lt;= 64MHz&lt;BR /&gt; CPMUSYNR_VCOFRQ = 0x00; //FVCO is between 48MHZ and 80MHZ &lt;BR /&gt; CPMUSYNR_SYNDIV = 0x7; //FVCO = 2xFREFx(SYNDIV+1) = FVCO = 2x2x(7+1) = 32MHZ&lt;BR /&gt; CPMUPOSTDIV_POSTDIV = 0x1;//FPLL = FVCO/(POSTDIV+1). FPLL = 32MHZ/(0+1) FPLL = 32MHz &lt;BR /&gt; &lt;BR /&gt; CPMUOSC_OSCE = 1;//External oscillator enable. 8MHZ. FREF=FOSC/(REFDIV+1) &lt;BR /&gt; while (!CPMUIFLG_LOCK) {} // Wait for LOCK. &lt;BR /&gt; CPMUIFLG = 0xFF;// clear CMPMU int flags - not needed but good practice &lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; //浣胯兘RTI 涓柇&lt;BR /&gt; // Source IRCLOCK 1M &lt;BR /&gt; //0x80:1ms 0x81:2ms 0x82:5ms 0x83: 10ms 0x84:20ms&lt;BR /&gt; CPMURTI=0x80; // 璁剧疆RTICTL涓?0101 1001 婧㈠嚭鍛ㄦ湡涓?(9+1)*2^(15)/(32M)= 10*2^15/(32M) &lt;BR /&gt; CPMUINT_RTIE=1; // 鍏佽鍦ㄦ瘡涓懆鏈熺粨鏉熶骇鐢熶腑鏂?&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;static void IOC5_Init(void){&lt;BR /&gt; &lt;BR /&gt; PERT_PERT5 = 1; // an internal pull resitor enable&lt;BR /&gt; PPST_PPST5 = 0; // an internal pull up connected&lt;BR /&gt; TIM0TIOS_IOS5 = 0x00; //指定通道5为输入捕捉方式&lt;BR /&gt; TIM0TCTL3_EDG5A = 0x01;&lt;BR /&gt; TIM0TCTL3_EDG5B = 0x0;&lt;BR /&gt; &lt;BR /&gt; //TIM1 16M&lt;BR /&gt; //32M/2 = 8M&lt;BR /&gt; TIM0TSCR2_PR = 0x01; // 16M/ 1^1 = 16M&lt;BR /&gt; TIM0TIE_C5I = 0x0; // 允许通道5定时中断&lt;BR /&gt; TIM0TSCR2_TOI = 0; &lt;BR /&gt; TIM0TSCR1 = 0x60; &lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;#pragma CODE_SEG NON_BANKED&lt;BR /&gt;interrupt VectorNumber_Vtim0ch5 void vectorNumber_Vtim0ch5(void){&lt;BR /&gt; unsigned int ttt, tof;&lt;BR /&gt; tof = TIM0TFLG2_TOF; // check whether additional TOF appeared&lt;BR /&gt; ttt = TIM0TC5; // get TCNT value&lt;BR /&gt; if( mPhase == FIRST_EDGE )&lt;BR /&gt; {&lt;BR /&gt; // what happens if ovfs happened while going to this interrupt?...solution&lt;BR /&gt; if( tof )&lt;BR /&gt; { // a new period has already started&lt;BR /&gt; if( ttt &amp;lt; 32768 ) TIM0TFLG2_TOF = 1; // clear ovf interrupt flag&lt;BR /&gt; }&lt;BR /&gt; ch0ovfCnt = 0; // reset overflows counter&lt;BR /&gt; //--------------------------&lt;BR /&gt; tFirstEdge = ttt; // get first edge value&lt;BR /&gt; mPhase = SECOND_EDGE; // set configuration to get second edge&lt;BR /&gt; TIM0TFLG1_C5F = 1; // clear interrupt flag from PT5&lt;BR /&gt; return; // go back to wait for second edge&lt;BR /&gt; }&lt;BR /&gt; else&lt;BR /&gt; {&lt;BR /&gt; // what happens if ovfs happened while going to this interrupt?...solution&lt;BR /&gt; if( tof )&lt;BR /&gt; { // a new period has already started&lt;BR /&gt; if( ttt &amp;lt; 32768 ) ch0ovfCnt++; &lt;BR /&gt; }&lt;BR /&gt; //--------------------------&lt;/P&gt;&lt;P&gt;tSecondEdge = ttt; // read new captured value and clear flag&lt;BR /&gt; // stop measurement&lt;BR /&gt; TIM0TSCR2_TOI = 0; // disable ovf interrupt&lt;BR /&gt; TIM0TIE_C5I = 0; // disable Ch5 interrupt &lt;BR /&gt; TIM0TFLG1_C5F = 1; // clear interrupt flag from PT5&lt;BR /&gt; }&lt;BR /&gt; // Ch0 period calculation&lt;BR /&gt; if( !ch0ovfCnt ) // Did edges appear within one timer period?&lt;BR /&gt; {&lt;BR /&gt; period = ( ULONG ) ( tSecondEdge - tFirstEdge );&lt;BR /&gt; }&lt;BR /&gt; else // some number of overflows has appeared between two edges&lt;BR /&gt; {&lt;BR /&gt; // time given by overflows period=....&lt;BR /&gt; period = ( ULONG ) ( ~tFirstEdge + 1 ); // time in the first period&lt;BR /&gt; period += ( ULONG ) ( tSecondEdge ); // time in the last period&lt;BR /&gt; period += ( ULONG ) (( ULONG ) ( ch0ovfCnt - 1 ) * ( ULONG ) ( 65536 ));&lt;BR /&gt; }&lt;BR /&gt; NEW_VALUE_PREPARED = TRUE; // information for main routine &lt;BR /&gt;}&lt;BR /&gt;#pragma CODE_SEG DEFAULT&lt;/P&gt;&lt;P&gt;#pragma CODE_SEG NON_BANKED&lt;BR /&gt;interrupt VectorNumber_Vtim0ovf void TIM0_Overflow_ISR(void) { &lt;BR /&gt; &lt;BR /&gt; ch0ovfCnt++; // count overflows&lt;/P&gt;&lt;P&gt;if( ch0ovfCnt &amp;gt; MAX_OVERFLOWS )&lt;BR /&gt; {&lt;BR /&gt; ch0ovfCnt = 0;&lt;BR /&gt; FREQUENCY_TOO_LOW = TRUE;&lt;BR /&gt; // stop measurement&lt;BR /&gt; TIM0TSCR2_TOI = 0; // disable ovf interrupt&lt;BR /&gt; TIM0TIE_C5I = 0; // disable Ch5 interrupt &lt;BR /&gt; TIM0TFLG1_C5F = 1; // clear interrupt flag from PT5&lt;BR /&gt; NEW_VALUE_PREPARED = TRUE; // information for main routine &lt;BR /&gt; }&lt;BR /&gt; else&lt;BR /&gt; {&lt;BR /&gt; FREQUENCY_TOO_LOW = FALSE;&lt;BR /&gt; }&lt;BR /&gt; TIM0TFLG2_TOF = 0x1; &lt;BR /&gt; &lt;BR /&gt;}&lt;BR /&gt;#pragma CODE_SEG DEFAULT&lt;BR /&gt;void GPIO_Init(void){&lt;BR /&gt; &lt;BR /&gt; //=== GPIO INIT ================&lt;BR /&gt; DDRT_DDRT5 = 0; // PT5 input port&lt;BR /&gt; PERT_PERT5 = 1; // Pull resistor enabled at PT5&lt;BR /&gt; PPST_PPST5 = 1; // Pull down selected at PT5&lt;BR /&gt; &lt;BR /&gt; DDRS_DDRS6 = 1; // output port&lt;BR /&gt; PTS_PTS6 = 0; // output port&lt;BR /&gt;}&lt;BR /&gt;void main(void) {&lt;BR /&gt; PLL_Init();&lt;BR /&gt; GPIO_Init();&lt;BR /&gt; FREQUENCY_TOO_LOW = TRUE; // set flag&lt;BR /&gt; NEW_VALUE_PREPARED = FALSE; // set flag&lt;BR /&gt; SET_INTERRUPT_PRIORITY(TIM0_Channel5_VEC_OFF, 7); // max priority&lt;BR /&gt; SET_INTERRUPT_PRIORITY(TIM0_Overflow_VEC_OFF, 6); // less priority than IC0&lt;BR /&gt; IOC5_Init();&lt;BR /&gt; &lt;BR /&gt; TIM0TSCR2_TOI = 1;&lt;BR /&gt; TIM0TIE_C5I = 0x01; // 允许通道2定时中断&lt;BR /&gt; EnableInterrupts;&lt;BR /&gt; /* include your code here */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for(;;) {&lt;BR /&gt; // __RESET_WATCHDOG(); /* feeds the dog */&lt;BR /&gt; &lt;BR /&gt; FREQUENCY_TOO_LOW = FALSE; // clear flag&lt;BR /&gt; NEW_VALUE_PREPARED = FALSE; // set flag&lt;BR /&gt; ch0ovfCnt = 0; // clear number of ovfs interrupts&lt;BR /&gt; TIM0TFLG1_C5F = 1; // clear interrupt flag from PT0&lt;BR /&gt; TIM0TFLG2_TOF = 0x1; // clear interrupt TOV flag&lt;BR /&gt; mPhase = FIRST_EDGE; // prepare processing of a first edge&lt;BR /&gt; TIM0TSCR1_TEN = 1; // run timer&lt;BR /&gt; TIM0TIE_C5I = 1; // enable Ch5 interrupt &lt;BR /&gt; TIM0TSCR2_TOI = 1; // enable ovf interrupt &lt;BR /&gt; while( !NEW_VALUE_PREPARED ) // wait for measurement &lt;BR /&gt; {&lt;BR /&gt; }&lt;BR /&gt; &lt;BR /&gt; if(FREQUENCY_TOO_LOW){&lt;BR /&gt; Fre=0;&lt;BR /&gt; }&lt;BR /&gt; else Fre=period/16000000;&lt;/P&gt;&lt;P&gt;asm nop; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// only for debug purposes for brkpnt&lt;BR /&gt; } /* loop forever */&lt;BR /&gt; /* please make sure that you never leave main */&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 03 Dec 2018 09:14:22 GMT</pubDate>
    <dc:creator>qianoocheng</dc:creator>
    <dc:date>2018-12-03T09:14:22Z</dc:date>
    <item>
      <title>About input capture question</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/About-input-capture-question/m-p/827130#M15931</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;&amp;nbsp; &amp;nbsp; I,m using S12ZVC64 for capture square wave's frequency and duty。&lt;/SPAN&gt;&lt;SPAN style="color: #222222; background-color: #f5f5f5; border: 0px;"&gt;&amp;nbsp;The input frequency is between 10Hz and 3000Hz&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;。&lt;/SPAN&gt;but it not work.just use PT5 as single input , when &lt;SPAN&gt;&amp;nbsp;The input frequency is 1000Hz,&lt;/SPAN&gt;&amp;nbsp;if dubug the code，it just join in the interrupt one time.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#include &amp;lt;hidef.h&amp;gt; /* for EnableInterrupts macro */&lt;BR /&gt;#include "derivative.h" /* include peripheral declarations */&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;#define TIMER_PRESCALER 1 // 1,2,4,8,16,32,64,128&lt;BR /&gt;#define MAX_OVERFLOWS 1000L // max. allowed number of TIM overflows&lt;BR /&gt;#define NEW_VALUE_PREPARED Flags.bit.f0 // info for sending data&lt;BR /&gt;#define FREQUENCY_TOO_LOW Flags.bit.f1 // mesured frequency is lower thannot measurablelower than&lt;BR /&gt;#define FIRST_EDGE 1&lt;BR /&gt;#define SECOND_EDGE 0&lt;BR /&gt;#define STOP_MEASUREMENT 3&lt;BR /&gt;#define TIM0_Channel5_VEC_OFF 0x1B8&lt;BR /&gt;#define TIM0_Overflow_VEC_OFF 0x1AC&lt;/P&gt;&lt;P&gt;#define SET_INTERRUPT_PRIORITY(vec_off, priority) \&lt;BR /&gt; INT_CFADDR= (vec_off/4) &amp;amp; 0xF8; \&lt;BR /&gt; INT_CFDATA_ARR[(vec_off/4) &amp;amp; 0x03]= (priority)&lt;/P&gt;&lt;P&gt;//----- DEPENDENT DEFINITIONS -----&lt;BR /&gt;#if TIMER_PRESCALER==1&lt;BR /&gt;#define PRESCALER 0&lt;BR /&gt;#endif&lt;BR /&gt;#if TIMER_PRESCALER==2&lt;BR /&gt;#define PRESCALER 1&lt;BR /&gt;#endif&lt;BR /&gt;#if TIMER_PRESCALER==4&lt;BR /&gt;#define PRESCALER 2&lt;BR /&gt;#endif&lt;BR /&gt;#if TIMER_PRESCALER==8&lt;BR /&gt;#define PRESCALER 3&lt;BR /&gt;#endif&lt;BR /&gt;#if TIMER_PRESCALER==16&lt;BR /&gt;#define PRESCALER 4&lt;BR /&gt;#endif&lt;BR /&gt;#if TIMER_PRESCALER==32&lt;BR /&gt;#define PRESCALER 5&lt;BR /&gt;#endif&lt;BR /&gt;#if TIMER_PRESCALER==64&lt;BR /&gt;#define PRESCALER 6&lt;BR /&gt;#endif&lt;BR /&gt;#if TIMER_PRESCALER==128&lt;BR /&gt;#define PRESCALER 7&lt;BR /&gt;#endif&lt;BR /&gt;//&lt;/P&gt;&lt;P&gt;/*******************************************************************************&lt;BR /&gt; * Local types&lt;BR /&gt; ******************************************************************************/&lt;BR /&gt;typedef unsigned char UBYTE;&lt;BR /&gt;typedef char SBYTE;&lt;BR /&gt;typedef unsigned int UWORD;&lt;BR /&gt;typedef int SWORD;&lt;BR /&gt;typedef unsigned long ULONG;&lt;BR /&gt;typedef long SLONG;&lt;BR /&gt;typedef union Flags&lt;BR /&gt;{&lt;BR /&gt; UBYTE byte;&lt;BR /&gt; struct&lt;BR /&gt; {&lt;BR /&gt; UBYTE f0 :1;&lt;BR /&gt; UBYTE f1 :1;&lt;BR /&gt; UBYTE f2 :1;&lt;BR /&gt; UBYTE f3 :1;&lt;BR /&gt; UBYTE f4 :1;&lt;BR /&gt; UBYTE f5 :1;&lt;BR /&gt; UBYTE f6 :1;&lt;BR /&gt; UBYTE f7 :1;&lt;BR /&gt; } bit;&lt;BR /&gt;} FLAGS;&lt;BR /&gt;static void IOC5_Init(void);&lt;BR /&gt;static void PLL_Init(void);&lt;BR /&gt;void GPIO_Init(void);&lt;BR /&gt;/*******************************************************************************&lt;BR /&gt; * Local variables&lt;BR /&gt; ******************************************************************************/&lt;BR /&gt;static ULONG period; // calcualted period between two rising edges&lt;BR /&gt;static UWORD ch0ovfCnt; // the number of main timer overflows between&lt;/P&gt;&lt;P&gt;volatile FLAGS Flags; // general purpose flags &lt;BR /&gt;// rising edges&lt;BR /&gt;static UWORD tFirstEdge = 0; // value of the timer when period starts&lt;BR /&gt;static UWORD tSecondEdge= 0; // value of the timer when period finishes&lt;BR /&gt;//static UBYTE mPhase;&lt;BR /&gt;static UBYTE mPhase = STOP_MEASUREMENT;&lt;BR /&gt;static UWORD Fre;&lt;/P&gt;&lt;P&gt;static void PLL_Init(void){&lt;BR /&gt; //USE External Power 0x06 not use:0x05&lt;BR /&gt; CPMUVREGCTL = 0x06; //Internal voltage regulator for VDDX domain&lt;BR /&gt; //CPMUVREGCTL = 0x05; //Internal voltage regulator for VDDX domain&lt;BR /&gt; &lt;BR /&gt; CPMUCLKS_PLLSEL = 1; //FBUS = FPLL/2. FBUS = 16MHz, &lt;BR /&gt; CPMUREFDIV_REFFRQ = 0x00; //Reference clock between 2MHZ and 6MHZ. &lt;BR /&gt; CPMUREFDIV_REFDIV = 0x3; //FREF=8/(1+3) = 2MHZ &lt;BR /&gt; //00: 32MHz &amp;lt;= fVCO &amp;lt;= 48MHz&lt;BR /&gt; //01: 48MHz &amp;lt; fVCO &amp;lt;= 64MHz&lt;BR /&gt; CPMUSYNR_VCOFRQ = 0x00; //FVCO is between 48MHZ and 80MHZ &lt;BR /&gt; CPMUSYNR_SYNDIV = 0x7; //FVCO = 2xFREFx(SYNDIV+1) = FVCO = 2x2x(7+1) = 32MHZ&lt;BR /&gt; CPMUPOSTDIV_POSTDIV = 0x1;//FPLL = FVCO/(POSTDIV+1). FPLL = 32MHZ/(0+1) FPLL = 32MHz &lt;BR /&gt; &lt;BR /&gt; CPMUOSC_OSCE = 1;//External oscillator enable. 8MHZ. FREF=FOSC/(REFDIV+1) &lt;BR /&gt; while (!CPMUIFLG_LOCK) {} // Wait for LOCK. &lt;BR /&gt; CPMUIFLG = 0xFF;// clear CMPMU int flags - not needed but good practice &lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; //浣胯兘RTI 涓柇&lt;BR /&gt; // Source IRCLOCK 1M &lt;BR /&gt; //0x80:1ms 0x81:2ms 0x82:5ms 0x83: 10ms 0x84:20ms&lt;BR /&gt; CPMURTI=0x80; // 璁剧疆RTICTL涓?0101 1001 婧㈠嚭鍛ㄦ湡涓?(9+1)*2^(15)/(32M)= 10*2^15/(32M) &lt;BR /&gt; CPMUINT_RTIE=1; // 鍏佽鍦ㄦ瘡涓懆鏈熺粨鏉熶骇鐢熶腑鏂?&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;static void IOC5_Init(void){&lt;BR /&gt; &lt;BR /&gt; PERT_PERT5 = 1; // an internal pull resitor enable&lt;BR /&gt; PPST_PPST5 = 0; // an internal pull up connected&lt;BR /&gt; TIM0TIOS_IOS5 = 0x00; //指定通道5为输入捕捉方式&lt;BR /&gt; TIM0TCTL3_EDG5A = 0x01;&lt;BR /&gt; TIM0TCTL3_EDG5B = 0x0;&lt;BR /&gt; &lt;BR /&gt; //TIM1 16M&lt;BR /&gt; //32M/2 = 8M&lt;BR /&gt; TIM0TSCR2_PR = 0x01; // 16M/ 1^1 = 16M&lt;BR /&gt; TIM0TIE_C5I = 0x0; // 允许通道5定时中断&lt;BR /&gt; TIM0TSCR2_TOI = 0; &lt;BR /&gt; TIM0TSCR1 = 0x60; &lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;#pragma CODE_SEG NON_BANKED&lt;BR /&gt;interrupt VectorNumber_Vtim0ch5 void vectorNumber_Vtim0ch5(void){&lt;BR /&gt; unsigned int ttt, tof;&lt;BR /&gt; tof = TIM0TFLG2_TOF; // check whether additional TOF appeared&lt;BR /&gt; ttt = TIM0TC5; // get TCNT value&lt;BR /&gt; if( mPhase == FIRST_EDGE )&lt;BR /&gt; {&lt;BR /&gt; // what happens if ovfs happened while going to this interrupt?...solution&lt;BR /&gt; if( tof )&lt;BR /&gt; { // a new period has already started&lt;BR /&gt; if( ttt &amp;lt; 32768 ) TIM0TFLG2_TOF = 1; // clear ovf interrupt flag&lt;BR /&gt; }&lt;BR /&gt; ch0ovfCnt = 0; // reset overflows counter&lt;BR /&gt; //--------------------------&lt;BR /&gt; tFirstEdge = ttt; // get first edge value&lt;BR /&gt; mPhase = SECOND_EDGE; // set configuration to get second edge&lt;BR /&gt; TIM0TFLG1_C5F = 1; // clear interrupt flag from PT5&lt;BR /&gt; return; // go back to wait for second edge&lt;BR /&gt; }&lt;BR /&gt; else&lt;BR /&gt; {&lt;BR /&gt; // what happens if ovfs happened while going to this interrupt?...solution&lt;BR /&gt; if( tof )&lt;BR /&gt; { // a new period has already started&lt;BR /&gt; if( ttt &amp;lt; 32768 ) ch0ovfCnt++; &lt;BR /&gt; }&lt;BR /&gt; //--------------------------&lt;/P&gt;&lt;P&gt;tSecondEdge = ttt; // read new captured value and clear flag&lt;BR /&gt; // stop measurement&lt;BR /&gt; TIM0TSCR2_TOI = 0; // disable ovf interrupt&lt;BR /&gt; TIM0TIE_C5I = 0; // disable Ch5 interrupt &lt;BR /&gt; TIM0TFLG1_C5F = 1; // clear interrupt flag from PT5&lt;BR /&gt; }&lt;BR /&gt; // Ch0 period calculation&lt;BR /&gt; if( !ch0ovfCnt ) // Did edges appear within one timer period?&lt;BR /&gt; {&lt;BR /&gt; period = ( ULONG ) ( tSecondEdge - tFirstEdge );&lt;BR /&gt; }&lt;BR /&gt; else // some number of overflows has appeared between two edges&lt;BR /&gt; {&lt;BR /&gt; // time given by overflows period=....&lt;BR /&gt; period = ( ULONG ) ( ~tFirstEdge + 1 ); // time in the first period&lt;BR /&gt; period += ( ULONG ) ( tSecondEdge ); // time in the last period&lt;BR /&gt; period += ( ULONG ) (( ULONG ) ( ch0ovfCnt - 1 ) * ( ULONG ) ( 65536 ));&lt;BR /&gt; }&lt;BR /&gt; NEW_VALUE_PREPARED = TRUE; // information for main routine &lt;BR /&gt;}&lt;BR /&gt;#pragma CODE_SEG DEFAULT&lt;/P&gt;&lt;P&gt;#pragma CODE_SEG NON_BANKED&lt;BR /&gt;interrupt VectorNumber_Vtim0ovf void TIM0_Overflow_ISR(void) { &lt;BR /&gt; &lt;BR /&gt; ch0ovfCnt++; // count overflows&lt;/P&gt;&lt;P&gt;if( ch0ovfCnt &amp;gt; MAX_OVERFLOWS )&lt;BR /&gt; {&lt;BR /&gt; ch0ovfCnt = 0;&lt;BR /&gt; FREQUENCY_TOO_LOW = TRUE;&lt;BR /&gt; // stop measurement&lt;BR /&gt; TIM0TSCR2_TOI = 0; // disable ovf interrupt&lt;BR /&gt; TIM0TIE_C5I = 0; // disable Ch5 interrupt &lt;BR /&gt; TIM0TFLG1_C5F = 1; // clear interrupt flag from PT5&lt;BR /&gt; NEW_VALUE_PREPARED = TRUE; // information for main routine &lt;BR /&gt; }&lt;BR /&gt; else&lt;BR /&gt; {&lt;BR /&gt; FREQUENCY_TOO_LOW = FALSE;&lt;BR /&gt; }&lt;BR /&gt; TIM0TFLG2_TOF = 0x1; &lt;BR /&gt; &lt;BR /&gt;}&lt;BR /&gt;#pragma CODE_SEG DEFAULT&lt;BR /&gt;void GPIO_Init(void){&lt;BR /&gt; &lt;BR /&gt; //=== GPIO INIT ================&lt;BR /&gt; DDRT_DDRT5 = 0; // PT5 input port&lt;BR /&gt; PERT_PERT5 = 1; // Pull resistor enabled at PT5&lt;BR /&gt; PPST_PPST5 = 1; // Pull down selected at PT5&lt;BR /&gt; &lt;BR /&gt; DDRS_DDRS6 = 1; // output port&lt;BR /&gt; PTS_PTS6 = 0; // output port&lt;BR /&gt;}&lt;BR /&gt;void main(void) {&lt;BR /&gt; PLL_Init();&lt;BR /&gt; GPIO_Init();&lt;BR /&gt; FREQUENCY_TOO_LOW = TRUE; // set flag&lt;BR /&gt; NEW_VALUE_PREPARED = FALSE; // set flag&lt;BR /&gt; SET_INTERRUPT_PRIORITY(TIM0_Channel5_VEC_OFF, 7); // max priority&lt;BR /&gt; SET_INTERRUPT_PRIORITY(TIM0_Overflow_VEC_OFF, 6); // less priority than IC0&lt;BR /&gt; IOC5_Init();&lt;BR /&gt; &lt;BR /&gt; TIM0TSCR2_TOI = 1;&lt;BR /&gt; TIM0TIE_C5I = 0x01; // 允许通道2定时中断&lt;BR /&gt; EnableInterrupts;&lt;BR /&gt; /* include your code here */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for(;;) {&lt;BR /&gt; // __RESET_WATCHDOG(); /* feeds the dog */&lt;BR /&gt; &lt;BR /&gt; FREQUENCY_TOO_LOW = FALSE; // clear flag&lt;BR /&gt; NEW_VALUE_PREPARED = FALSE; // set flag&lt;BR /&gt; ch0ovfCnt = 0; // clear number of ovfs interrupts&lt;BR /&gt; TIM0TFLG1_C5F = 1; // clear interrupt flag from PT0&lt;BR /&gt; TIM0TFLG2_TOF = 0x1; // clear interrupt TOV flag&lt;BR /&gt; mPhase = FIRST_EDGE; // prepare processing of a first edge&lt;BR /&gt; TIM0TSCR1_TEN = 1; // run timer&lt;BR /&gt; TIM0TIE_C5I = 1; // enable Ch5 interrupt &lt;BR /&gt; TIM0TSCR2_TOI = 1; // enable ovf interrupt &lt;BR /&gt; while( !NEW_VALUE_PREPARED ) // wait for measurement &lt;BR /&gt; {&lt;BR /&gt; }&lt;BR /&gt; &lt;BR /&gt; if(FREQUENCY_TOO_LOW){&lt;BR /&gt; Fre=0;&lt;BR /&gt; }&lt;BR /&gt; else Fre=period/16000000;&lt;/P&gt;&lt;P&gt;asm nop; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// only for debug purposes for brkpnt&lt;BR /&gt; } /* loop forever */&lt;BR /&gt; /* please make sure that you never leave main */&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Dec 2018 09:14:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/About-input-capture-question/m-p/827130#M15931</guid>
      <dc:creator>qianoocheng</dc:creator>
      <dc:date>2018-12-03T09:14:22Z</dc:date>
    </item>
    <item>
      <title>Re: About input capture question</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/About-input-capture-question/m-p/827131#M15932</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have just run your code, disabled the&amp;nbsp;RTI interrupt because you don't have the routine in the code and it works.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Both the variable&amp;nbsp;tFirstEdge and&amp;nbsp;tSecondEdge get updated.&lt;/P&gt;&lt;P&gt;Do you have any update? Have you solved it already?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Dec 2018 12:32:20 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/About-input-capture-question/m-p/827131#M15932</guid>
      <dc:creator>danielmartynek</dc:creator>
      <dc:date>2018-12-10T12:32:20Z</dc:date>
    </item>
  </channel>
</rss>

