Skip to content

Commit e2e7bc9

Browse files
committed
MPAE-18790 - Initial Commit after reset
0 parents  commit e2e7bc9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+7827
-0
lines changed

.citd/Jenkinsfilek8s

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Jenkinsfile v2.0.0
2+
3+
pipeline {
4+
agent {
5+
kubernetes {
6+
7+
defaultContainer 'xc8-mplabx'
8+
yamlFile '.citd/cloudprovider.yml'
9+
}
10+
}
11+
parameters {
12+
string( name: 'NOTIFICATION_EMAIL',
13+
defaultValue: '[email protected]',
14+
description: "Email to send build failure and fixed notifications.")
15+
}
16+
17+
environment {
18+
GITHUB_OWNER = 'microchip-pic-avr-examples'
19+
GITHUB_URL ='https://github.com/microchip-pic-avr-examples/pic18f56q24-curiosity-nano-explorer-vcnl4200-ambient-sensor'
20+
BITBUCKET_URL = 'https://bitbucket.microchip.com/scm/ebe/pic18f56q24-curiosity-nano-explorer-vcnl4200-ambient-sensor.git'
21+
SEMVER_REGEX = '^(0|[1-9]\\d*)+\\.(0|[1-9]\\d*)+\\.(0|[1-9]\\d*)+$'
22+
ARTIFACTORY_SERVER = 'https://artifacts.microchip.com:7999/artifactory'
23+
}
24+
options {
25+
timestamps()
26+
timeout(time: 30, unit: 'MINUTES')
27+
}
28+
29+
stages {
30+
stage('setup') {
31+
steps {
32+
script {
33+
execute("git clone https://bitbucket.microchip.com/scm/citd/mpae-buildpipeline-groovy-scripts.git")
34+
def buildPipeline = load ('mpae-buildpipeline-groovy-scripts/xc8mplabx-buildpipeline.groovy')
35+
buildPipeline.runStages()
36+
}
37+
}
38+
}
39+
}
40+
41+
post {
42+
failure {
43+
script {
44+
sendPipelineFailureEmail()
45+
}
46+
}
47+
}
48+
}
49+
def execute(String cmd) {
50+
if(isUnix()) {
51+
sh cmd
52+
} else {
53+
bat cmd
54+
}
55+
}
56+
def sendPipelineFailureEmail() {
57+
mail to: "${env.EMAILLIST},${params.NOTIFICATION_EMAIL}",
58+
subject: "Failed Pipeline: ${currentBuild.fullDisplayName}",
59+
body: "Pipeline failure. ${env.BUILD_URL}"
60+
}

