void PDB_QuickInit(PDB_TriggerSrc_Type triggerSrc, uint32_t timeInUs) { uint32_t clock; PDB_InitTypeDef PDB_InitStruct1; CLOCK_GetClockFrequency(kBusClock, &clock); PDB_InitStruct1.inputTrigSource = kPDB_SoftwareTrigger; /* software Trigger */ PDB_InitStruct1.isContinuesMode = true; PDB_InitStruct1.srcClock = clock; PDB_InitStruct1.timeInUs = timeInUs; PDB_Init(&PDB_InitStruct1); }
/*! * @brief Main function */ int main(void) { pdb_config_t pdbConfigStruct; pdb_adc_pretrigger_config_t pdbAdcPreTriggerConfigStruct; BOARD_InitPins(); BOARD_BootClockRUN(); BOARD_InitDebugConsole(); EnableIRQ(DEMO_PDB_IRQ_ID); EnableIRQ(DEMO_ADC_IRQ_ID); PRINTF("\r\nPDB ADC16 Pre-Trigger Example.\r\n"); /* Configure the PDB counter. */ /* * pdbConfigStruct.loadValueMode = kPDB_LoadValueImmediately; * pdbConfigStruct.prescalerDivider = kPDB_PrescalerDivider1; * pdbConfigStruct.dividerMultiplicationFactor = kPDB_DividerMultiplicationFactor1; * pdbConfigStruct.triggerInputSource = kPDB_TriggerSoftware; * pdbConfigStruct.enableContinuousMode = false; */ PDB_GetDefaultConfig(&pdbConfigStruct); PDB_Init(DEMO_PDB_BASE, &pdbConfigStruct); /* Configure the delay interrupt. */ PDB_SetModulusValue(DEMO_PDB_BASE, 1000U); /* The available delay value is less than or equal to the modulus value. */ PDB_SetCounterDelayValue(DEMO_PDB_BASE, 1000U); PDB_EnableInterrupts(DEMO_PDB_BASE, kPDB_DelayInterruptEnable); /* Configure the ADC Pre-Trigger. */ pdbAdcPreTriggerConfigStruct.enablePreTriggerMask = 1U << DEMO_PDB_ADC_PRETRIGGER_CHANNEL; pdbAdcPreTriggerConfigStruct.enableOutputMask = 1U << DEMO_PDB_ADC_PRETRIGGER_CHANNEL; pdbAdcPreTriggerConfigStruct.enableBackToBackOperationMask = 0U; PDB_SetADCPreTriggerConfig(DEMO_PDB_BASE, DEMO_PDB_ADC_TRIGGER_CHANNEL, &pdbAdcPreTriggerConfigStruct); PDB_SetADCPreTriggerDelayValue(DEMO_PDB_BASE, DEMO_PDB_ADC_TRIGGER_CHANNEL, DEMO_PDB_ADC_PRETRIGGER_CHANNEL, 200U); /* The available Pre-Trigger delay value is less than or equal to the modulus value. */ PDB_DoLoadValues(DEMO_PDB_BASE); /* Configure the ADC. */ DEMO_InitPDB_ADC(); g_PdbDelayInterruptCounter = 0U; g_AdcInterruptCounter = 0U; while (1) { PRINTF("\r\nType any key into terminal to trigger the PDB and then trigger the ADC's conversion ...\r\n"); GETCHAR(); g_PdbDelayInterruptFlag = false; g_AdcInterruptFlag = false; PDB_DoSoftwareTrigger(DEMO_PDB_BASE); while ((!g_PdbDelayInterruptFlag) || (!g_AdcInterruptFlag)) { } PRINTF("\r\n"); PRINTF("PDB Interrupt Counter: %d\r\n", g_PdbDelayInterruptCounter); PRINTF("ADC Conversion Interrupt Counter: %d\r\n", g_AdcInterruptCounter); PRINTF("ADC Conversion Value: %d\r\n", g_AdcConvValue); } }