Analog Sampling on LPC2148

Hello,

I am trying to expand the capabilities of the Kinetamap (LPC4128 based) to sample a microphone. The application is shock and vibration analysis. The kinetamap already has a 3 axis accelerometer chip, I also want to be able to do a higher frequency acoustic analysis. I am planning connecting one of the SFE electret condenser mic breakout boards to one of the unused analog I/Os on the kinetamap board.

I would like to set up a regular sample interval at about 24KHz, to give 12KHz bandwidth of the measurement. I would like to store about 1024 samples into a buffer. I will write the buffer to the flash disk periodically and analyze the data later (do an FFT on the PC to see the frequency content of the captured signal). IF I can take a snapshot about every second that would be good enough.

I am not super familiar with the peripheral set of the 2148. Obviously I am getting up to speed on the datasheets, but I am hoping that someone can point me in the right direction to an example project or might have some insight on the best way to set up this measurement given the resources available on the 2148.

Thanks!

Jeff

Sparkfun’s GPS logger uses a '2148 with SD card flash. It’s logging GPS coordinates. But it might be a good basis.

stevech:
Sparkfun’s GPS logger uses a '2148 with SD card flash. It’s logging GPS coordinates. But it might be a good basis.

Thanks for the post. The kinetamap firmware already takes care of logging the GPS coordianates to SD card. What I need some help with is sampling the ADC at set frequency (not just on demand).

Generate a 24kHz interrupt with a timer. Here’s how I do it for a 50Hz interrupt using the Rowley CrossWorks Tasking Library (CTL):

  // initialise pclk (30 MHz)
  unsigned long pclk = liblpc2000_get_pclk(liblpc2000_get_cclk(OSCILLATOR_CLOCK_FREQUENCY));

  // initialise TIMER0
  T0TCR = 0; /* Reset timer 0 */
  T0PR = 0; /* Set the timer 0 prescale counter */
  T0MR0 = pclk/50 - 1; /* Set time 0 match register to generate an interrupt every 20 ms */
  T0MCR = 3; /* Generate interrupt and reset counter on match */
  T0TCR = 1; /* Start timer 0 */

  // setup CTL stuff for Timer 0
  ctl_set_isr(4, 0, CTL_ISR_TRIGGER_FIXED, timer0ISR, 0);
  ctl_unmask_isr(4);

  // enable global interrupts
  ctl_global_interrupts_enable();

It might be harder with a different compiler, the CTL makes that sort of thing very easy.

Thanks for the sample code! As I look into the ADC peripheral closer, it looks like the LPC2148 has a burst mode option for the ADC that will automatically sample on a timer edge and generate an interrupt when the conversion is complete, so I will probably take that route. I will post the code when I have it working. I am using the WinARM GCC compiler for now, just because that is what the base Kinteamap code was started with.

jtw131:
Thanks for the sample code! As I look into the ADC peripheral closer, it looks like the LPC2148 has a burst mode option for the ADC that will automatically sample on a timer edge and generate an interrupt when the conversion is complete, so I will probably take that route. I will post the code when I have it working. I am using the WinARM GCC compiler for now, just because that is what the base Kinteamap code was started with.

The [firmware I wrote to run on the Logomatic V1 hardware included use of the burst mode but I set the ADC to run continuously. Once it finished one conversion, it started the next. The conversion rate depends on the CPU clock, ADC clock divider, and number of channels selected.](http://home.earthlink.net/~schultdw/logOmatic/LogomaticV4_0.tar.gz)

UhClem:
The [firmware I wrote to run on the Logomatic V1 hardware included use of the burst mode but I set the ADC to run continuously. Once it finished one conversion, it started the next. The conversion rate depends on the CPU clock, ADC clock divider, and number of channels selected.[/quote]

OK, looked at your code – so you set up an automatic conversion at a set rate, and then grab the value when an interrupt is generated and throw it in a buffer?](http://home.earthlink.net/~schultdw/logOmatic/LogomaticV4_0.tar.gz)

jtw131:
OK, looked at your code – so you set up an automatic conversion at a set rate, and then grab the value when an interrupt is generated and throw it in a buffer?

Exactly.