lpcware

LPC1549 ADC Timer Sample Problems

Discussion created by lpcware Employee on Jun 15, 2016
Content originally posted in LPCWare by samedtopal on Wed Mar 30 05:39:03 MST 2016
Hi to all,

my name is Samed. A freind and me, we have a project with the lpc1549. We have to use the ADC to get the ultrasonic value from the sensor. We use the timer0 to activate the ADC0. We use only the timer interrupt to start a new conversation and the overrun bit to get feedback, that a conversation is finished.

But the problem is, that our ultrasonic signal has a frequency of 40kHz. We want to sample with 240kHz. But we can not configurate the ADC to do that. We are not sure with which frequency we sample the signal. The sampled signal (example signal = sinus 1kHz) has 19 or 20 samples per period. And now if we calculate backwards, so we can see that the sample frequency is not 240kHz. (n=fs/fc). It is only 19 or 20kHz.

What we do wrong?

Here the configuration of the ADC:

/* Setup ADC for 12-bit mode and normal power */
Chip_ADC_Init(LPC_ADC0, 0);

/* Setup for maximum ADC clock rate */
Chip_ADC_SetClockRate(LPC_ADC0, ADC_MAX_SAMPLE_RATE);

/* Use higher voltage trim for both ADCs */
Chip_ADC_SetTrim(LPC_ADC0, ADC_TRIM_VRANGE_HIGHV);

// We use channel 1 becouse channel 0 ist slowlier
Chip_ADC_SetupSequencer(LPC_ADC0, ADC_SEQA_IDX,ADC_SEQ_CTRL_CHANSEL(1));

/* Disables pullups/pulldowns and disable digital mode */
Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 8, (IOCON_MODE_INACT | IOCON_DIGMODE_EN));

/* Assign ADC0_0 to PIO0_8 via SWM (fixed pin) */
Chip_SWM_EnableFixedPin(SWM_FIXED_ADC0_0);

/* Need to do a calibration after initialization and trim */
Chip_ADC_StartCalibration(LPC_ADC0);
while (!(Chip_ADC_IsCalibrationDone(LPC_ADC0))) {}

/* Clear all pending interrupts */
Chip_ADC_ClearFlags(LPC_ADC0, Chip_ADC_GetFlags(LPC_ADC0));

/* Enable sequencers */
Chip_ADC_EnableSequencer(LPC_ADC0, ADC_SEQA_IDX);

//---------- Timer initialisation ------------

// initialize pwm timer
Chip_MRT_Init();

// Timer für den ADC
LPC_MRT_CH_T *ADCTimer;
ADCTimer= Chip_MRT_GetRegPtr(1);

// enable interrupt for the ADC timer
NVIC_EnableIRQ(MRT_IRQn);

// fire timer interrupt for ADC with 2*ultrasonic frequency                                            (240kHz)
Chip_MRT_SetInterval(ADCTimer, (Chip_Clock_GetSystemClockRate() / (2*ADC_FREQUENCY)) | MRT_INTVAL_LOAD);

// single shot timer interrupt
Chip_MRT_SetMode(ADCTimer, MRT_MODE_ONESHOT);

// clear pending interrupt
Chip_MRT_IntClear(ADCTimer);
Chip_MRT_SetDisabled(ADCTimer);

Outcomes