lpc1788 ADC burst

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

lpc1788 ADC burst

1,072 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ojima on Wed Jan 11 02:39:35 MST 2012
hello,

Please tell me that how to get the ADC burst result via GPDMA transfer.

I'm programing to get ADC result on burst mode with IAR Kickstart Kit.

I've set the parameter as follows and run the program,
then I got the result that is not my expected.

I need somebody's help.

[source] (using CMSIS "lpc177x.lpc178x.cmsis_.driver.library.zip")

---- set ADC ---
  // Set the P0.13 pin as an analog input.
  PINSEL_ConfigPin(0, 13, 3);
  PINSEL_SetInBufMode(0, 13, DISABLE); // to assert bit7(analog mode)

  // set the sampling rate
  ADC_Init(LPC_ADC, 400000);

  // disable interruption
  ADC_IntConfig(LPC_ADC, ADC_ADINTEN7, DISABLE);
  // enable ch#7
  ADC_ChannelCmd(LPC_ADC, ADC_CHANNEL_7, ENABLE);
  // enable interruption
  ADC_IntConfig(LPC_ADC, ADC_ADINTEN7, ENABLE);
  // disable interruption(NVIC) make sure
  NVIC_DisableIRQ(ADC_IRQn);

--- start DMA transfer ---

  // channel 1
  GPDMACfg.ChannelNum = 1;
  // Source memory - unused
  GPDMACfg.SrcMemAddr = 0;
  // Destination memory
  GPDMACfg.DstMemAddr = (uint32_t) s_buf;
  // Transfer size
  GPDMACfg.TransferSize = 1000;
  // Transfer width - unused
  GPDMACfg.TransferWidth = 0;
  // Transfer type
  GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_P2M;
  // Source connection
  GPDMACfg.SrcConn = GPDMA_CONN_ADC;
  // Destination connection - unused
  GPDMACfg.DstConn = 0;
  // Linker List Item - unused
  GPDMACfg.DMALLI = 0;
  GPDMA_Setup(&GPDMACfg);

  // Enable GPDMA channel 1
  GPDMA_ChannelCmd(1, ENABLE);

  // Start ADC
  ADC_BurstCmd(LPC_ADC, ENABLE);


[result]
s_buf[0] : 0x87007840 <-- DONE bit is 1
s_buf[1] : 0x07007840 <-- DONE bit is 0
s_buf[2] : 0x07007840 <-- DONE bit is 0
                  :
s_buf[15]: 0x07003C20 <-- DONE bit is 0
s_buf[16]: 0x87007850 <-- DONE bit is 1
s_buf[17]: 0x07007850 <-- DONE bit is 0


--- my expected ---                
s_buf[0] : 0x87007840 <-- DONE bit is 1
s_buf[1] : 0x87007850 <-- DONE bit is 1
                  :
Labels (1)
0 Kudos
6 Replies

780 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by manoj on Sun Aug 25 21:25:52 MST 2013
#include<iolpc1788.h>
int main(void)
{
  int data;
  FIO0DIR |=(0<< 23);
PCONP =0X00001000;
AD0CR = 0X00210101;

IOCON_P0_23 =0X00000001;

while (!( AD0GDR & (1 << 31))) ;


   AD0CR |= (0<<24);
   data = AD0GDR;
return(0);
 
}
  sir i m new to lpc 1788  pls check this code sirrrrr tell me correct or not
0 Kudos

780 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ojima on Mon Oct 29 18:37:49 MST 2012
Hi Ariel, I tried to check latest example of CMSIS but I could not get.
If you can get the latest CMSIS source code from GIT "http://sw.lpcware.com/" and try again, you will get better result.
Now, snapshot is disabled.

Ojima
0 Kudos

780 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by arieldas on Sun Oct 28 20:22:43 MST 2012
Hello Ojima, thanks for the answer. The function ADC_IntConfig(LPC_ADC,ADC_ADINTEN2,SET); is for enable the ADC´s interrupt to indicate the DMA when ADC "end of convertion". It is a CMSIS´s function.

In the case of non-use, the DMA does not write to memory.

Ariel
0 Kudos

780 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ojima on Wed Oct 24 23:56:33 MST 2012
Hello Ariel,

One difference I found. Comment out following line and try again.
>ADC_IntConfig(LPC_ADC,ADC_ADINTEN2,SET);

I will comment on "I've confirmed that..."

I measured ADC sampling time as below:
start = LPC_TIMx->TC;
{
// ADC sampliling
}
end = LPC_TIMx->TC;

"sample rate = 10Hz", "sampling point = 100" => "sampling time = 10sec"
"sample rate = 100Hz", "sampling point = 100" => "sampling time = 1sec"
"sample rate = 100Hz", "sampling point = 1000" => "sampling time = 10sec"
"DMA transfer(sampling) time depends on ADC sampling rate and transfer size" means above.

