|
1 | 1 | [](https://www.microchip.com)
|
2 | 2 |
|
3 | 3 |
|
4 |
| -# PIC16F18446 Sensor Board Battery Measurement |
| 4 | +## Sensor Board Battery Measurement Using the PIC16F18446 Microcontroller |
5 | 5 |
|
6 |
| -The PIC16F184xx family has a new Analog to Digital Converter with Computation (ADCC) with a 12-bit resolution. This project shows how the PIC can internally measure its Vdd using the ADCC and FVR. |
| 6 | +The PIC16F184xx family has a new Analog-to-Digital Converter with Computation (ADCC) with a 12-bit resolution. This project shows how the PIC can internally measure its Vdd using the ADCC and FVR. |
7 | 7 |
|
8 |
| -In this example we will be using the PIC16F18446 Sensor Board. Battery (Vdd) level measurement is performed while the display is turned on. The percentage level of the remaining charge in the batteries is shown as a battery icon with proportional filing in the top-right corner of the display. Additionally, the battery voltage in Volts and percentage graph are displayed. |
| 8 | +This example showcases the PIC16F18446 Sensor Board. Battery (Vdd) level measurement is performed while the display is turned on. The percentage level of the remaining charge in the batteries is shown as a battery icon with proportional filing in the top-right corner of the display. Additionally, the battery voltage in Volts and percentage graph are displayed. |
9 | 9 |
|
10 | 10 | ## Related Documentation
|
11 | 11 | - [PIC16F18446 Product Family Page](https://www.microchip.com/design-centers/8-bit/pic-mcus/device-selection/pic16f18446)
|
12 | 12 | - [PIC16F18446 datasheet](http://ww1.microchip.com/downloads/en/DeviceDoc/40001985B.pdf) for more information or specifications.
|
13 | 13 |
|
14 | 14 |
|
15 | 15 | ## Software Used
|
16 |
| -- MPLAB® X IDE 5.30 or newer [(microchip.com/mplab/mplab-x-ide)](http://www.microchip.com/mplab/mplab-x-ide) |
17 |
| -- MPLAB® XC8 2.10 or a newer compiler [(microchip.com/mplab/compilers)](http://www.microchip.com/mplab/compilers) |
18 |
| -- MPLAB® Code Configurator (MCC) 3.95.0 or newer [(microchip.com/mplab/mplab-code-configurator)](https://www.microchip.com/mplab/mplab-code-configurator) |
19 |
| -- MPLAB® Code Configurator (MCC) Device Libraries 8-bit AVR MCUs 2.3.0 or newer [(microchip.com/mplab/mplab-code-configurator)](https://www.microchip.com/mplab/mplab-code-configurator) |
20 |
| -- PIC16F1xxxx DFP 1.2.99 or newer Device Pack |
| 16 | +- [MPLAB® X IDE](http://www.microchip.com/mplab/mplab-x-ide) v6.15 or newer |
| 17 | +- [MPLAB® XC8](http://www.microchip.com/mplab/compilers) v2.45 or newer |
| 18 | +- [PIC16F1xxxx_DFP](https://packs.download.microchip.com/) v1.2.99 |
21 | 19 |
|
22 | 20 | ## Hardware Used
|
23 |
| -- [PIC16F18446 Sensor Board Demonstration](https://www.microchip.com/promo/pic16f18446-sensor-board-demonstration) |
| 21 | +- [PIC16F18446 Sensor Board Quick Start Guide](http://ww1.microchip.com/downloads/en/DeviceDoc/30010172A.pdf) |
| 22 | + <br><img src="images/PIC16F18446_Sensor_board.PNG" width="800"> |
24 | 23 |
|
| 24 | +## Operation |
| 25 | + |
| 26 | +To program the microcontroller with this MPLAB® X project, follow the steps provided in the [How to Program the Microcontroller](#how-to-program-the-microcontroller) chapter.<br><br> |
25 | 27 |
|
26 | 28 | ## Setup
|
27 | 29 |
|
28 |
| -To get the Vdd voltage, ADCC is used to measure the FVR (which is configured to 1.024V) with Vdd as positive reference. Then the Vdd is calculated using this formula: Vdd = 1.024V * 4096 / ADC_Reading. |
| 30 | +The following configurations must be made for this project: |
| 31 | + |
| 32 | +- Clock Control: |
| 33 | + - Clock Source: HFINTOSC |
| 34 | + - HF Internal Clock: 32 MHz |
| 35 | + - Clock Divider: 1 |
| 36 | + |
| 37 | + <br><img src="images/clock_control.PNG" width="600"> |
| 38 | + |
| 39 | +- Configuration bits: |
| 40 | + - External Oscillator Selection bits: Oscillator disabled |
| 41 | + - Reset Oscillator Selection bits: HFINTOSC (1 MHz) |
| 42 | + - WDT Operating Mode bits: WDT Disabled, SWDTEN is ignored |
| 43 | + |
| 44 | + <br><img src="images/config_bits.jpg" width="600"> |
| 45 | + |
| 46 | +- MSSP1 (SPI): |
| 47 | + - Mode: Host |
| 48 | + - SPI Mode: SPI Mode 0 |
| 49 | + - Input data sampled at: Middle |
| 50 | + - Clock source selection: F<sub>OSC</sub>/4 |
| 51 | + |
| 52 | + <br><img src="images/mssp1(spi).PNG" width="600"> |
| 53 | + |
| 54 | +- CLC1: |
| 55 | + - Enable CLC: Yes |
| 56 | + - Logic Cell mode: AND-OR |
| 57 | + |
| 58 | + <br><img src="images/CLC1.PNG" width="600"> |
| 59 | + |
| 60 | +- CLC2: |
| 61 | + - Enable CLC: Yes |
| 62 | + - Logic Cell mode: AND-OR |
| 63 | + |
| 64 | + <br><img src="images/CLC2.PNG" width="600"> |
| 65 | + |
| 66 | +- FVR: |
| 67 | + - Enable FVR: Yes |
| 68 | + - FVR buffer gain to ADC: 1x |
| 69 | + - FVR buffer gain to other peripherals: 1x |
| 70 | + |
| 71 | + <br><img src="images/FVR.PNG" width="600"> |
| 72 | + |
| 73 | +- ADCC: |
| 74 | + - Enable ADC: Yes |
| 75 | + - Operating Mode: Burst Average mode |
| 76 | + - Result Alignment: Right |
| 77 | + - Positive Input Channel: ANA0 |
| 78 | + - Positive Reference: V<sub>DD</sub> |
| 79 | + - Negative Reference: V<sub>SS</sub> |
| 80 | + - Auto-conversion Trigger: Disabled |
| 81 | + - Acquisition Count: 0 |
| 82 | + - Clock Source: F<sub>OSC</sub> |
| 83 | + - Clock Divider: F<sub>OSC</sub>/128 |
| 84 | + - Repeat: 64 |
| 85 | + |
| 86 | + <br><img src="images/adc_hardware_settings.PNG" width="600"> |
| 87 | + <br><img src="images/adc_clock_and_computation_feature.PNG" width="600"> |
| 88 | + |
| 89 | +| Pin | Configuration | Description | Custom Name | |
| 90 | +| :-: | :------------: | :-----------------------: | :-----------------------: | |
| 91 | +| RC1 | SCK1 | Serial Clock | SCK1 | |
| 92 | +| RB4 | SDI1 | Serial Data In | SDI1 | |
| 93 | +| RC5 | CLC2 | Analog output | IO_RC5 | |
| 94 | +| RC6 | CLC1 | Analog output | IO_RC6 | |
| 95 | +| RB5 | GPIO | Digital input | S2 | |
| 96 | +| RC4 | GPIO | Digital input | S3 | |
| 97 | +| RB7 | GPIO | Digital output | LCD_RESET | |
| 98 | +| RC2 | GPIO | Digital output | LCD_BACKLIGHT | |
| 99 | +| RC7 | GPIO | Digital output | LCD_CS | |
| 100 | + |
| 101 | + <br><img src="images/pin_grid_view.PNG" width="600"> |
| 102 | + <br><img src="images/pins.PNG" width="600"> |
| 103 | + |
| 104 | +## Demo |
29 | 105 |
|
30 |
| -### MCC Settings |
| 106 | +To get the Vdd voltage, ADCC is used to measure the FVR, which is configured to 1.024V, with Vdd as positive reference. Then the Vdd is calculated using this formula: Vdd = 1.024V * 4096 / ADC_Reading. |
31 | 107 |
|
32 |
| -Here are the settings used for MSSP, CLC, FVR, and ADCC. MSSP + CLC are used for the LCD control. |
33 |
| -### MSSP Settings |
34 |
| -<br><img src="images/MSSP1.png" width="600"> |
| 108 | +<br><img src="images/display.png" width="600"> |
35 | 109 |
|
36 |
| -### CCL Settings |
37 |
| -<br><img src="images/CLC1.png" width="600"> |
| 110 | +## Summary |
38 | 111 |
|
39 |
| -<br><img src="images/CLC2.png" width="600"> |
| 112 | +This code example shows how to use the Battery level measurement feature on the Sensor Board, using MSSP and CLC for LCD control, FVR and ADCC. |
40 | 113 |
|
41 |
| -### FVR Settings |
42 |
| -<br><img src="images/FVR.png" width="600"> |
| 114 | +## How to Program the Microcontroller |
43 | 115 |
|
44 |
| -### ADCC settings |
45 |
| -<br><img src="images/ADCC1.png" width="600"> |
46 |
| -ADRPT register is set to 0x40, to average a burst of 64 samples. |
47 |
| -<br><img src="images/ADCC2.png" width="600"> |
| 116 | +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. |
48 | 117 |
|
49 |
| -### PIN Grid |
50 |
| -<br><img src="images/PIN_Grid.png" width="600"> |
| 118 | +1. Connect the Sensor board to the PC. |
51 | 119 |
|
52 |
| -### PIN Module |
53 |
| -<br><img src="images/PIN_Module.png" width="600"> |
| 120 | +2. Open the `Example_Project.X` project in MPLAB X IDE. |
54 | 121 |
|
55 |
| -## Demo |
56 |
| -<br><img src="images/display.png" width="600"> |
| 122 | +3. Set the `Example_Project.X` project as main project. |
| 123 | + <br>Right click the project in the **Projects** tab and then Set as Main Project. |
| 124 | + <br><img src="images/Program_Set_as_Main_Project.PNG" width="600"> |
| 125 | + |
| 126 | +4. Clean and build the `Example_Project.X` project. |
| 127 | + <br>Right click the `Example_Project.X` project and select Clean and Build. |
| 128 | + <br><img src="images/Program_Clean_and_Build.PNG" width="600"> |
| 129 | + |
| 130 | +5. Select Starter Kits (PKOB) in the Connected Hardware Tool section of the project settings: |
| 131 | + <br>Right click the project and **Properties**. |
| 132 | + <br>Click the arrow under the Connected Hardware Tool, and from the dropdown, select Starter Kits (PKOB) by clicking the SN. |
| 133 | + <br>Click **Apply** and then **OK**. |
| 134 | + <br><img src="images/Program_Tool_Selection.PNG" width="600"> |
| 135 | + |
| 136 | +6. Program the project to the microcontroller. |
| 137 | + <br>Right click the project and then Make and Program Device. |
| 138 | + <br><img src="images/Program_Make_and_Program_Device.PNG" width="600"> |
| 139 | + |
| 140 | +<br> |
| 141 | + |
| 142 | +- [Back to Top](#sensor-board-battery-measurement-using-the-pic16f18446-microcontroller) |
| 143 | +- [Back to Setup](#setup) |
| 144 | +- [Back to Demo](#demo) |
| 145 | +- [Back to Summary](#summary) |
0 commit comments