/*! * @Brief enable the trigger source * * @param instance The ADC instance number */ void adc16InitPitTriggerSource(uint32_t adcInstance) { /* Change the timer period here in unit of microseconds.*/ uint32_t timerPeriod = 500; uint32_t pitInstance = BOARD_PIT_INSTANCE; uint32_t pitChannel = 0; if(sPdbInitialized) { return; } sPdbInitialized = 1; pitUserConf.isInterruptEnabled = false; pitUserConf.periodUs = timerPeriod; /* Init pit module and enable run in debug */ PIT_DRV_Init(pitInstance, false); /* Initialize PIT timer 0 */ PIT_DRV_InitChannel(pitInstance, pitChannel, &pitUserConf); /* Set timer0 period and start it.*/ PIT_DRV_SetTimerPeriodByUs(pitInstance, pitChannel, timerPeriod * 1000); // Configure SIM for ADC hw trigger source PIT SIM_HAL_SetAdcAlternativeTriggerCmd(gSimBase[0], adcInstance, true); SIM_HAL_SetAdcTriggerMode(gSimBase[0], adcInstance, kSimAdcTrgSelPit0); PIT_DRV_StartTimer(pitInstance, pitChannel); }
/*! * @Brief enable the trigger source */ void init_trigger_source(uint32_t adcInstance) { pdb_adc_pre_trigger_config_t pdbAdcTriggerConfig; pdb_user_config_t pdbUserConfig; pdb_clk_prescaler_div_mode_t divMode = kPdbClkPreDivBy64; uint32_t busClock, modValue; uint8_t preDivider = 1 << divMode; // get the bus clock freq which for PDB CLOCK_SYS_GetFreq(kBusClock, &busClock); // calculate for MOD value modValue = INPUT_SIGNAL_FREQ*NR_SAMPLES; modValue = busClock/preDivider/modValue*4; // init the pdb user config structure for // enable SW trigger, enable continuous mode, // set the correct MOD and DLY // Enable the sequency error interrupt. PDB_DRV_StructInitUserConfigForSoftTrigger(&pdbUserConfig); pdbUserConfig.continuousModeEnable = true; pdbUserConfig.pdbModulusValue = modValue; pdbUserConfig.intEnable = true; pdbUserConfig.seqErrIntEnable = true; pdbUserConfig.clkPrescalerDivMode = divMode; pdbUserConfig.multFactorMode = kPdbMultFactorAs1; // Initialize PDB driver PDB_DRV_Init(0, &pdbUserConfig); // Configure the PDB channel for ADC_adcInstance // disable BACK to BACK mode pdbAdcTriggerConfig.backToBackModeEnable = false; // enable pretrigger out pdbAdcTriggerConfig.preTriggerOutEnable = true; pdbAdcTriggerConfig.delayValue = modValue/4; // Configure the pre trigger A for ADC PDB_DRV_EnableAdcPreTrigger(0, adcInstance, 0, &pdbAdcTriggerConfig); // the Pre-trigger A delay is set to 1/4 MOD, // the Pre-trigger B delay is set to 3/4 MOD, // so the trigger interval between A/B, B/A is same. pdbAdcTriggerConfig.delayValue = modValue*3/4; // Configure the pre trigger B for ADC PDB_DRV_EnableAdcPreTrigger(0, adcInstance, 1, &pdbAdcTriggerConfig); // Configure SIM for ADC hw trigger source PDB SIM_HAL_SetAdcAlternativeTriggerCmd(gSimBase[0], adcInstance, false); // Trigger the PDB, let it go in continuous mode PDB_DRV_SoftTriggerCmd(0); }
/*! * @Brief enable the trigger source of LPTimer */ void init_trigger_source(uint32_t adcInstance) { uint32_t freqUs; lptmr_user_config_t lptmrUserConfig = { .timerMode = kLptmrTimerModeTimeCounter, .freeRunningEnable = false, .prescalerEnable = false, // bypass perscaler #if (CLOCK_INIT_CONFIG == CLOCK_VLPR) // use MCGIRCCLK, 4M or 32KHz .prescalerClockSource = kClockLptmrSrcMcgIrClk, #else // Use LPO clock 1KHz .prescalerClockSource = kClockLptmrSrcLpoClk, #endif .isInterruptEnabled = false }; // Init LPTimer driver LPTMR_DRV_Init(0, &gLPTMRState, &lptmrUserConfig); // Set the LPTimer period freqUs = 1000000U/(INPUT_SIGNAL_FREQ*NR_SAMPLES)*2; LPTMR_DRV_SetTimerPeriodUs(0, freqUs); // Start the LPTimer LPTMR_DRV_Start(0); // Configure SIM for ADC hw trigger source selection #if defined(KM34Z7_SERIES) SIM_HAL_EnableClock(gSimBase[0], kSimClockGateXbar0); SIM_HAL_SetAdcTrgSelMode(gSimBase[0], kSimAdcTrgSelXbar); XBAR_DRV_ConfigSignalConnection(kXbaraInputLPTMR0_Output, kXbaraOutputADC_TRGA); #else SIM_HAL_SetAdcAlternativeTriggerCmd(gSimBase[0], adcInstance, true); SIM_HAL_SetAdcPreTriggerMode(gSimBase[0], adcInstance, kSimAdcPretrgselA); SIM_HAL_SetAdcTriggerMode(gSimBase[0], adcInstance, kSimAdcTrgSelLptimer); #endif } /*! * @Brief disable the trigger source */ void deinit_trigger_source(uint32_t adcInstance) { LPTMR_DRV_Stop(0); LPTMR_DRV_Deinit(0); }
/*! * @Brief enable the trigger source of LPTimer */ void init_trigger_source(uint32_t adcInstance) { uint32_t freqUs; lptmr_user_config_t lptmrUserConfig = { .timerMode = kLptmrTimerModeTimeCounter, .freeRunningEnable = false, .prescalerEnable = false, // bypass perscaler .prescalerClockSource = kClockLptmrSrcMcgIrClk, // use MCGIRCCLK, 4M or 32KHz .isInterruptEnabled = false }; // Init LPTimer driver LPTMR_DRV_Init(0, &lptmrUserConfig, &gLPTMRState); // Set the LPTimer period freqUs = 1000000U/(INPUT_SIGNAL_FREQ*NR_SAMPLES)*2; LPTMR_DRV_SetTimerPeriodUs(0, freqUs); // Start the LPTimer LPTMR_DRV_Start(0); // Configure SIM for ADC hw trigger source selection SIM_HAL_SetAdcAlternativeTriggerCmd(gSimBase[0], adcInstance, true); SIM_HAL_SetAdcPreTriggerMode(gSimBase[0], adcInstance, kSimAdcPretrgselA); SIM_HAL_SetAdcTriggerMode(gSimBase[0], adcInstance, kSimAdcTrgSelLptimer); } /*! * @Brief disable the trigger source */ void deinit_trigger_source(uint32_t adcInstance) { LPTMR_DRV_Stop(0); LPTMR_DRV_Deinit(0); }