Beginner
10 min

Discover new directions with AK8963 and PIC18F57Q43

Chart your course with eCompass innovation

Compass 2 Click with Curiosity Nano with PIC18F57Q43

Published Feb 13, 2024

Click board™

Compass 2 Click

Dev Board

Curiosity Nano with PIC18F57Q43

Compiler

NECTO Studio

MCU

PIC18F57Q43

Experience the future of direction-finding with our electronic compass technology. It offers precision and responsiveness, making it an essential tool for applications based on position detection, navigation, and orientation.

A

A

Hardware Overview

How does it work?

Compass 2 Click is based on the AK8963, a 3-axis electronic compass from AKM Semiconductor. This electronic compass includes an A/D converter for magnetometer data output in two selectable resolutions. The sensitivity for 14-bit resolution is typically 0.6μT/LSB, while for 16-bit, it is typically 0.15μT/LSB. Some other functions built into this electronic compass are a power-on reset circuit, a data-ready indicator, a magnetic sensor overflow monitor function, a self-test function for a built-in internal magnetic source, and very low power consumption. The AK8963 has several operating modes. All internal circuits are turned off in Power-down mode while all registers are accessible (fuse ROM data cannot be read correctly). In Signal measurement mode, the sensor is measured, and data is processed. The Continuous measurement

mode differs from the Single measurement because the sensor is measured periodically at 8Hz or 100Hz, after which the data is processed. The third measurement mode is an External trigger measurement that will start after the AK8963 gets a trigger input. To check if the sensor is working normally, AK8963 uses the Self-test mode. This test the AK8963 achieves by generating a magnetic field by its internal magnetic source, and then the sensor is measured. The last is the Fuse ROM access mode, which reads Fuse ROM data (sensitivity adjustment data for each axis). This Click board™ allows the use of both I2C and SPI interfaces. Selection is made by positioning SMD jumpers marked SPI I2C to the appropriate position. All jumpers must be on the same side, or the Click

board™ may become unresponsive. When the I2C interface is selected, the AK8963 allows the choice of its I2C address, using the ADDR SEL SMD jumper set to an appropriate position marked 1 or 0. In addition to the general reset function (RST pin), there is also the INT pin used as an interrupt signal to tell the host MCU about the status of the AK8963, and the TRG pin which serves as a trigger pin to make the AK8963 to enter the External Trigger measurement mode. This Click board™ can be operated only with a 3.3V logic voltage level. The board must perform appropriate logic voltage level conversion before using MCUs with different logic levels. Also, it comes equipped with a library containing functions and an example code that can be used as a reference for further development.

Compass 2 Click top side image
Compass 2 Click bottom side image

Features overview

Development board

PIC18F57Q43 Curiosity Nano evaluation kit is a cutting-edge hardware platform designed to evaluate microcontrollers within the PIC18-Q43 family. Central to its design is the inclusion of the powerful PIC18F57Q43 microcontroller (MCU), offering advanced functionalities and robust performance. Key features of this evaluation kit include a yellow user LED and a responsive

mechanical user switch, providing seamless interaction and testing. The provision for a 32.768kHz crystal footprint ensures precision timing capabilities. With an onboard debugger boasting a green power and status LED, programming and debugging become intuitive and efficient. Further enhancing its utility is the Virtual serial port (CDC) and a debug GPIO channel (DGI

GPIO), offering extensive connectivity options. Powered via USB, this kit boasts an adjustable target voltage feature facilitated by the MIC5353 LDO regulator, ensuring stable operation with an output voltage ranging from 1.8V to 5.1V, with a maximum output current of 500mA, subject to ambient temperature and voltage constraints.

PIC18F57Q43 Curiosity Nano double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

PIC

MCU Memory (KB)

128

Silicon Vendor

Microchip

Pin count

48

RAM (Bytes)

8196

You complete me!

Accessories

