Disha Patil

Light intensity measurement using the new LPC845 Breakout Board

Blog Post created by Disha Patil Employee on Jan 14, 2019
Using SDK drivers for LPC845 Breakout Board, this project measures the ambient light intensity by using LDR (Light Dependent Resistor). The voltage values from LDR are read through an ADC. The new LPC845 Breakout board has an SDK support which makes it a lot easier to interface an LDR for measuring light intensity compared to the conventional coding style. I have used the MCUXpresso IDE for modifying the pins and clock configuration settings.
The project requires a resistor and LDR (Light Dependent Resistor)/Photoresistor in a resistor divider circuit as shown below:
ldr-circuit.jpg

The value of R1 here is 4.4Kohm. 

The output of this resistor divider circuit is connected to the assigned ADC channel. In this application, I have assigned it to the ADC0_8 channel which is the PIO0_18 (pin 3) and configured it accordingly in the software.
Components used: LPC845 Breakout Board, Light Dependent Resistor(LDR)/Photoresistor, 2.2Kohm resistor (Quantity:2)
LPC845 Breakout Board connections to the LDR are as shown:
LPC845LDR
Pin NameBoard LocationPin Name
ADC_8PIO0_18 (CN1-3)resistor divider o/p
VCCCN1-40LDR
GNDCN1-204.4k resistor
image.png
For this application, I have used ADC0_8 as the ADC channel which converts the LDR output analog voltage values to digital values. The values printed on the console window reflect the change in the light intensity.
(For testing purposes, the light intensity can be changed by covering the LDR or using a cellphone flash)
The LPC845 Breakout board has an SDK package support. I used the ADC SDK driver API in the software for interfacing the hardware components. The MCUXpresso SDK Builder has open source drivers, middleware, and reference example applications for software development. Customize and download the SDK specific to the processor and then import the zip file to the project in MCUXpresso IDE.
                                                                                                                                                                            
The LPC845 Breakout board also features function-configurable I/O ports through a switch matrix (SWM). This makes it easier to configure pin routing and other pin electrical features. The configuration tool which is integrated into the IDE is useful for making changes in the switch matrix. The source code is auto-generated when the pin configuration or peripherals are changed.
 
/* ADC_CHN8 connect to P0_18 */
SWM_SetFixedPinSelect(SWM0, kSWM_ADC_CHN8, true);
The source code for this application and board info for the LPC845 Breakout board can be found here.
int main(void)
{
/* Initialize board hardware. */
BOARD_InitPins();
BOARD_BootClockRUN();
BOARD_InitDebugConsole();
/* Configure the converter and work mode. */
ADC_Configuration();
while(1)
{
/* Trigger the sequence's conversion by software */
ADC_DoSoftwareTriggerConvSeqA(DEMO_ADC_BASE);
/* Wait for the converter to be done. */
while (!ADC_GetChannelConversionResult(DEMO_ADC_BASE, DEMO_ADC_SAMPLE_CHANNEL_NUMBER, &adcResultInfoStruct))
{
}
/* Display the conversion result */
PRINTF("adcResult = %d\r\n", adcResultInfoStruct.result);
}
}

Outcomes