And I confirmed I was able to get expected result of "sampling time".

Enjoy :)
Ojima
0 Kudos

780 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by arieldas on Tue Oct 23 12:58:28 MST 2012
Hello Ojima, I have the same problem that you had. I read your comments but I can´t solution my code. I need that the ADC works with DMA and in the sampling frequency that I need (it´s different in parts of my code).

Besides, I do not understand your sentence "I've confirmed that DMA transfer time depends on ADC sampling rate and transfer size.". Can you explain me???

I´m using the LPC1769 y my code is:

#include "lpc17xx_adc.h"
#include "lpc17xx_libcfg_default.h"
#include "lpc17xx_pinsel.h"
#include "lpc17xx_nvic.h"
#include "lpc17xx_gpdma.h"

#define DMA_SIZE_ADC256

/************************************************/
uint32_t FLAG=0;

/************************************************/
void DMA_IRQHandler (void);


/**********************************************************************/
void DMA_IRQHandler (void)
{

if (GPDMA_IntGetStatus(GPDMA_STAT_INT, 0))
{

if(GPDMA_IntGetStatus(GPDMA_STAT_INTTC, 0))
{

GPDMA_ClearIntPending (GPDMA_STATCLR_INTTC, 0);
FLAG=1;
}

if (GPDMA_IntGetStatus(GPDMA_STAT_INTERR, 0))
{

GPDMA_ClearIntPending (GPDMA_STATCLR_INTERR, 0);

}
}
}


/*------------------------------------------------*/

int main(void)
{
PINSEL_CFG_Type PinCfg;
GPDMA_Channel_CFG_Type GPDMACfg;
uint32_t adc_value [DMA_SIZE_ADC], tmp,frecuencia_muestreo_adc=30, i;

SystemInit();


PinCfg.Funcnum = 1;
PinCfg.OpenDrain = 0;
PinCfg.Pinmode = 0;
PinCfg.Pinnum = 25;
PinCfg.Portnum = 0;
PINSEL_ConfigPin(&PinCfg);




ADC_Init(LPC_ADC, frecuencia_muestreo_adc);
ADC_IntConfig(LPC_ADC,ADC_ADINTEN2,SET);
ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_2,SET);
NVIC_DisableIRQ(ADC_IRQn); // desabilitamos la interrupción del NVIC para el ADC por las dudas.


GPDMA_Init();

GPDMACfg.ChannelNum = 0;//Canal 0 del DMA
GPDMACfg.SrcMemAddr = 0;//No empleamos memoria origen (el orgien será el ADC)
GPDMACfg.DstMemAddr = (uint32_t) adc_value;//Memoria destino: puntero a adc_value
GPDMACfg.TransferSize = DMA_SIZE_ADC;//Tamaño de la transferencia
GPDMACfg.TransferWidth = 0;//No utilizamos el ancho de la transferencia
GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_P2M;//Tipo de transferencia: Periférico a Memory P2M
GPDMACfg.SrcConn = GPDMA_CONN_ADC;//Conexión origen: periférico ADC
GPDMACfg.DstConn = 0;//Conexión destino: no aplica, pues el destino es memoria
GPDMACfg.DMALLI = 0;//No utilizamos el Linker List
GPDMA_Setup(&GPDMACfg);//Escribimos la configuración

NVIC_EnableIRQ(DMA_IRQn);//Encendemos la interrupción de DMA en el NVIC

for(i=0;i<DMA_SIZE_ADC;i++)
{
adc_value =0;
}

while (1) {


GPDMA_ChannelCmd(0, ENABLE);//Encendemos el canal 0


ADC_BurstCmd(LPC_ADC,ENABLE);



while ((FLAG == 0) );


GPDMA_ChannelCmd(0, DISABLE);//Apaga el canal DMA

for(tmp = 0; tmp < 1000000; tmp++);//Demora

GPDMA_Setup(&GPDMACfg);//Reconfigura DMA

FLAG=0;//Borra el FLAG

}
ADC_DeInit(LPC_ADC);
return 1;
}

RESULT when I measure a 1,5V battery:

