Skip to content

This code example demonstrates how to interface a bipolar hall sensor to PIC microcontroller through built-in CCP peripheral. Compatible PIC16F152xx family of MCUs are PIC16F15214,PIC16F15223,PIC16F15254,PIC16F15276.

License

Notifications You must be signed in to change notification settings

microchip-pic-avr-examples/pic16f15244-cnano-bipolar-hall-sensor-interface-mplab-mcc

Repository files navigation

MCHP

Interfacing Bipolar Hall Sensor to PIC16F15244 Microcontroller

Introduction

The bipolar Hall sensor is used in a variety of applications, such as the internal combustion engine ignition timing, the anti-lock braking system or tachometers. It works on the principle of Hall effect and is sensitive to both the North and South pole magnetic fields. It generates a high-to-low pulse signal when exposed to the North pole magnetic field, and a low-to-high pulse when exposed to the South one. This code example presents a use case focused on measuring the speed and distance covered by a wheel using a bipolar Hall sensor interfaced to a microcontroller (MCU).

This project demonstrates the usage of Capture/Compare/PWM (CCP), Timer, Universal Asynchronous Receiver Transmitter (UART) and PWM (Pulse-Width Modulation) peripherals of the PIC16F15244 microcontroller for interfacing a bipolar Hall sensor using the Capture mode of the CCP peripheral available in the PIC16F152xx microcontroller family. The Capture mode is used to detect the pulses generated by the bipolar Hall sensor in the presence of magnetic field. The speed and distance covered by the wheel are calculated using these captured pulses.

Note: This example can be generated with all the pin variants of the PIC16F152xx microcontrollers family.

Related Documentation

Demo Description

This example aims to capture the pulses generated by the bipolar Hall effect sensor in the presence of magnetic field using the CCP peripheral of the MCU. The PIC16F15244 Curiosity Nano Evaluation kit and Curiosity Nano Base for Click boards™ are used as a development platform. A small rotating wheel is connected to a DC motor. The DC Motor 8 click is used to drive the DC motor which rotates the wheel. The BI HALL click detects the number of rotations completed by the wheel and provides digital output. When the sensor is exposed to the South pole magnetic field, it produces the low-level pulse, and when it is exposed to North one, it produces the high-level pulse.


Figure 1. Block Diagram View of the Application

A piece of magnet is stuck on the wheel and the BI HALL click is placed near it, in such a way that every time the wheel rotates, the Hall sensor detects it and generates a pulse signal. This pulse signal is captured by the CCP peripheral of microcontroller, which counts the number of pulses generated within a specified duration. One pulse signal indicates the completion of a wheel rotation. The speed and distance covered by the wheel are calculated based on the number of rotations completed in a specified duration and are displayed on the terminal window through the UART interface. The onboard switch of the PIC16F15244 Curiosity Nano board is used to vary the speed of the wheel through the PWM interface.

Software Used

  • MPLAB® X IDE 6.15 or newer
  • MPLAB XC8 2.45 or newer
  • MPLAB Code Configurator (MCC) 5.3.7 or newer
  • Microchip PIC16F1xxxx Series Device Support 1.20.366 or newer
  • Standalone Data Visualizer 2.20.674 or newer
  • MCC Melody Core 2.6.1
  • Capture Compare and PWM (CCP) MCC Melody driver 4.0.12
  • Timer0 (TMR0) MCC Melody driver 4.0.11
  • Timer1 (TMR1) MCC Melody driver 4.3.6
  • Timer2 (TMR2) MCC Melody driver 4.0.16
  • Universal Asynchronous Receiver and Transmitter (UART) MCC Melody driver 1.8.0

Notes:

1. The integrated MPLAB Data visualizer can also be used as a terminal window.

2. For running this demo, the installed tool version should be same or later. This example is not tested with the previous versions.

Hardware Used

Hardware Setup

  • Connect the PIC16F15244 Curiosity Nano (CNANO) board to the Curiosity Nano footprint on the Curiosity Nano Base for Click boards
  • Insert the DC Motor 8 click into the mikroBUS™ slot 1, and the BI HALL click into the mikroBUS™ slot 2 on Curiosity Nano Base for Click boards
  • Connect the VOUT and GND pins of the DC Motor 8 click to the +ve and -ve terminal of the DC Motor
  • Connect the VIN and GND pins of the DC Motor 8 click to the VBUS and GND ports of the Curiosity Nano Base for Click boards, as shown in Figure 2
  • Short the RB4 pin in the PIC16F15244 CNANO board to the INT2 pin in the Curiosity Nano Base for Click boards, because the MCU port is not available for the INT2 pin (Hall sensor pulse output)


Figure 2. Hardware Setup Connections

Hardware Connection Table

The following table shows the pin connection details of the hardware setup:

Slot No. Microcontroller Pin Click Board/Peripheral Signal Name I/O Pin Direction
1 RC7 DC Motor 8 EN (enables DC motor) OUT
2 RC3 DC Motor 8 PWM (varies speed) OUT
3 RB4 BI HALL INT (pulse signal) IN
4 RC0 UART peripheral TX OUT

Demo Operation

  • Configure the hardware as shown in the hardware setup section. Open the Data Visualizer and select the Virtual COM port to which the PIC16F15244 CNANO board is connected. Refer to the Data Visualizer User's Guide for more details. Set the baud rate to 115200 and click Connect as shown in Figure 3.


Figure 3. Data Visualizer

Note: Alternately, the user can use any terminal window to visualize the data.

  • Connect the PIC16F15244 Curiosity Nano board RB4 pin (SDA) to the Curiosity Nano Base Board INT2 pin
  • Download and open the project in MPLAB X IDE. Build the project to make sure there are no build errors. Refer to the MPLAB User's Guide for more details on how to build the project.
  • Program the microcontroller by clicking the ‘Make and program device’ icon on MPLAB X IDE
  • Start the wheel rotation at low speed, by pressing the onboard switch on the PIC16F15244 Curiosity Nano board. The speed and distance covered by the wheel are displayed on the terminal window, as shown in Figure 4.


Figure 4. Output Displayed on the Terminal Window at Low Wheel Speed

  • Change the wheel rotation speed to average speed, by pressing the onboard switch the second time. The speed and distance covered by the wheel are displayed on the terminal window, as shown in Figure 5.


Figure 5. Output Displayed on the Terminal Window at Average Wheel Speed

  • Change the wheel rotation speed to high speed, by pressing the onboard switch the third time. The speed and distance covered by the wheel are displayed on the terminal window, as shown in Figure 6.


Figure 6. Output Displayed on the Terminal Window at High Wheel Speed

  • Stop the wheel rotation by pressing the onboard switch the fourth time. The covered distance remains the same and speed is displayed as zero on the terminal window, as shown in Figure 7.


Figure 7. Output Displayed on the Terminal Window when the Wheel Stops Rotating

Conclusion

This example demonstrates how the pulse signal generated by the bipolar hall sensor in the presence of magnetic field is captured by the CCP peripheral of the PIC16F15244 microcontroller.

About

This code example demonstrates how to interface a bipolar hall sensor to PIC microcontroller through built-in CCP peripheral. Compatible PIC16F152xx family of MCUs are PIC16F15214,PIC16F15223,PIC16F15254,PIC16F15276.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published