MPLAB Xpress: Proximity Click XC8 code

Some of the links on this blog are affiliated links. READ MORE

More than two weeks have passed since I published my Altitude Click code. If you don’t have an MPLAB Xpress Development board yet it’s time to order one: the part number is DM164140. On the Microchip Direct site you’ll find this little development board with an estimated ship date of 1 June 2016. Some other big distributors have announced it too: you can find it on Farnell (order code 2543062), Mouser (part no 579-DM164140) and TME.

OK, enough with the hardware. Time for another MPLAB Xpress project: a demo code for the Proximity click board from MikroElektronika.

MIKROE-1445 - Proximity Click

Proximity Click

This little click board carries one VCNL4010 proximity sensor from Vishay, plus all the additional components required for it’s use. It’s one of the few MikroElektronika click boards that can be configured for 5V operation – so you can use it also with 5V microcontrollers. However, as the PIC167F18855 is a 3.3V microcontroller I’ll just leave it on it’s factory setting.

The VCNL4010 combines ambient light detection and proximity detection in one single chip. Ambient light is measured in 16 bit precision on a range 0.25 lx to 16 klx, with 100 Hz and 120 Hz flicker noise rejection. Proximity measurements are also returned on 16 bit, with the distance range from 0 to 20cm.

Interfacing with the microcontroller is done via I2C, plus an interrupt pin. VCNL4010 has a number of 16 internal registers, of which register #0 is used to configure the operating mode and also as a flag register for completing a measurement. Register #1 stores the device version (current version is 0x21).

Parameters for ambient light measurement are stored in registers #4, while ambient measurement results are stored in registers #5 and #6.

Proximity measurements are configured via registers #2 (proximity measurement rate), #3 (IR LED current) and register #15 (proximity modulator timing adjustments). Results are stored in registers #7 and #8.

VCNL4010 has also an interrupt system, which can be configured to issue an interrupt when specific thresholds are reached. There is a 16 bit low threshold level stored in registers #10 and #11, and a high threshold level stored in registers #12 and #13.

Interrupts are configured via register #9, with the interrupts status stored in register #14.

1 2 3 4

Leave A Reply