Hi all!
I am trying to sample two channels with ADC0 on Kinetis K66 (MK66FN2).
I have configure the ADC to be triggered by TPM1:
tmp32 = SIM->SOPT7 & ~(SIM_SOPT7_ADC0TRGSEL_MASK | SIM_SOPT7_ADC1TRGSEL_MASK);
tmp32 |= SIM_SOPT7_ADC1ALTTRGEN_MASK | SIM_SOPT7_ADC1TRGSEL(15U) | SIM_SOPT7_ADC0ALTTRGEN_MASK | SIM_SOPT7_ADC0TRGSEL(15U);
SIM->SOPT7 = tmp32;
TPM1 is configured with a period of 8us, triggering the two ADC channels in alternating fashion:
tpm_config_t tpmConfig;
CLOCK_SetTpmClock(1U);
CLOCK_SetPllFllSelClock(1,0,0);
TPM_GetDefaultConfig(&tpmConfig);
TPM_Init(TPM1, &tpmConfig);
TPM_SetTimerPeriod(TPM1, 960); // equals 8us at 120 MHz
TPM_SetupOutputCompare(TPM1, kTPM_Chnl_0, kTPM_HighPulseOutput, 0);
TPM_SetupOutputCompare(TPM1, kTPM_Chnl_1, kTPM_HighPulseOutput, 480);
The ADC results are transfered using DMA. DMA is also triggered by TPM1:
TPM1->CONTROLS[kTPM_Chnl_0].CnSC |= TPM_CnSC_DMA_MASK;
TPM1->CONTROLS[kTPM_Chnl_1].CnSC |= TPM_CnSC_DMA_MASK;
Now the problem is, that the ADC samples after I turn off TPM1 via
TPM_StopTimer(TPM1);
I observed this by turning a GPIO pin on and off in the conversion complete ISR of the ADC. Additionally I also turn a pin on and off in the overflow ISR of TPM1 and I am able to observe the pulses using an oscilloscope.
Does anyone have an idea why the timer runs and fires after I stop it?