Simplest ADC not working!!!!!!!!!!1

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

Simplest ADC not working!!!!!!!!!!1

1,402 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jose_peeterson on Wed Sep 26 11:26:02 MST 2012
Hello all,

            can you please tell me why my code is not working.


Quote:

#include "stdio.h"
#include "stdint.h"
#include "lpc17xx_adc.h"
#include "lpc17xx_pinsel.h"
#include "LPC17xx.h"


static void adc_pinsel();


int main(void)
{// done for AD0.0 ONLY.
uint16_t digi_distance;

LPC_ADC_TypeDef adc_cfg;

adc_cfg.ADCR;
adc_cfg.ADDR0;


adc_pinsel();

ADC_DeInit(&adc_cfg);
// ADC_DeInit(&adc_cfg);

ADC_Init(&adc_cfg,13000000);
// ADC_Init(&adc_cfg,13000000);

ADC_BurstCmd(&adc_cfg,0);

ADC_ChannelCmd(&adc_cfg,0,1);

//  while(1)
//  {
ADC_StartCmd(&adc_cfg,ADC_START_NOW);

if((ADC_ChannelGetStatus(&adc_cfg,0,1)) == 1)
{
digi_distance =ADC_ChannelGetData(&adc_cfg,0);

printf("%d\n",digi_distance);
//}
  }


return 0;
}


static void adc_pinsel()
{
PINSEL_CFG_Type PinCfg;

PinCfg.Funcnum = 1; // select AD0.0
PinCfg.Pinnum = 23;
PinCfg.Portnum = 0;
PinCfg.Pinmode = 2;
// select AD0.1


/* do the similarly for rest of the 3 pins*/

PINSEL_ConfigPin(&PinCfg);
}





i get check_failed error after I reach ADC_DEinit();
0 Kudos
Reply
6 Replies

1,320 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jose_peeterson on Wed Sep 26 12:49:56 MST 2012
Hey zero,

thanks.
0 Kudos
Reply

1,320 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Wed Sep 26 12:38:34 MST 2012
I don't know why you try to deinit just before you init ADC :confused: That's nonsense :eek:

This function is expecting a 'LPC_ADC_TypeDef *ADCx' usually defined in LPC17xx.h:
#define LPC_ADC               ((LPC_ADC_TypeDef *) LPC_ADC_BASE)
You can download examples from your computer

LPCXpresso is installing a lot of samples in LPCXpresso folder like C:\???\LPCXpresso_4.3.0_1023\lpcxpresso\Examples\NXP
0 Kudos
Reply

1,320 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jose_peeterson on Wed Sep 26 12:26:27 MST 2012
hi,
can you please answer the question!

thanks.

now can you tell me where to download the example.i cant find it.
0 Kudos
Reply

1,320 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Wed Sep 26 12:10:54 MST 2012

Quote: jose_peeterson
thanks for your post, can you please tell me how to declare and use typedef struct


:confused:

Is there a special reason why you don't use some of the examples in your example folder like:

\Examples\NXP\LPC1000\LPC17xx\NXP_LPCXpresso1769_MCB1700_2011-02-11.zip\ADC
0 Kudos
Reply

1,320 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jose_peeterson on Wed Sep 26 11:57:33 MST 2012
hi,
      thanks for your post, can you please tell me how to
declare and use typedef struct
/*------------- Analog-to-Digital Converter (ADC) ----------------------------*/
typedef struct
{
  __IO uint32_t ADCR;
  __IO uint32_t ADGDR;
       uint32_t RESERVED0;
  __IO uint32_t ADINTEN;
  __I  uint32_t ADDR0;
  __I  uint32_t ADDR1;
  __I  uint32_t ADDR2;
  __I  uint32_t ADDR3;
  __I  uint32_t ADDR4;
  __I  uint32_t ADDR5;
  __I  uint32_t ADDR6;
  __I  uint32_t ADDR7;
  __I  uint32_t ADSTAT;
  __IO uint32_t ADTRM;
} LPC_ADC_TypeDef;




in this fucntion
ADC_DeInit(LPC_ADC_TypeDef *ADCx);
0 Kudos
Reply

1,320 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpc1113 on Wed Sep 26 11:48:48 MST 2012
I suggest to initialize all ADC registers manually.
If you use functions, it is hard to understand internal machanism.

If you setup the all of the ADC registers manually,
you can watch the change of internal ADC register value which may
cause some problem. (Peripheral Watch Manu of LPC expresso)

Good luck!
0 Kudos
Reply