The PIC16F184xx family has a new Analog-to-Digital Converter with Computation (ADCC) with a 12-bit resolution. This project shows the reading of an analog temperature sensor (MCP9701) using the ADCC.
This example showcases the PIC16F18446 Sensor Board. The PIC reads the temperature sensor, and displays the temperature on the LCD. The sensor has a temperature coefficient of 19.5 mV/°C. It is sensitive enough to detect the heat of the user's hand from a distance of 1 cm. The temperature sensor is shown in the image below:
- PIC16F18446 Product Family Page
- PIC16F18446 Datasheet for more information or specifications.
- MPLAB® X IDE v6.15 or newer
- MPLAB® XC8 v2.45 or newer
- PIC16F1xxxx_DFP v1.2.99
To program the microcontroller with this MPLAB® X project, follow the steps provided in the How to Program the Microcontroller chapter.
The following configurations must be made for this project:
-
Clock Control:
- Clock Source: HFINTOSC
- HF Internal Clock: 32 MHz
- Clock Divider: 1
-
Configuration bits:
- External Oscillator Selection bits: Oscillator disabled
- Reset Oscillator Selection bits: HFINTOSC (1 MHz)
- WDT Operating Mode bits: WDT Disabled, SWDTEN is ignored
-
MSSP1 (SPI):
- Mode: Host
- SPI Mode: SPI Mode 0
- Input data sampled at: Middle
- Clock source selection: FOSC/4
-
CLC1:
- Enable CLC: Yes
- Logic Cell mode: AND-OR
-
CLC2:
- Enable CLC: Yes
- Logic Cell mode: AND-OR
-
FVR:
- Enable FVR: Yes
- FVR buffer gain to ADC: 1x
- FVR buffer gain to other peripherals: 1x
-
ADCC:
- Enable ADC: Yes
- Operating Mode: Burst Average mode
- Result Alignment: Right
- Positive Input Channel: ANC3
- Positive Reference: FVR
- Negative Reference: VSS
- Auto-conversion Trigger: Disabled
- Acquisition Count: 0
- Clock Source: FOSC
- Clock Divider: FOSC/128
- Repeat: 64
Pin | Configuration | Description | Custom Name |
---|---|---|---|
RC1 | SCK1 | Serial Clock | SCK1 |
RB4 | SDI1 | Serial Data In | S3 |
RC5 | CLC2 | Analog output | IO_RC5 |
RC6 | CLC1 | Analog output | IO_RC6 |
RC3 | ADCC | Analog input | channel_Temperature |
RB5 | GPIO | Digital input | S2 |
RB7 | GPIO | Digital output | LCD_RESET |
RC2 | GPIO | Digital output | LCD_BACKLIGHT |
RC4 | GPIO | Digital input | IO_RC4 |
RC7 | GPIO | Digital output | LCD_CS |
The current temperature is displayed, in °C, on the LCD. Also, two graphs display the variations of the 12-bit and 10-bit temperature values in real time.
This code example shows how to use the temperature sensor on the Sensor Board, featuring MSSP, CLC, FVR and ADCC peripherals.
This chapter demonstrates how to use the MPLAB X IDE to program a PIC® device with an Example_Project.X
. This applies to other projects.
-
Connect the Sensor board to the PC.
-
Open the
Example_Project.X
project in MPLAB X IDE. -
Set the
Example_Project.X
project as main project.
Right click the project in the Projects tab and then Set as Main Project. -
Clean and build the
Example_Project.X
project.
Right click theExample_Project.X
project and select Clean and Build. -
Select Starter Kits (PKOB) in the Connected Hardware Tool section of the project settings:
Right click the project and Properties.
Click the arrow under the Connected Hardware Tool, and from the dropdown, select Starter Kits (PKOB) by clicking the SN.
Click Apply and then OK. -
Program the project to the microcontroller.
Right click the project and then Make and Program Device.