Skip to content

microchip-pic-avr-examples/pic16f18446-sensor-board-metal-detection

Repository files navigation

MCHP

Sensor Board Metal Detector Using the PIC16F18446 Microcontroller

The PIC16F184xx family has a new Analog-to-Digital Converter with Computation (ADCC) with a 12-bit resolution. This project shows the reading of a metal detector using the ADCC.

In this example, the PIC16F18446 is used. The board scans the metal detector LC circuit to find the peak (resonant) frequency. It then supplies a signal with that frequency using the Numerically Controlled Oscillator (NCO) and reads the ADCC. If a metal object approaches, it shifts the resonant frequency and the ADCC value changes. This project has two operating modes.

In the first mode, the 12-bit and 10-bit values are plotted in real time. When entering this mode, the first ADCC reading is used as an offset for the plots.

In the second mode, the buzzer's beeping time interval depends on the metal detector reading.

Related Documentation

Software Used

Hardware Used


Operation

To program the microcontroller (MCU) with this MPLAB® X project, follow the steps provided in the How to Program the Microcontroller section.

Setup

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: Oscillator not enabled
    • Reset Oscillator Selection: HFINTOSC (1 MHz)


  • MSSP:

    • Serial Protocol: SPI
    • Mode: Host
    • SPI Mode: SPI Mode 0
    • Input Data Sampled at: Middle
    • Clock Source Selection: FOSC/4


  • CLC:

    • Enable CLC: Yes
    • Operating Mode: AND-OR



  • NCO:
    NCO is used to oscillate the LC circuit.

    • Enable NCO: Yes
    • NCO Mode: FDC_mode
    • Output Polarity: active_hi
    • Clock Source: HFINTOSC
    • Requested NCO Output Frequency (Hz): 35000


  • FVR:
    FVR is used as a positive reference for the ADCC's higher accuracy and gain.

    • 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: ANC0
    • Positive Reference: FVR
    • Negative Reference: VSS
    • Auto-conversion Trigger: Disabled
    • Acquisition Count: 0
    • Clock Source: FOSC
    • Clock Divider: FOSC/128
    • Repeat: 64



    Repeat is set to 64 to average a burst of 64 samples.

  • CWG:
    Complementary Waveform Generator (CWG) outputs the signal from CCP1 in antiphase on 2 pins, so that the buzzer sounds louder.

    • Enable CWG: Yes
    • Input Source: CCP1_OUT
    • Output Mode: Half Bridge mode
    • Clock Source: FOSC


  • CCP1:
    CCP1 generates the buzzer tone.

    • Enable CCP: Yes
    • CCP Mode: Compare
    • Select Timer: Timer 1
    • Mode: Toggle_cleartmr


  • TMR1:
    TMR1 is used to clock the CCP1. It sets the pitch of the buzzer tone.

    • Enable Timer: Yes
    • Clock Source: FOSC/4
    • Prescaler: 1:4
    • External Clock Input Sync: Synchronize
    • Timer Period (s): 0.0327675


  • TMR3:
    TMR3 sets the beep interval.

    • Enable Timer: Yes
    • Clock Source: MFINTOSC_31.25kHz
    • Prescaler: 1:2
    • External Clock Input Sync: Synchronize
    • Timer Period (s): 0.1
    • TMR Interrupt Enable: Yes
    • Callback Factor: 1



  • PIN_Grid


  • PIN_Module

Demo

Board setup:


Summary

This code exemple shows the reading of a metal detector using the ADCC peripheral.

How to Program the Microcontroller

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.

  1. Connect the Curiosity Development board to the PC.

  2. Open the Example_Project.X project in MPLAB X IDE.

  3. Set the Example_Project.X project as main project.
    Right click the project in the Projects tab and then Set as Main Project.

  4. Clean and build the Example_Project.X project.
    Right click the Example_Project.X project and select Clean and Build.

  5. 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.

  6. Program the project to the microcontroller.
    Right click the project and then Make and Program Device.