LPC1768 ADC Reads Garbage

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

LPC1768 ADC Reads Garbage

1,366 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by melpel on Wed Mar 20 15:01:48 MST 2013
Unable to get the ADC to read anything but garbage.  Started with the test code on my board, changed boards, went back to the Keil board... all do the same thing.  What am I missing...?

Fault Symptoms:
Typically reads back 0 or FFF.  When adjusting the analog control on the eval board there was a small range where the values would bounce around randomly, then flop to the other extreme. 
On my board if I hard ground the analog input I get 0, otherwise any slight value on the pin reads FFF.

The key steps I am using:
1.  LPC_SC->PCONP |= ADC_PCONP_BIT;// Set global ADC Power Enable
2. LPC_ADC->ADCR = adcChan | adcClk | adcBurst | adcPdn | adcEdge;  // Edge = Burst = 0

Trigger Read:
3.adcStatus = LPC_ADC->ADGDR;// Dummy read to clear overrun bit if set
4.LPC_ADC->ADCR |= ADC_STARTCONV;
5.while ((LPC_ADC->ADGDR & CONV_COMPLETE_FLAG) == 0);   /* Bit 31 is the done bit, set to 1 when conversion is complete */

Read value:
6.avalue = (LPC_ADC->DR[chan] >> 4);
6.b//value = (LPC_ADC->ADDR >> 4);
标签 (1)
0 项奖励
回复
5 回复数

1,133 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by amar on Thu Mar 21 21:56:50 MST 2013
I am new for the linux device drivers please help me....

how to read and write to a port pins of the LPC1788 cortex-m3 processor pin..? I have done hello word device driver but now I want to access the port pins and read/write the port pins to control some hardware device with my controller.

suppose i want to blink an LED at some particular port pin of the hardware, how to achieve this and what all the changes need to made in file system.

please explain me in detail.
0 项奖励
回复

1,133 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by melpel on Thu Mar 21 15:04:15 MST 2013
UPDATE:
Working with Keil they suggested running the "Blinky" code on the eval board.  Once I got my flash download tools properly configured, this code worked.  When ported back into my design the code failed same as before.  Changed my design to run from Flash, and the code worked.

So the core problem is "ADC values inop when running from RAM - Flash OK". 

I've previously tried manipulating the clock rates assuming that was the problem, but made no difference.  Any suggestions as to what to look for next in terms of why the ADC does not operate when running from RAM, but works fine running from flash? 
0 项奖励
回复

1,133 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Dave on Thu Mar 21 11:07:48 MST 2013
and which microcontroller are you using?
0 项奖励
回复

1,132 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by melpel on Thu Mar 21 09:04:50 MST 2013
I've tried multiple methods of pion configuration, makes no difference.  Also have gone back to reverify the pin configuration by reading back the PINSEL[n] registers.

One thing that is not clear is whether the PINMODE[n] and pin direction FIOxDIR registers require setting or not.  I set them to no pull up/down just in case.  Based on the PINSEL documentation this should be set automatically when selecting non-GPIO function.

Fault mode update:  What I am seeing is 0x0FFF for input < 2V, stray values for 2- ~2.3V, and 0x0000 for Vin > 2.3V.   

The clean code style:
configAdcPin(PORT0, 24, MODE1);// ADC0.1 on P0.24
configAdcPin(PORT0, 25, MODE1);// ADC0.2 on P0.25
configAdcPin(PORT0, 26, MODE1);// ADC0.3 on P0.26
configAdcPin(PORT1, 30, MODE3);// ADC0.4 on P1.30
configAdcPin(PORT1, 31, MODE3);// ADC0.5 on P1.31
configAdcPin(PORT0, 3, MODE2);// ADC0.6 on P0.3
configAdcPin(PORT0, 2, MODE2);// ADC0.7 on P0.2

And the brute force:
   // 3. Set Pins
  LPC_PINCON->PINSEL0 &= ~0x000000F0;/* P0.2~3, A0.6~7, function 10 */
  LPC_PINCON->PINSEL0 |= 0x000000A0;
  LPC_PINCON->PINSEL1 &= ~0x003FC000;/* P0.23~26, A0.0~3, function 01 */
  LPC_PINCON->PINSEL1 |= 0x00154000;  
  LPC_PINCON->PINSEL3 |= 0xF0000000;/* P1.30~31, A0.4~5, function 11 */

  /* No pull-up no pull-down (function 10) on these ADC pins. */
  LPC_PINCON->PINMODE0 &= ~0x000000F0;
  LPC_PINCON->PINMODE0 |= 0x000000A0;
  LPC_PINCON->PINMODE1 &= ~0x003FC000;
  LPC_PINCON->PINMODE1 |= 0x002A8000;
  LPC_PINCON->PINMODE3 &= ~0xF0000000;
  LPC_PINCON->PINMODE3 |= 0xA0000000;

No difference either way...
0 项奖励
回复

1,133 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Dave on Thu Mar 21 08:51:41 MST 2013
Where do you set the pin functions?
0 项奖励
回复