XBAR,QTMR,CMP line frequency detection

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

XBAR,QTMR,CMP line frequency detection

1,029 次查看
nickng
Contributor II

HI,

I would like ask if there is an example to use all the cmp (0,1,2) and TMR0,1,2 and DAC connected by XBAR in order to capture the 3 phase frequency .

I got a trouble on only Phase 1 is detected correctly by the timer TMR0-CAPT. the other two timers are always return me 0.

Phase 1 : CMP0 INT0  INT7 (DAC)

Phase 2 : CMP1 INT0  INT7 (DAC)

Phase 3 : CMP2 INT3  INT7 (DAC)

I got all the signals from cmp interrupt routine, by just phase 2 and 3 return 0 value of the TMRX-CAPT.

Which means the cmp did captured the signal but the TMR1 and TMR2 does not really counting.

Do I need to enable something at the SIM module?

      /* Select secondary source count from XBAR */
      SIM->MISC_CTL |= SIM_MISC_CTL_TMR0SCSEL(1);
      SIM->MISC_CTL |= SIM_MISC_CTL_TMR1SCSEL(1);
      SIM->MISC_CTL |= SIM_MISC_CTL_TMR2SCSEL(1);

   /*    config->debugMode = kQTMR_RunNormalInDebug;
    *    config->enableExternalForce = false;
    *    config->enableMasterMode = false;
    *    config->faultFilterCount = 0;
    *    config->faultFilterPeriod = 0;
    *    config->primarySource = kQTMR_ClockDivide_2;
    *    config->secondarySource = kQTMR_Counter0InputPin;*/
    QTMR_GetDefaultConfig(&qtmrConfig);

    /* Set clock prescaler */
    qtmrConfig.primarySource = kQTMR_ClockDivide_16;
    QTMR_Init(TMR0, &qtmrConfig);
//    qtmrConfig.secondarySource = kQTMR_Counter1InputPin;
    QTMR_Init(TMR1, &qtmrConfig);
//    qtmrConfig.secondarySource = kQTMR_Counter2InputPin;
    QTMR_Init(TMR2, &qtmrConfig);
    /* Set qtimer work in input capture mode */
    QTMR_SetupInputCapture(TMR0, kQTMR_Counter0InputPin, false, true, kQTMR_RisingEdge);
    QTMR_SetupInputCapture(TMR1, kQTMR_Counter0InputPin, false, true, kQTMR_RisingEdge);
    QTMR_SetupInputCapture(TMR2, kQTMR_Counter0InputPin, false, true, kQTMR_RisingEdge);

    CMP_GetDefaultConfig(&mCmpConfigStruct);
    mCmpConfigStruct.hysteresisMode = kCMP_HysteresisLevel2;
    mCmpConfigStruct.enableInvertOutput = true;
    /* Init the CMP comparator. */
    CMP_Init(CMP0, &mCmpConfigStruct);
    CMP_Init(CMP1, &mCmpConfigStruct);
    CMP_Init(CMP2, &mCmpConfigStruct);
    /* Configure the DAC channel. */
    mCmpDacConfigStruct.referenceVoltageSource = kCMP_VrefSourceVin2; /* VCC. */
    mCmpDacConfigStruct.DACValue = 8U;                               /* ref value = 8*3.3V/64 =412.5mV. */
    CMP_SetDACConfig( CMP0, &mCmpDacConfigStruct);
    CMP_SetDACConfig( CMP1, &mCmpDacConfigStruct);
    CMP_SetDACConfig( CMP2, &mCmpDacConfigStruct);


    /* Initialize the CMP comparator. */
    CMP_Init(CMP0, &mCmpConfigStruct);
    CMP_Init(CMP1, &mCmpConfigStruct);
    CMP_Init(CMP2, &mCmpConfigStruct);
    CMP_SetInputChannels(CMP0, 0, 7);// 0 = CMP0 INT0 7 = DAC
    CMP_SetInputChannels(CMP1, 0, 7);// 0 = CMP1 INT0 7 = DAC
    CMP_SetInputChannels(CMP2, 3, 7);// 0 = CMP2 INT3 7 = DAC

    XBAR_SetSignalsConnection(XBAR, kXBAR_InputCmp0Output , kXBAR_OutputTmrCh0SecInput);
    XBAR_SetSignalsConnection(XBAR, kXBAR_InputCmp1Output , kXBAR_OutputTmrCh1SecInput);
    XBAR_SetSignalsConnection(XBAR, kXBAR_InputCmp2Output , kXBAR_OutputTmrCh2SecInput);

    /* Configure the XBAR interrupt. */
    xbarConfig.activeEdge = kXBAR_EdgeRisingAndFalling;
    xbarConfig.requestType = kXBAR_RequestDisable;
    XBAR_SetOutputSignalConfig(XBAR, kXBAR_OutputTmrCh0SecInput, &xbarConfig);
    XBAR_SetOutputSignalConfig(XBAR, kXBAR_OutputTmrCh1SecInput, &xbarConfig);
    XBAR_SetOutputSignalConfig(XBAR, kXBAR_OutputTmrCh2SecInput, &xbarConfig);

标签 (1)
标记 (1)
0 项奖励
回复
1 回复

696 次查看
nickng
Contributor II

closed

NO problem. just because of wrong init sequence.

The capture started before init completed.

0 项奖励
回复