ADC Of LPC1768 cortex-m3 interface with CNY70

Status
Not open for further replies.
Thanks for ur attention. I've changed my functions but again there is no sign of improvment.Could u please give me sources for If Function ? I think my If function doesn't works .
OR maybe I should have any kind of delay?
This is my latest program :
Code:
#include "lpc17xx.h"
#include "type.h"
#include "adc.h"
extern volatile uint32_t ADCValue[ADC_NUM];
extern volatile uint32_t ADCIntDone;
extern volatile uint32_t OverRunCounter;

/*****************************************************************************
**   Main Function  main()
******************************************************************************/
int main (void)
{
 uint32_t i,j;
 uint16_t L;
  /* SystemClockUpdate() updates the SystemFrequency variable */
  SystemClockUpdate();
 
 LPC_GPIO2->FIODIR = 0x000000FF;		/* P2.xx defined as Outputs */
 LPC_GPIO2->FIOCLR = 0x000000FF;		/* turn off all the LEDs */

	for(i = 0; i < 8; i++)
	{
	  LPC_GPIO2->FIOSET = 1 << i;
	  for(j = 1000000; j > 0; j--);
	}
	LPC_GPIO2->FIOCLR = 0x000000FF;
	for(j = 1000000; j > 0; j--);  
  /* Initialize ADC  */
  ADCInit( ADC_CLK );
  while(1)
  {
L = ADCRead(0);
L = (L >> 4) & 0x00000FFF;
if ( L < 100 ) 	
break;
}


 LPC_GPIO2->FIOCLR = 0x000000FF;		/* turn off all the LEDs */

	for(i = 0; i < 8; i++)
	{
	  LPC_GPIO2->FIOSET = 1 << i;
	  for(j = 1000000; j > 0; j--);
	}
	LPC_GPIO2->FIOCLR = 0x000000FF;
	for(j = 1000000; j > 0; j--);  

  while(1)
  {
L = ADCRead(1);
L = (L >> 4) & 0x00000FFF;
if ( L < 100 ) 	
break;
}


 LPC_GPIO2->FIOCLR = 0x000000FF;		/* turn off all the LEDs */

	for(i = 0; i < 8; i++)
	{
	  LPC_GPIO2->FIOSET = 1 << i;
	  for(j = 1000000; j > 0; j--);
	}
	LPC_GPIO2->FIOCLR = 0x000000FF;
	for(j = 1000000; j > 0; j--); 
	
	  while(1)
  {
L = ADCRead(2);
L = (L >> 4) & 0x00000FFF;
if ( L < 100 ) 	
break;
}


 LPC_GPIO2->FIOCLR = 0x000000FF;		/* turn off all the LEDs */

	for(i = 0; i < 8; i++)
	{
	  LPC_GPIO2->FIOSET = 1 << i;
	  for(j = 1000000; j > 0; j--);
	}
	LPC_GPIO2->FIOCLR = 0x000000FF;
	for(j = 1000000; j > 0; j--); 
	
	  while(1)
  {
L = ADCRead(3);
L = (L >> 4) & 0x00000FFF;
if ( L < 100 ) 	
break;
}


 LPC_GPIO2->FIOCLR = 0x000000FF;		/* turn off all the LEDs */

	for(i = 0; i < 8; i++)
	{
	  LPC_GPIO2->FIOSET = 1 << i;
	  for(j = 1000000; j > 0; j--);
	}
	LPC_GPIO2->FIOCLR = 0x000000FF;
	for(j = 1000000; j > 0; j--); 
	
	  while(1)
  {
L = ADCRead(4);
L = (L >> 4) & 0x00000FFF;
if ( L < 100 ) 	
break;
}


 LPC_GPIO2->FIOCLR = 0x000000FF;		/* turn off all the LEDs */

	for(i = 0; i < 8; i++)
	{
	  LPC_GPIO2->FIOSET = 1 << i;
	  for(j = 1000000; j > 0; j--);
	}
	LPC_GPIO2->FIOCLR = 0x000000FF;
	for(j = 1000000; j > 0; j--); 
	
	  while(1)
  {
L = ADCRead(5);
L = (L >> 4) & 0x00000FFF;
if ( L < 100 ) 	
break;
}


 LPC_GPIO2->FIOCLR = 0x000000FF;		/* turn off all the LEDs */

	for(i = 0; i < 8; i++)
	{
	  LPC_GPIO2->FIOSET = 1 << i;
	  for(j = 1000000; j > 0; j--);
	}
	LPC_GPIO2->FIOCLR = 0x000000FF;
	for(j = 1000000; j > 0; j--); 
	
 while(1)
  {
L = ADCRead(6);
L = (L >> 4) & 0x00000FFF;
if ( L < 100 ) 	
break;
}


 LPC_GPIO2->FIOCLR = 0x000000FF;		/* turn off all the LEDs */

	for(i = 0; i < 8; i++)
	{
	  LPC_GPIO2->FIOSET = 1 << i;
	  for(j = 1000000; j > 0; j--);
	}
	LPC_GPIO2->FIOCLR = 0x000000FF;
	for(j = 1000000; j > 0; j--); 	
	
  while(1)
  {
L = ADCRead(7);
L = (L >> 4) & 0x00000FFF;
if ( L < 100 ) 	
break;
}


 LPC_GPIO2->FIOCLR = 0x000000FF;		/* turn off all the LEDs */

	for(i = 0; i < 8; i++)
	{
	  LPC_GPIO2->FIOSET = 1 << i;
	  for(j = 1000000; j > 0; j--);
	}
	LPC_GPIO2->FIOCLR = 0x000000FF;
	for(j = 1000000; j > 0; j--); 	
	
  while(1)
  {
L = ADCRead(8);
L = (L >> 4) & 0x00000FFF;
if ( L < 100 ) 	
break;
}


 LPC_GPIO2->FIOCLR = 0x000000FF;		/* turn off all the LEDs */

	for(i = 0; i < 8; i++)
	{
	  LPC_GPIO2->FIOSET = 1 << i;
	  for(j = 1000000; j > 0; j--);
	}
	LPC_GPIO2->FIOCLR = 0x000000FF;
	for(j = 1000000; j > 0; j--); 	
	

	}
I've try to Examine all of my ADC input but i put high voltage about 3.3 to 5 Volt for preventing To Light the port which is off. but all light up in regular structure....

- - - Updated - - -

Also there is no Error in compiling.....
 

I'm not even sure if you read correct values.
I would suggest you start with the ADC example and make sure that you read the voltages in the ADC input correctly, then you just need to use the same ADC read functions in your code.

An alternative would be a debugger so that you can read the ADC value or some kind of lcd to show the result
 
Thanks,Dear Alexan & other friends.... problem solved........!
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…