.citd/cloudprovider.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: xc8-mplabx
5+
spec:
6+
containers:
7+
- name: xc8-mplabx
8+
image: artifacts.microchip.com:7999/microchip/citd/bundles/xc8-mplabx:latest
9+
imagePullPolicy: Always
10+
command: ['cat']
11+
tty: true
12+
resources:
13+
requests:
14+
cpu: 0.25
15+
memory: 500Mi
16+
limits:
17+
cpu: 0.5
18+
memory: 750Mi

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Untracked files in MPLABX projects
2+
/**/build/*
3+
/**/nbproject/*
4+
!/**/nbproject/*.xml
5+
/**/dist/*
6+
/**/.generated_files/*

.main-meta/main.json

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"metaDataVersion": "1.0.0",
3+
"category": "com.microchip.ide.project",
4+
"content": {
5+
"metaDataVersion": "1.3.0",
6+
"name": "com.microchip.mcu8.mplabx.project.pic18f56q24-curiosity-nano-explorer-vcnl4200-ambient-sensor",
7+
"version": "1.0.0",
8+
"displayName": "pic18f56q24 Light intensity measurement using MCC",
9+
"projectName": "pic18f56q24-curiosity-nano-explorer-vcnl4200-ambient-sensor",
10+
"shortDescription": "This example will demonstrate how to interface the VCNL4200-Ambient-LightSensor on-board the Curiosity Nano Explorer development board using I2C protocol, and UART to display light intensity values on the terminal.",
11+
"ide": {
12+
"name": "MPLAB X",
13+
"semverRange": ">=6.20.0"
14+
},
15+
"compiler": [
16+
{
17+
"name": "XC8",
18+
"semverRange": "^3.00.0"
19+
}
20+
],
21+
"dfp": {
22+
"name": "PIC18F-Q_DFP",
23+
"semverRange": "^1.24.430"
24+
},
25+
"configurator": {
26+
"name": "MCC",
27+
"semverRange": ">=5.5.1"
28+
},
29+
"device": {
30+
"metaDataVersion": "1.0.0",
31+
"category": "com.microchip.portal.contentRef",
32+
"content": {
33+
"metaDataVersion": "1.0.0",
34+
"category": "com.microchip.device",
35+
"name": "PIC18F56Q24",
36+
"versionRange": "*"
37+
}
38+
},
39+
"author": "Shikhar Tandon",
40+
"peripherals": ["I2C","UART","TMR0","EIC"],
41+
"keywords": ["Lighting","Melody","MCC"],
42+
"additionalData": {
43+
"longDescription": {
44+
"metaDataVersion": "1.0.0",
45+
"category": "com.microchip.portal.fileRef",
46+
"content": {
47+
"metaDataVersion": "1.0.0",
48+
"fileName": "./README.md",
49+
"mimeType": "text/markdown"
50+
}
51+
}
52+
}
53+
}
54+
}

LICENSE.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
(c) 2024 Microchip Technology Inc. and its subsidiaries.
2+
3+
Subject to your compliance with these terms, you may use Microchip software
4+
and any derivatives exclusively with Microchip products. You're responsible
5+
for complying with 3rd party license terms applicable to your use of 3rd
6+
party software (including open source software) that may accompany Microchip
7+
software.
8+
9+
SOFTWARE IS "AS IS." NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY,
10+
APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
11+
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
12+
13+
IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
14+
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
15+
WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP
16+
HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO
17+
THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL
18+
CLAIMS RELATED TO THE SOFTWARE WILL NOT EXCEED AMOUNT OF FEES, IF ANY,
19+
YOU PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
20+

README.md

Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
<!-- Please do not change this logo with link -->
2+
3+
<a target="_blank" href="https://www.microchip.com/" id="top-of-page">
4+
<picture>
5+
<source media="(prefers-color-scheme: light)" srcset="images/mchp_logo_light.png" width="350">
6+
<source media="(prefers-color-scheme: dark)" srcset="images/mchp_logo_dark.png" width="350">
7+
<img alt="Microchip Technologies Inc." src="https://www.microchip.com/content/experience-fragments/mchp/en_us/site/header/master/_jcr_content/root/responsivegrid/header/logo.coreimg.100.300.png/1605828081463/microchip.png">
8+
</picture>
9+
</a>
10+
11+
# Interface VCNL4200 Ambient Light Sensor on Curiosity Nano Explorer with PIC18F56Q24 Curiosity Nano Board
12+
13+
This example demonstrates how the VCNL4200 Ambient Light Sensor on the Curiosity Nano Explorer board operates when interfaced with the PIC18F56Q24 microcontroller. The PIC18F56Q24 Curiosity Nano development board (host) communicates with the VCNL4200 Ambient Light Sensor (client) using the I2C protocol. The example application displays the current light intensity (in lux) every second.
14+
15+
## Related Documentation
16+
17+
- [PIC18F26/45/46/55/56Q24 Data Sheet](https://ww1.microchip.com/downloads/aemDocuments/documents/MCU08/ProductDocuments/DataSheets/PIC18F26-45-46-55-56Q24-Microcontroller-Data-Sheet-XLP-DS40002503.pdf)
18+
- [I2C Host Driver](https://onlinedocs.microchip.com/oxy/GUID-420E6AAC-9141-47BF-A4C7-A6EA17246D0D-en-US-23/GUID-9123ED22-5064-448E-AB55-11C967BB20A4.html?hl=i2c%2Chost)
19+
- [VCNL4200 Data Sheet](https://www.vishay.com/docs/84430/vcnl4200.pdf)
20+
- [VCNL4200 App Note](https://www.vishay.com/docs/84327/designingvcnl4200.pdf)
21+
- [Curiosity Nano Explorer board EV58G97A](https://www.microchip.com/en-us/development-tool/EV58G97A?_ga=2.255984587.1527562019.1718650260-1302344245.1675103399)
22+
- [MPLAB XC8 C Compiler User's Guide for PIC MCU](https://ww1.microchip.com/downloads/en/DeviceDoc/50002737C%20XC8%20C%20Compiler%20UG%20for%20PIC.pdf)
23+
24+
## Software Used
25+
26+
- MPLAB® X IDE 6.20.0 or newer [(MPLAB® X IDE 6.20)](https://www.microchip.com/en-us/development-tools-tools-and-software/mplab-x-ide)
27+
- MPLAB® XC8 3.00 or newer compiler [(MPLAB® XC8 3.00)](https://www.microchip.com/en-us/tools-resources/develop/mplab-xc-compilers/xc8)
28+
- MPLAB® Code Configurator [(MCC Melody)](https://www.microchip.com/en-us/tools-resources/configure/mplab-code-configurator/melody)
29+
30+
## Hardware Used
31+
32+
- [Curiosity Nano Explorer board EV58G97A](https://www.microchip.com/en-us/development-tool/EV58G97A?_ga=2.255984587.1527562019.1718650260-1302344245.1675103399)
33+
- [User guide](https://ww1.microchip.com/downloads/aemDocuments/documents/MCU08/ProductDocuments/UserGuides/CNANO-Explorer-UserGuide-DS50003716.pdf)
34+
- [Schematics](https://ww1.microchip.com/downloads/aemDocuments/documents/MCU08/ProductDocuments/BoardDesignFiles/Curiosity-Nano-Explorer-Schematics.pdf
35+
)
36+
37+
- [PIC18F56Q24 Curiosity Nano](https://www.microchip.com/en-us/development-tool/ev01e86a)
38+
- [PIC18F56Q24 Curiosity Nano User Guide](https://ww1.microchip.com/downloads/aemDocuments/documents/MCU08/ProductDocuments/UserGuides/PIC18F56Q24-CNANO-UserGuide-DS50003618.pdf)
39+
- [Schematics](https://ww1.microchip.com/downloads/aemDocuments/documents/MCU08/ProductDocuments/BoardDesignFiles/PIC18F56Q24-Curiosity-Nano-Schematics.PDF)
40+
41+
- [PIC18F56Q24 product page](https://www.microchip.com/en-us/product/pic18f56q24)
42+
43+
## Block Diagram
44+
45+
The block diagram shows a brief summary of the high level connection beween the microcontroller and the sensor.<br>
46+
- In the [Schematics](https://ww1.microchip.com/downloads/aemDocuments/documents/MCU08/ProductDocuments/BoardDesignFiles/Curiosity-Nano-Explorer-Schematics.pdf
47+
), a 47 kΩ resistor is connected between the Interrupt pin of the VCNL4200 sensor and VCC.
48+
- To achieve the recommended resistance from the [VCNL4200 App Note](https://www.vishay.com/docs/84327/designingvcnl4200.pdf) a 26.5 kΩ resistor is added in parallel, bringing the total resistance down to around 17 kΩ.
49+
![Block Diagram](./images/ALS_sensor_block_diagram.png)
50+
51+
###### Figure 1: Block diagram<br><br><br><br>
52+
53+
## Setup
54+
55+
Connect the PIC18F56Q24 Curiosity Nano development board to the host PC using a USB-C cable. Then, insert the Curiosity Nano into the Curiosity Nano socket on the Curiosity Nano Explorer board, as shown in the figure below.<br><br>
56+
<img src="./images/setup.png" alt="setup.png" width="619" height="561" style="float: left; margin-right: 10px;">
57+
58+
###### Figure 2: Hardware Setup<br><br>
59+
60+
### Pins utilized
61+
| Pins | Function
62+
|----------|----------
63+
| PROX_INT | Interrupt output from the VCNL4200 for proximity or ambient light changes.
64+
| RB0 | Digital input pin on PIC18F56Q24,receives interrupts from PROX_INT
65+
| 3.3V(from MikroE BUS) | Provides 3.3V input voltage to the pull-up resitor used(26.5kohm)
66+
|GND(from MikroE BUS) | Ground pin from MikroE BUS
67+
68+
69+
Remove the jumper wire on PROX_INT pin and pin 16 to allow the PIC18F56Q24 to receive interrupts from the VCNL4200.<br><br>
70+
<img src="./images/prox_int_jumper.png" alt="prox_int_jumper.png" width="250" height="150">
71+
<br><br>Connect the left pin of the PROX_INT 2-pin header to RB0 (pin 30) as shown in the figure below<br><br>
72+
<img src="./images/prox_int_rb0.png" alt="prox_int_rb0.png" width="220" height="150">
73+
74+
The next three figures illustrate this setup, which represents the hardware implementation of the connections depicted in the block diagram (Figure 1). In this configuration, PROX_INT and RB0 are connected to one terminal of a resistor, while the opposite terminal is connected to the 3.3V supply via a red wire. Additionally, a wire runs from the GND pin to the breadboard. <br><br>
75+
<img src="./images/setup_1.png" alt="setup_1.png" width="350" height="350">
76+
77+
###### Figure 3: Setup Part - I<br><br><br><br>
78+
79+
![Setup-II](./images/setup_2.png)
80+
81+
###### Figure 4: Setup Part - II<br><br><br><br>
82+
83+
![Setup-II](./images/setup_3.png)
84+
85+
###### Figure 5: Setup Part - III<br><br><br><br>
86+
87+
88+
89+
1. Open the project 'pic18f56q24-curiosity-nano-explorer-vcnl4200-ambient-sensor' as shown in figure below.<br><br>
90+
91+
![Open Project Window](./images/open_project.png)
92+
###### Figure 6: Open Project Window<br><br>
93+
94+
2. Right click on the Project in the projects tab and click **Properties** to open the Project Properties window. Select the:
95+
- Curiosity Nano device from the **Connected Hardware Tool** drop-down menu, as shown in figure. 7
96+
- Select the latest tool pack
97+
- Select the latest compiler and click **OK**.<br><br>
98+
99+
![Select Tool](./images/select_hw_tool.png)
100+
###### Figure 7: Select the Hardware Tool in Project Properties Window<br><br>
101+
102+
3. Once the project is open, click the **MCC** button in the top toolbar to open it.
103+
104+
![MCC](./images/mcc_setup.png)
105+
###### Figure 8: Open MCC<br><br>
106+
107+
##### Clock Control:
108+
4. Under <u>*Project Resources*</u>><u>*System*</u>><u>*Clock Control*</u>
109+
110+
- The Clock Driver settings are as in the image below<br><br>
111+
112+
![Clock Driver](./images/Clock_control.png)
113+
###### Figure 9: Clock Driver
114+
- We choose a High-Frequency Internal Oscillator (64 Mhz) with a clock divider of 2
115+
<br><br>
116+
117+
##### Timer Setup:
118+
5. Under <u>*Project Resources*</u>><u>*Drivers*</u>><u>*Select TMR0*</u>
119+
120+
- The Timer Driver settings are as in the image below.<br><br>
121+
122+
![TMR Driver](./images/TMR0.png)
123+
###### Figure 10: Timer Driver
124+
125+
- Settings for Timer
126+
1. Timer Mode - 8-bit
127+
2. Clock Pre-Scaler - 1:16384
128+
3. Postscaler - 1:16
129+
4. Clock source - HFINTOSC
130+
5. Requested Period - 1s
131+
6. TMR interrupt - Enabled
132+
7. Callback function Rate - 1
133+
<br><br>
134+
135+
##### UART Setup:
136+
6. Under Project Resources go to Drivers and Select UART
137+
138+
- The UART Driver settings are as in the image below.
139+
140+
![Uart Driver](./images/UART2.png)
141+
###### Figure 11: UART Driver
142+
143+
- Setting for UART:
144+
1. Baud rate - 115200
145+
2. Parity - None
146+
3. Data Size - 8 bits
147+
4. Stop bits - 1
148+
5. Flow Control Mode - None
149+
6. Interrupt Driven - Yes
150+
7. Software Transmit and Receive Buffer Size - 8 bytes
151+
8. UART PLIB Selector - UART2
152+
153+
- RB5 and RB4 are the UART2 TX and RX pins, respectively, as selected below in the pin grid view (in the red circle).
154+
155+
![UART pins](./images/UART2_Pin_Grid_View.png)
156+
###### Figure 12: UART Pin Grid View<br><br>
157+
158+
##### I2C Setup:
159+
7. Under Project Resources go to Drivers and Select I2C1_Host
160+
161+
- The I2C Host Driver settings are as in the image below.
162+
163+
![I2C Driver](./images/I2C1_Host.png)
164+
###### Figure 13: I2C Host <br><br>
165+
166+
- The I2C Peripheral settings are as in the image below.
167+
168+
![I2C Peripheral](./images/I2C1_Peripheral.png)
169+
###### Figure 14: I2C Peripheral <br><br>
170+
171+
- RB1 and RB2 are the SCL and SDA pins for the I2C1 peripheral as selected below in the pin grid view (in the red circle).
172+
173+
![I2C pins](./images/I2C1_Pin_Grid_View.png)
174+
###### Figure 15: I2C Pin Grid View
175+
176+
## Operation
177+
178+
1. After configuring the peripherals in the Setup section, click the **Generate** button on the right side panel in **Project Resources** as shown in the figure below.
179+
180+
![Generate button](./images/MCC_generate.png)
181+
###### Figure 16: MCC Generate Button<br><br>
182+
183+
2. In the right side panel of the **Projects** tab, you will see "MCC Generated Files" in your project folder.
184+
185+
![Project Tree](./images/project_tree.png)
186+
###### Figure 17: Project Tree<br><br>
187+
188+
3. The code execution starts from the ``main.c`` file.
189+
190+
4. The ``app.c`` file handles the initialization of the Ambient Light Sensor (ALS) and reads the light intensity value by interfacing the PIC18F56Q24 microcontroller with the VCNL Ambient Light Sensor.
191+
192+
5. To compile the project and generate the binaries, go to the Production menu in the menu bar and select "Clean and Build Main Project".<br>
193+
![Compile](./images/compile.png)
194+
###### Figure 18: Compile Button<br><br>
195+
196+
6. To flash the binaries on the PIC18F56Q24 click the 'Make and Program Device Main Project' icon in the toolbar.<br>
197+
![Flash](./images/Flash.png)
198+
###### Figure 19: Flash Button<br><br>
199+
200+
7. Now, to observe the live temperature readings follow the below steps:
201+
- Click the "MPLAB Data Visualizer" icon in the toolbar (Step 1 in Figure 20).
202+
- Click the gear icon for the COM port where the PIC MCU is connected to the host PC (Step 2 in Figure 20).
203+
- Set the UART settings as shown below (Step 3 in Figure 20).
204+
205+
![Data Visualizer](./images/data_visualizer.png)
206+
###### Figure 20: Data Visualizer<br><br>
207+
208+
8. Now Click the **Play** button next to the gear icon in the COM port and click the **Send to Terminal** button in the window that pops up and then click **Close** to close the window.
209+
210+
![Play button](./images/Play.png)
211+
###### Figure 21: Play Button<br><br>
212+
213+
![Send to terminal](./images/send_to_terminal.png)
214+
###### Figure 22: Send to Terminal Button<br><br>
215+
216+
9. On the terminal window live light intensity is observed every one second.
217+
218+
![Light readings](./images/light_readings.png)
219+
###### Figure 23: Light Intensity Readings<br><br>
220+
221+
## Demo
222+
<p align="left">
223+
<img src="images/demo.gif" alt="Description" width="500">
224+
</p>
225+
226+
## Summary
227+
228+
This demo demonstrates how to configure the peripherals of the PIC18F56Q24, including Clock, Timer, UART, and I2C, to communicate with the VCNL4200 Ambient Light Sensor using the I2C communication protocol. The light intensity values are then displayed on a UART terminal every second.
29.6 KB
Loading

images/Clock_control.png

31.4 KB
Loading

images/Flash.png

20.8 KB
Loading

images/I2C1_Host.png

17.8 KB
Loading

0 commit comments

Comments
 (0)