Curiosity Nano Base for Click boards is a versatile hardware extension platform created to streamline the integration between Curiosity Nano kits and extension boards, tailored explicitly for the mikroBUS™-standardized Click boards and Xplained Pro extension boards. This innovative base board (shield) offers seamless connectivity and expansion possibilities, simplifying experimentation and development. Key features include USB power compatibility from the Curiosity Nano kit, alongside an alternative external power input option for enhanced flexibility. The onboard Li-Ion/LiPo charger and management circuit ensure smooth operation for battery-powered applications, simplifying usage and management. Moreover, the base incorporates a fixed 3.3V PSU dedicated to target and mikroBUS™ power rails, alongside a fixed 5.0V boost converter catering to 5V power rails of mikroBUS™ sockets, providing stable power delivery for various connected devices.

Curiosity Nano Base for Click boards accessories 1 image

Used MCU Pins

mikroBUS™ mapper

External Trigger Pulse
PA0
AN
Reset
PA7
RST
SPI Chip Select
PD4
CS
SPI Clock
PC6
SCK
SPI Data OUT
PC5
MISO
SPI Data IN
PC4
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
Interrupt
PA6
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PB2
SCL
I2C Data
PB1
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

Compass 2 Click Schematic schematic

Step by step

Project assembly

Curiosity Nano Base for Click boards front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Curiosity Nano with PIC18F57Q43 as your development board.

Curiosity Nano Base for Click boards front image hardware assembly
Charger 27 Click front image hardware assembly
PIC18F47Q10 Curiosity Nano front image hardware assembly
Prog-cut hardware assembly
Curiosity Nano with PICXXX Access MB 1 - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
Necto image step 5 hardware assembly
Necto image step 6 hardware assembly
PIC18F57Q43 Curiosity MCU Step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware assembly

Track your results in real time

Application Output

This Click board can be interfaced and monitored in two ways:

  • Application Output - Use the "Application Output" window in Debug mode for real-time data monitoring. Set it up properly by following this tutorial.

Software Support

Library Description

This library contains API for Compass 2 Click driver.

Key functions:

  • compass2_get_axis_data - This function gets the data from one specified axis

  • compass2_new_measurement - This function prepares the device for a new measurement

  • compass2_reset - This function does a hardware reset of the device.

Open Source

Code example

The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.

/*!
 * \file 
 * \brief Comass2 Click example
 * 
 * # Description
 * The example prepares the device for a new measurement and reads and displays data from all three axes.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes and configures the click and logger modules.
 * 
 * ## Application Task  
 * Reads and displays data from all three axes every two seconds.
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "compass2.h"

// ------------------------------------------------------------------ VARIABLES

static compass2_t compass2;
static log_t logger;

// ------------------------------------------------------ APPLICATION FUNCTIONS

void application_init ( )
{
    log_cfg_t log_cfg;
    compass2_cfg_t cfg;

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, "---- Application Init ----" );

    //  Click initialization.

    compass2_cfg_setup( &cfg );
    COMPASS2_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    compass2_init( &compass2, &cfg );

    compass2_reset( &compass2 );
    Delay_ms( 100 );

    compass2_default_cfg( &compass2 );
    Delay_ms( 100 );
}

void application_task ( )
{
    int16_t x_axis;
    int16_t y_axis;
    int16_t z_axis;
    
    compass2_new_measurement( &compass2 );
    
    log_printf( &logger, " --- Axis ---\r\n" );

    x_axis = compass2_get_axis_data( &compass2, COMPASS2_X_AXIS );
    y_axis = compass2_get_axis_data( &compass2, COMPASS2_Y_AXIS );
    z_axis = compass2_get_axis_data( &compass2, COMPASS2_Z_AXIS );
    
    log_printf( &logger, "X: %d\r\n", x_axis );
    log_printf( &logger, "Y: %d\r\n", y_axis );
    log_printf( &logger, "Z: %d\r\n", z_axis );

    log_printf( &logger, "----------------\r\n" );
    
    Delay_ms( 2000 );
}

void main ( )
{
    application_init( );

    for ( ; ; )
    {
        application_task( );
    }
}

// ------------------------------------------------------------------------ END

Additional Support

Resources

Love this project?

'Buy This Kit' button takes you directly to the shopping cart where you can easily add or remove products.