adc_value0x10007bb8
[0...99]
adc_value[0]0x820077b0
adc_value[1]0x20077b0
adc_value[2]0x20077b0
adc_value[3]0x20077b0
adc_value[4]0x20077b0
adc_value[5]0x20077b0
adc_value[6]0x20077b0
adc_value[7]0x20077b0
adc_value[8]0x20077b0
adc_value[9]0x20077b0
adc_value[10]0x20077b0
adc_value[11]0x20077b0
adc_value[12]0x20077b0
adc_value[13]0x20077b0
adc_value[14]0x20077b0
adc_value[15]0x20077b0
adc_value[16]0x20077b0
adc_value[17]0x20077b0
adc_value[18]0x20077b0
adc_value[19]0x20077b0
adc_value[20]0x20077b0
adc_value[21]0x20077b0
adc_value[22]0x20077b0
adc_value[23]0x20077b0
adc_value[24]0x20077b0
adc_value[25]0x20077b0
adc_value[26]0x20077b0
adc_value[27]0x20077b0
adc_value[28]0x20077b0
adc_value[29]0x20077b0
adc_value[30]0x20077b0
adc_value[31]0x20077b0
adc_value[32]0x20077b0
adc_value[33]0x20077b0
adc_value[34]0x20077b0
adc_value[35]0x20077b0
adc_value[36]0x20077b0
adc_value[37]0x20077b0
adc_value[38]0x20077b0
adc_value[39]0x20077b0
adc_value[40]0x20077b0
adc_value[41]0x20077b0
adc_value[42]0x20077b0
adc_value[43]0x20077b0
adc_value[44]0x20077b0
adc_value[45]0x20077b0
adc_value[46]0x20077b0
adc_value[47]0x20077b0
adc_value[48]0x20077b0
adc_value[49]0x20077b0
adc_value[50]0x20077b0
adc_value[51]0x20077b0
adc_value[52]0x20077b0
adc_value[53]0x20077b0
adc_value[54]0x20077b0
adc_value[55]0x20077b0
adc_value[56]0x20077b0
adc_value[57]0x20077b0
adc_value[58]0x20077b0
adc_value[59]0x20077b0
adc_value[60]0x20077b0
adc_value[61]0x20077b0
adc_value[62]0x20077b0
adc_value[63]0x20077b0
adc_value[64]0x20077b0
adc_value[65]0x20077b0
adc_value[66]0x20077b0
adc_value[67]0x20077b0
adc_value[68]0x20077b0
adc_value[69]0x20077b0
adc_value[70]0x20077b0
adc_value[71]0x20077b0
adc_value[72]0x20077b0
adc_value[73]0x20077b0
adc_value[74]0x20077b0
adc_value[75]0x20077b0
adc_value[76]0x20077b0
adc_value[77]0x20077b0
adc_value[78]0x20077b0
adc_value[79]0x20077b0
adc_value[80]0x20077b0
adc_value[81]0x20077b0
adc_value[82]0x20077b0
adc_value[83]0x20077b0
adc_value[84]0x20077b0
adc_value[85]0x20077b0
adc_value[86]0x20077b0
adc_value[87]0x20077b0
adc_value[88]0x20077b0
adc_value[89]0x20077b0
adc_value[90]0x20077b0
adc_value[91]0x20077b0
adc_value[92]0x20077b0
adc_value[93]0x20077b0
adc_value[94]0x20077b0
adc_value[95]0x20077b0
adc_value[96]0x20077b0
adc_value[97]0x20077b0
adc_value[98]0x20077b0
adc_value[99]0x20077b0
[100...199]
adc_value[100]0x20077b0
adc_value[101]0x20077b0
adc_value[102]0x20077b0
adc_value[103]0x20077b0
adc_value[104]0x20077b0
adc_value[105]0x20077b0
adc_value[106]0x20077b0
adc_value[107]0x20077b0
adc_value[108]0x20077b0
adc_value[109]0x20077b0
adc_value[110]0x20077b0
adc_value[111]0x20077b0
adc_value[112]0x20077b0
adc_value[113]0x20077b0
adc_value[114]0x20077b0
adc_value[115]0x20077b0
adc_value[116]0x20077b0
adc_value[117]0x20077b0
adc_value[118]0x20077b0
adc_value[119]0x20077b0
adc_value[120]0x20077b0
adc_value[121]0x20077b0
adc_value[122]0x20077b0
adc_value[123]0x20077b0
adc_value[124]0x20077b0
adc_value[125]0x20077b0
adc_value[126]0x20077b0
adc_value[127]0x20077b0
adc_value[128]0x20077b0
adc_value[129]0x20077b0
adc_value[130]0x20077b0
adc_value[131]0x20077b0
adc_value[132]0x20077b0
adc_value[133]0x20077b0
adc_value[134]0x20077b0
adc_value[135]0x20077b0
adc_value[136]0x20077b0
adc_value[137]0x20077b0
adc_value[138]0x20077b0
adc_value[139]0x20077b0
adc_value[140]0x20077b0
adc_value[141]0x20077b0
adc_value[142]0x20077b0
adc_value[143]0x20077b0
adc_value[144]0x20077b0
adc_value[145]0x20077b0
adc_value[146]0x20077b0
adc_value[147]0x20077b0
adc_value[148]0x20077b0
adc_value[149]0x20077b0
adc_value[150]0x20077b0
adc_value[151]0x20077b0
adc_value[152]0x20077b0
adc_value[153]0x20077b0
adc_value[154]0x20077b0
adc_value[155]0x20077b0
adc_value[156]0x200ef60
adc_value[157]0x200ef60
adc_value[158]0x200ef60
adc_value[159]0x200ef60
adc_value[160]0x200ded0
adc_value[161]0x200ded0
adc_value[162]0x200bdb0
adc_value[163]0x200bdb0
adc_value[164]0x200bdb0
adc_value[165]0x2007b70
adc_value[166]0x2007b70
adc_value[167]0x2007b70
adc_value[168]0x200f6e0
adc_value[169]0x200f6e0
adc_value[170]0x200f6e0
adc_value[171]0x200edd0
adc_value[172]0x200edd0
adc_value[173]0x200edd0
adc_value[174]0x200dbb0
adc_value[175]0x200dbb0
adc_value[176]0x200dbb0
adc_value[177]0x200b770
adc_value[178]0x200b770
adc_value[179]0x200b770
adc_value[180]0x2006ef0
adc_value[181]0x2006ef0
adc_value[182]0x2006ef0
adc_value[183]0x200ddf0
adc_value[184]0x200ddf0
adc_value[185]0x200ddf0
adc_value[186]0x200bbe0
adc_value[187]0x200bbe0
adc_value[188]0x200bbe0
adc_value[189]0x820077c0
adc_value[190]0x20077c0
adc_value[191]0x20077c0
adc_value[192]0x20077c0
adc_value[193]0x20077c0
adc_value[194]0x20077c0
adc_value[195]0x20077c0
adc_value[196]0x20077c0
adc_value[197]0x20077c0
adc_value[198]0x20077c0
adc_value[199]0x20077c0
[200...255]
adc_value[200]0x20077c0
adc_value[201]0x20077c0
adc_value[202]0x20077c0
adc_value[203]0x20077c0
adc_value[204]0x20077c0
adc_value[205]0x20077c0
adc_value[206]0x20077c0
adc_value[207]0x20077c0
adc_value[208]0x20077c0
adc_value[209]0x20077c0
adc_value[210]0x20077c0
adc_value[211]0x20077c0
adc_value[212]0x20077c0
adc_value[213]0x20077c0
adc_value[214]0x20077c0
adc_value[215]0x20077c0
adc_value[216]0x20077c0
adc_value[217]0x20077c0
adc_value[218]0x20077c0
adc_value[219]0x20077c0
adc_value[220]0x20077c0
adc_value[221]0x20077c0
adc_value[222]0x20077c0
adc_value[223]0x20077c0
adc_value[224]0x20077c0
adc_value[225]0x20077c0
adc_value[226]0x20077c0
adc_value[227]0x20077c0
adc_value[228]0x20077c0
adc_value[229]0x20077c0
adc_value[230]0x20077c0
adc_value[231]0x20077c0
adc_value[232]0x20077c0
adc_value[233]0x20077c0
adc_value[234]0x20077c0
adc_value[235]0x20077c0
adc_value[236]0x20077c0
adc_value[237]0x20077c0
adc_value[238]0x20077c0
adc_value[239]0x20077c0
adc_value[240]0x20077c0
adc_value[241]0x20077c0
adc_value[242]0x20077c0
adc_value[243]0x20077c0
adc_value[244]0x20077c0
adc_value[245]0x20077c0
adc_value[246]0x20077c0
adc_value[247]0x20077c0
adc_value[248]0x20077c0
adc_value[249]0x20077c0
adc_value[250]0x20077c0
adc_value[251]0x20077c0
adc_value[252]0x20077c0
adc_value[253]0x20077c0
adc_value[254]0x20077c0
adc_value[255]0x20077c0

Thanks for everything and sorry for the inconvenience,
Ariel
0 Kudos

779 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ojima on Wed Jan 11 17:39:34 MST 2012
Hi,

I've got a result I expect!

[changing point]
- lpc177x_8x_gpdma.c
line 142 in GPDMA_LUTPerBurst table data.
original GPDMA_BSZE_4
correct  GPDMA_BSZE_1

- program as above(in --- set ADC ---)
comment out following line(that means "ADC_ADINTEN7" is disabled)
// enable interruption
// ADC_IntConfig(LPC_ADC, ADC_ADINTEN7, ENABLE);

I hope this changing reflect CMSIS and examples.

[result]
s_buf[0] : 0x87007840 <-- DONE bit is 1
s_buf[1] : 0x87007850 <-- DONE bit is 1
:

I've confirmed that DMA transfer time depends on ADC sampling rate and transfer size.

OJIMA
0 Kudos