Dear sir,
Can you help me about ADC1 convert time in S32K144?
I follow the link below,https://community.nxp.com/t5/NXP-Model-Based-Design-Tools/s32k144-PWM-to-ADC-sync/m-p/1032279#M4217 , configured my FTM0/PDB1 to trigger ADC1, attemp to sync adc1 convert data to a PWM signal(100KHz) which generated by FTM0.
My code as below:
int main(void)
{
ftm_state_t ftmStateStruct;
CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT,
g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT);
PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);
TRGMUX_DRV_Init(INST_TRGMUX1, &trgmux1_InitConfig0);
PCC->PCCn[PCC_PDB1_INDEX] |= PCC_PCCn_CGC_MASK; /* Enable bus clock in PDB1 */
PDB_DRV_Init(INST_PDB1, &pdb1_InitConfig0);
PDB_DRV_Enable(INST_PDB1);
// config 8 pretriggers on ch0 based on component setting
PDB_DRV_ConfigAdcPreTrigger(INST_PDB1, 0UL, &pdb1_AdcTrigInitConfig0);
PDB_DRV_SetTimerModulusValue(INST_PDB1, 30); //
// set ch0 trigger0 delay to happen immediate upon Trigger_In 0 (PIT0 ch0)
PDB_DRV_SetAdcPreTriggerDelayValue(INST_PDB1, 0UL, 0UL, 30);
//PDB_DRV_SetCmpPulseOutDelayForHigh(INST_PDB1, 0L , 0);
//PDB_DRV_SetCmpPulseOutDelayForLow(INST_PDB1, 0L, 75);
//PDB_DRV_SetCmpPulseOutEnable(INST_PDB1, 1<<0, true);
PDB_DRV_LoadValuesCmd(INST_PDB1);
INT_SYS_InstallHandler(PDB1_IRQn, &PDB1_IRQHandler, (isr_t *)0);
INT_SYS_EnableIRQ(PDB1_IRQn);
ADC_DRV_ConfigConverter(INST_ADC1, &adc1_ConvConfig0);
ADC_DRV_ConfigChan(INST_ADC1,0, &adc1Channel)
FTM_DRV_Init(INST_FLEXTIMER_PWM1, &flexTimer_pwm1_InitConfig, &ftmStateStruct );
FTM_DRV_InitPwm(INST_FLEXTIMER_PWM1, &flexTimer_pwm1_PwmConfig);
INT_SYS_InstallHandler(ADC1_IRQn,&ADC1_IRQHandler,(isr_t *)0);
INT_SYS_EnableIRQ(ADC1_IRQn);
INT_SYS_EnableIRQGlobal();
while(1)
{
}
}
void ADC1_IRQHandler()
{
ADC_DRV_GetChanResult(INST_ADDEMOD, 0, &ADC1_res);
convert_success = TRUE;
}
void PDB1_IRQHandler(void)
{
//PDB1->SC &= ~0x00000040; //PDBIF w0c
if((PDB1->CH[0].S & 0x00000001)==0x1)
{
PDB1->CH[0].S &= 0xFFFFFFFE;
}
}
PDB1 delay = 1/48MHz * 30 = 0.625us
ADC1 Clock = 48M, SMPLTS=12, 8-bit Mode, No HW average, ONLY sample one channel. According to S32K-RM, ADC Convert time = (12+1)+1+20+5+5 = 38 ADC cycles + 5 bus clock cycles = 43 /48M = 0.895us
BUT, I found it will go into PDB1 sequence error interrupt handler. Then until I reduce the PWM frequence to 2KHz, it will never go into the sequence error INT handler. I think it means the FTM0-TRGMUX-PDB1-ADC1 will cost at lease 500us. I want to know WHY.
Hello,
The calculation of a single ADC conversion time is correct.
But I would recommend routing the FTM trigger to a TRGMUX_OUTn pin as well and measuring the period of the trigger so that you can be sure this is correct.
Also, some ADC COCO triggers can be routed to TRGMUX_OUTn pins.
Can you attach the whole project or a test code that would replicate the issue?
Regards,
Daniel
Dear Daniel,
Thanks for your reply. My project is attached.
I toggle PD7 as test pin when ADC1 Interrupt and toggle again after read ADC1 data. Channel 0,1,2,3 are combine PWM, channel 4 is PD7.
If I change PWM frequency up to 100KHz, there will be a sequence error.
Look forward to your reply!Thanks very much!
Hello,
Thank you for the project, but for some reason, I'm not able to run it.
I guess you use an old version of the Design Studio.
Can you show PDB registers after configuration?
Thanks,
BR, Daniel