LPC1114 + ADC CH0 & CH1 - different work

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

LPC1114 + ADC CH0 & CH1 - different work

983 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by teslabox on Tue Jun 10 12:48:41 MST 2014
Hi everyone!

I need to use two channels of ADC in the LPC1114. The first one is ADC0 and the second one is ADC1.

First, I run ADC0 channel and everything is OK.
Next, I additionaly run ADC1 channel and it doesn't work and what more... it hangs.

Below is my code:

First function is with "Frequency" argument byt in real it daesn't exist yet - there could be anythink for now.
Second function just read the ADC vaulue from propoer channel.

void Init_ADC (uint8_t Frequency)
{
    LPC_SYSCON->PDRUNCFG        &= ~(0x1<<4);  //power the ADC (sec. 3.5.35)
    LPC_SYSCON->SYSAHBCLKCTRL   |= (1<<13);    //enable clock for ADC (sec. 3.5.14)

    LPC_IOCON->R_PIO0_11        &= 0xFFFFFF78; //clear FUNC field for pin 32, set to analog input (sec. 7.4.28)
    LPC_IOCON->R_PIO0_11        |= (1<<1);     //set to ADC mode for pin 32 (sec. 7.4.28)

    LPC_IOCON->R_PIO1_0&= 0xFFFFFF78; //clear FUNC field for pin 33, set to analog input (sec. 7.4.29)
    LPC_IOCON->R_PIO1_0      |= (1<<1);     //set to ADC mode for pin 33 (sec. 7.4.29)

    LPC_ADC->CR                 = 0x0B03;      //select ADC channel AD0 (pin 32) and AD1 (pin33), set up clock (sec 25.5.1)
}

uint16_t ADC_Read (uint8_t Channel)
{
uint16_t Data = 0;

LPC_ADC->CR |= (1<<24);                         //start conversion by setting "Start Conversion Now" bit (sec. 25.5.1)
while((LPC_ADC->DR[Channel] < 0x7FFFFFFF));//wait for "done" bit to be set (sec. 25.5.4)
Data = (LPC_ADC->DR[Channel] & 0xFFC0) >> 6;
return (Data);
}


And main loop:

// main programm
int main (void)
{
uint32_t temp = 0;

Timer32b_0_Init();// Set clock to the Timer 32-bit No. 0
UART_Init (115200);// Set UART bitrate

Init_ADC (1);

for (;;)
{
Timer32b_0_ms (100);// just wait 100 ms

//temp = ADC_Read (0);// read data form ADC0 channel doesn't work, it hangs
// or
temp = ADC_Read (1);// read data form ADC1 channel works good

UART_Send4B (temp);// send temp value (4 bytes) to the PC terminal
}

 return (0);
}


When I run line with ADC1 I got in the PC terminal window:

00 ef fc 7d  .ďü}
07           .   

Always 5 bytes... Even if UART_Send4B always send 4 bytes.

When I run line with ADC0 I got in the PC terminal window:

00 00 00 09  ....
00 00 00 09  ....
00 00 00 80  ...€
00 00 01 95  ...•
00 00 02 2a  ...*
00 00 02 89  ...‰
00 00 02 e7  ...ç
00 00 03 23  ...#
00 00 03 53  ...S
00 00 03 82  ...‚
00 00 03 b8  ...¸
00 00 03 ea  ...ę
00 00 04 26  ...&
00 00 04 29  ...)
00 00 04 29  ...)
and so on...


Exellent proper data.

I have no idea what's going wrong on with ADC1 channel.

I also noticed that if the ADC pins are configured as ADC and they float there is c.a. 2,78 V - 2,99 V of voltage on them... strange for me because they are inputs, no outputs with output voltage.
Labels (1)
0 Kudos
1 Reply

614 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ano on Wed Oct 08 09:09:09 MST 2014
Did somebody find an answer to this problem? I'm having the same problem with adding a second Channel to my code. Channel0 works fine adding Channel1 makes the whole thing hang up in the waiting for conversion while() loop of the second channel.
Am working on LPC11C14.

/edit: Sry, my mistake. Found the solution in this thread: http://www.lpcware.com/content/forum/lpc1769-adc-code
0 Kudos