HELP, how to use PDB to trigger the ADC
Hello,
hope someone can help me with this problem. In an earlier program I have used the FTM timer to trigger the ADC and simultaneously used DMA to transfer to adc values to a memory field. The FTM was run in pwm mode at a frequency of about 76kHz (modulo 320). The channel 0 of FTM0 was used to generate square wave which modulated a LED. Apart from channel 0 I also used ch1,2,and 3. The channel value were 160, 240, 320 and 80 respectively. All channels of FTM0 were used to trigger the ADC. With this setup it was no problem for the ADC to convert upon receiving the trigger from the FTM.
However, I need to have triggers that are delayed by a certain period of time after the FTM triggers have occurred . So I used the PDB as the trigger for the ADC and the FTM to trigger the PDB. But by this way the adc seems not to convert. Probably it has not been triggered at all. Hope someone can give me some advices.
thanks
Hung
Here are the my configurations and codes. I used ksdk 1.2 and processor expert and kinetis design studio 3.0.
/* Including needed modules to compile this module/procedure */
#include "Cpu.h"
#include "Events.h"
#include "clockMan1.h"
#include "pin_init.h"
#include "osa1.h"
#include "daConv1.h"
#include "voltageRef1.h"
#include "i2cCom1.h"
#include "pdly1.h"
#if CPU_INIT_CONFIG
#include "Init_Config.h"
#endif
/* User includes (#include below this line is not maintained by Processor Expert) */
#include "SEGGER_RTT_Conf.h"
#include "SEGGER_RTT.h"
#include "DMA.h"
#include "ADC0.h"
#include <math.h>
#define chnGroup (0)
#define batch 150
volatile bool ad_wandeln=false, gemessen=false;
volatile uint16_t ft_zaehler=0;
uint16_t ad_wert_aktuell, ad_werte[2000]={0};
/*lint -save -e970 Disable MISRA rule (6.3) checking. */
int main(void)
/*lint -restore Enable MISRA rule (6.3) checking. */
{
/* Write your local variable definition here */
static uint16_t ad_index=0, cntr=0, zaehler=0;
uint16_t kalib_plus=0, kalib_minus=0;
static uint16_t pulsstar=0;
uint8_t widerstand=20, widerstand2=40;
i2c_status_t fehler_i2c;
bool bestaetigt,stop_gesendet;
//adc16_calibration_param_t adcCalibrationParam;
/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
PE_low_level_init();
/*** End of Processor Expert internal initialization. ***/
/* Write your code here */
/* For example: for(;;) { } */
// 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.
PDB_DRV_SetTimerModulusValue(FSL_PDLY1, 669U);
PDB_DRV_SetAdcPreTriggerDelayValue(FSL_PDLY1,1U,1U,10U);
//PDB_DRV_SetAdcPreTriggerDelayValue(0U, adcInstance, 0U, modValue/4);
//PDB_DRV_SetAdcPreTriggerDelayValue(0U, adcInstance, 1U, modValue*3/4);
PDB_DRV_LoadValuesCmd(FSL_PDLY1);
// Auto calibration
// adc16_calibration_param_t adcCalibrationParam;
//SIM_HAL_SetAdcAlternativeTriggerCmd(SIM_BASE_PTR,adcInstance,true);
DAC_DRV_Output(FSL_DACONV1,512);
//SIM_SOPT7|=0x000088; // alternative trigger ftm0 is selected instead of pdb trigger
OSA_TimeDelay(10);
// initialize ftm0
FTM0_Init();
// Initialize ADC
ADC0_Init();
ADC16_HAL_GetAutoCalibrationActiveFlag(ADC0_BASE_PTR);
ADC16_HAL_SetAutoCalibrationCmd(ADC0_BASE_PTR,true);
kalib_plus=ADC16_HAL_GetAutoPlusSideGainValue(ADC0_BASE_PTR);
kalib_minus=ADC16_HAL_GetAutoMinusSideGainValue(ADC0_BASE_PTR);
ADC16_HAL_SetPlusSideGainValue(ADC0_BASE_PTR, kalib_plus);
ADC16_HAL_SetMinusSideGainValue(ADC0_BASE_PTR,kalib_minus);
// Initialize DMA
DMA_Init();
for(;;)
{
// check if DMA cycle is finished
if (gemessen)
{
pulsstar++;
if(pulsstar>2)
{ EDMA_HAL_HTCDSetDisableDmaRequestAfterTCDDoneCmd(DMA_BASE_PTR,0,true);
for(zaehler=100;zaehler<=200;zaehler++)
{
//zaehler++;
SEGGER_RTT_printf(0,"%u\t",zaehler);
SEGGER_RTT_printf(0,"%u\n",ad_werte[zaehler]);
}
SEGGER_RTT_printf(0,"OK\n");
pulsstar=0;
}
gemessen=false;
}
}
….
/* END main
/*! adConv1 IRQ handler */
void DMA0_IRQHandler(void)
{
// Clear all DMA interrupt flags
DMA_CINT = 0x40;
batch_aktuell+=1000;
ad_addresse_aktuell=(uint32_t) &(ad_werte[batch_aktuell]);
DMA_TCD0_DADDR = ad_addresse_aktuell;
// toggle flag
gemessen = true;
}
Hi Hung,
Please refer to the attachment for details.
Have a great day,
Ping
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------