Analog Digital Converter on LPC2138


This examples demonstrates reading the built-in Analog to Digital Converter of LPC2138. The example relies on GetADC() function from BiPOM Library.

Toolkit:ARM Development System

Location:/bipom/devtools/GCC/LPC2000/examples/adc/LPC

Code Example


int main (void)
{
	UBYTE channel;
	float voltage;
	UINT val;

	/* Initialize the system */
	Initialize();

	/* Send messages */
	uart0Puts("\n\rBIPOM MINI-MAX/ARM");
	uart0Puts("\n\rADC  EXAMPLE");

	/* Forever */
	for(;;)
	{
		/* Print carriage return, line feed to the terminal */
		uart0Puts("\n\r");

		/* For all the channels */
		for( channel=AN0_INPUT; channel<=AN4_INPUT; channel++ )
		{
			/* Measure voltage on that channel */
			val=GetADC(channel);
			
			/* Convert raw value to a real voltage */
			voltage = (((float)val) * VREF) 1023.0;
			
			/* Print that channel value to the terminal */
			tprintf ("Ch[%d]=%6.4fV(%04d) ",channel,voltage,val);
		}
		
		/* A small delay before the next set of measurements */
		SoftDelay(DELAY);
	}
}