Content originally posted in LPCWare by mariano315 on Mon Jan 28 10:11:57 MST 2013
Hi everyone,
I'm using the LPC1769's ADC with DMA transfer to ram mem, and trying to sample at 200 KHz to no avail (with a 100MHz cpu clock). I can get to 192 KHz at most but not exactly 200, as I show you with this piece of code:
/*
In the PCLKSEL0 registry I leave PCLK_ADC with the default 00 value (I've also tried other combinations) => it divides the cpu clock by 4.
I also divide that value by the desired adcclk(200 KHz) multiplied by the number of cycles each conversion takes(65 cycles): 200K*65=13M
*/
tmp = (SystemCoreClock >>2)/13000000;
/*
Then I decrement tmp since the cpu will use that value plus one
*/
tmp--;
/*
Finally I write that value in the ADCR->CLKDIV reg
*/
LPC_ADC->ADCR |=((tmp&0xFF)<<8);
The main problem is at the first line: dividing 100MHz by 4 we get 25MHz, and divided by 13MHz is 1.923. So, excluding the decimal part we get tmp=1 and then we decrement it, tmp=0, and we store it in CLKDIV. Finally, AdcClk=(CpuClk/4)/(CLKDIV+1)=25MHz.
The closest natural tmp would be 2, which we get it with an AdcClk of 12.5MHz. So, 12.5MHz/65cycles=192KHz.
Does anyone know the way to get 200KHz using DMA in burst mode, with a 100MHz cpu clock?
Thanks a lot.