Download Kinetis Quick Reference User Guide
Transcript
Configuration example 6. Calibrate the ADCs in the configuration in which they will be used and then restore the desired configuration. 7. Enable the ADC and PDB interrupts in NVIC. 8. Software trigger the PDB. The PDB will then start triggering the ADC as it times the intervals. 9. Handle the PDB, ADC0, and ADC1 interrupts. 18.2.1.1 Turn on ADC and PDB clocks Example Code from the adc_demo project: Clocks need to be turned on to the ADC and PDB using the SIM module: // Turn on SIM_SCGC6 SIM_SCGC3 SIM_SCGC6 the ADC0 and ADC1 clocks as well as the PDB clocks to test ADC triggered by PDB |= (SIM_SCGC6_ADC0_MASK ); |= (SIM_SCGC3_ADC1_MASK ); |= SIM_SCGC6_PDB_MASK ; 18.2.1.2 Configure System Integration module for ADC defaults SIM_SOPT7 &= ~(SIM_SOPT7_ADC1ALTTRGEN_MASK | // selects PDB not ALT trigger SIM_SOPT7_ADC1PRETRGSEL_MASK | SIM_SOPT7_ADC0ALTTRGEN_MASK | // selects PDB not ALT trigger SIM_SOPT7_ADC0ALTTRGEN_MASK) ; SIM_SOPT7 = SIM_SOPT7_ADC0TRGSEL(0); // applies only in case of ALT trigger, in which case // PDB external pin input trigger for ADC SIM_SOPT7 = SIM_SOPT7_ADC1TRGSEL(0); // same for both ADCs 18.2.1.3 Configure Peripheral Delay Block (PDB) // Configure the Peripheral Delay Block (PDB): // enable PDB, pdb counter clock = busclock / 20 , continuous triggers, sw trigger , and use prescaler too PDB_SC = PDB_SC_CONT_MASK // Continuous, rather than one-shot, mode | PDB_SC_PDBEN_MASK // PDB enabled | PDB_SC_PDBIE_MASK // PDB Interrupt Enable | PDB_SC_PRESCALER(0x5) // Slow down the period of the PDB for testing | PDB_SC_TRGSEL(0xf) // Trigger source is Software Trigger to be invoked in this file | PDB_SC_MULT(2); // Multiplication factor 20 for the prescale divider for the counter clock // the software trigger, PDB_SC_SWTRIG_MASK is not triggered at this time. PDB_IDLY = 0x0000; modulus reached // need to trigger interrupt every counter reset which happens when PDB_MOD = 0xffff; see each conversion. // largest period possible with the selections above, so slow you can // channel 0 pretrigger 0 and 1 enabled and delayed PDB_CH0C1 = PDB_CH0C1_EN(0x01) Kinetis Quick Reference User Guide, Rev. 0, 11/2010 170 Freescale Semiconductor