Intermediate
30 min

Building stable motion sensing solution with ICG-1020S and PIC18F4685

Helping you keep your balance in a topsy-turvy world!

Gyro 7 Click with Curiosity HPC

Published Nov 01, 2023

Click board™

Gyro 7 Click

Dev Board

Curiosity HPC

Compiler

NECTO Studio

MCU

PIC18F4685

Advanced solution for precise orientation and angular velocity measurement and stabilization

A

A

Hardware Overview

How does it work?

Gyro 7 Click is based on the ICG-1020S, a high-performance 2-axis gyroscope from TDK InvenSense. The ICG-1020S is highly configurable with a full-scale programmable range from ±46.5dps to ±374dps. The single structure vibratory MEMS rate gyroscope detects the X- and Y-axis rotation. When the gyroscope is rotated about any sense axes, the Coriolis effect causes a detected vibration. The resulting signal is amplified, demodulated, and filtered to produce a proportional voltage to the angular rate. With its 2-axis integration, this Click board™ allows users to design it into an optical image stabilization (OIS) application. Two-axis MEMS rate gyroscope sensor, the ICG-1020S,

comes with integrated 16-bit ADCs and signal conditioning with two axes XY configuration. After digitizing the signal, data is processed through a digital filter and output through sensor data registers. Besides, the ICG-1020S is also characterized by high resolution and low RMS noise, noise density, a fast sample rate of up to 32kHz, and low power consumption. Gyro 7 Click communicates with MCU through a register-selectable standard SPI interface that enables high clock speed up to 20MHz, supporting the two most common SPI modes, SPI Mode 0 and 3. Other blocks include onboard clocking, temperature compensation, and bias circuits.

The sensor data registers contain the latest gyro data, which are read-only registers accessible via the serial interface. Data from these registers may be read anytime. It also possesses an additional interrupt signal, routed on the INT pin of the mikroBUS™ socket labeled as INT, indicating when a specific interrupt event occurs. This Click board™ can only be operated with a 3.3V logic voltage level. The board must perform appropriate logic voltage level conversion before using MCUs with different logic levels. However, the Click board™ comes equipped with a library containing functions and an example code that can be used as a reference for further development.

Gyro 7 Click top side image
Gyro 7 Click lateral side image
Gyro 7 Click bottom side image

Features overview

Development board

Curiosity HPC, standing for Curiosity High Pin Count (HPC) development board, supports 28- and 40-pin 8-bit PIC MCUs specially designed by Microchip for the needs of rapid development of embedded applications. This board has two unique PDIP sockets, surrounded by dual-row expansion headers, allowing connectivity to all pins on the populated PIC MCUs. It also contains a powerful onboard PICkit™ (PKOB), eliminating the need for an external programming/debugging tool, two mikroBUS™ sockets for Click board™ connectivity, a USB connector, a set of indicator LEDs, push button switches and a variable potentiometer. All

these features allow you to combine the strength of Microchip and Mikroe and create custom electronic solutions more efficiently than ever. Each part of the Curiosity HPC development board contains the components necessary for the most efficient operation of the same board. An integrated onboard PICkit™ (PKOB) allows low-voltage programming and in-circuit debugging for all supported devices. When used with the MPLAB® X Integrated Development Environment (IDE, version 3.0 or higher) or MPLAB® Xpress IDE, in-circuit debugging allows users to run, modify, and troubleshoot their custom software and hardware

quickly without the need for additional debugging tools. Besides, it includes a clean and regulated power supply block for the development board via the USB Micro-B connector, alongside all communication methods that mikroBUS™ itself supports. Curiosity HPC development board allows you to create a new application in just a few steps. Natively supported by Microchip software tools, it covers many aspects of prototyping thanks to many number of different Click boards™ (over a thousand boards), the number of which is growing daily.

Curiosity HPC double image

Microcontroller Overview

MCU Card / MCU

PIC18F4685

Architecture

PIC

MCU Memory (KB)

96

Silicon Vendor

Microchip

Pin count

40

RAM (Bytes)

3328

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
NC
NC
RST
SPI Chip Select
RA3
CS
SPI Clock
RB1
SCK
SPI Data OUT
RB2
MISO
SPI Data IN
RB3
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
Interrupt
RB5
INT
NC
NC
TX
NC
NC
RX
NC
NC
SCL
NC
NC
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Schematic

Gyro 7 Click Schematic schematic

Step by step

Project assembly

Curiosity HPC front no-mcu image hardware assembly

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

Curiosity HPC front no-mcu image hardware assembly
Thermo 28 Click front image hardware assembly
MCU DIP 40 hardware assembly
Prog-cut hardware assembly
Curiosity HPC MB 1 - upright/with-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
Necto DIP image step 7 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

After loading the code example, pressing the "DEBUG" button builds and programs it on the selected setup.

Application Output Step 1

After programming is completed, a header with buttons for various actions available in the IDE appears. By clicking the green "PLAY "button, we start reading the results achieved with Click board™.

Application Output Step 3

Upon completion of programming, the Application Output tab is automatically opened, where the achieved result can be read. In case of an inability to perform the Debug function, check if a proper connection between the MCU used by the setup and the CODEGRIP programmer has been established. A detailed explanation of the CODEGRIP-board connection can be found in the CODEGRIP User Manual. Please find it in the RESOURCES section.

Application Output Step 4

Software Support

Library Description

This library contains API for Gyro 7 Click driver.

Key functions:

  • gyro7_get_int_pin This function returns the INT pin logic state.

  • gyro7_read_gyroscope This function reads the gyroscope's X and Y axis in degrees per second (dps).

  • gyro7_read_temperature This function reads the internal temperature in Celsius.

Open Source

Code example

This example can be found in NECTO Studio. Feel free to download the code, or you can copy the code below.

/*!
 * @file main.c
 * @brief Gyro7 Click example
 *
 * # Description
 * This example demonstrates the use of Gyro 7 click board by reading and displaying
 * the values of X and Y axis in degrees per second and the chip internal temperature in Celsius.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and performs the click default configuration which sets the sample rate
 * to 40 Hz, gyroscope resolution to 374 dps, and enables the data ready interrupt.
 *
 * ## Application Task
 * Waits for the data ready interrupt, then reads the values of X and Y gyroscope axis as well as
 * the chip internal temperature and displays the results on the USB UART. The data sample rate is 
 * set to 40Hz by default, therefore the data is being read approximately every 25ms.
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "gyro7.h"

static gyro7_t gyro7;
static log_t logger;

void application_init ( void )
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    gyro7_cfg_t gyro7_cfg;  /**< Click config object. */

    /** 
     * 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.
    gyro7_cfg_setup( &gyro7_cfg );
    GYRO7_MAP_MIKROBUS( gyro7_cfg, MIKROBUS_1 );
    if ( SPI_MASTER_ERROR == gyro7_init( &gyro7, &gyro7_cfg ) )
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    if ( GYRO7_ERROR == gyro7_default_cfg ( &gyro7 ) )
    {
        log_error( &logger, " Default configuration." );
        for ( ; ; );
    }
    
    log_info( &logger, " Application Task " );
}

void application_task ( void )
{
    if ( gyro7_get_int_pin ( &gyro7 ) )
    {
        float x_axis, y_axis, temperature;
        if ( GYRO7_OK == gyro7_read_gyroscope ( &gyro7, &x_axis, &y_axis ) )
        {
            log_printf( &logger, " X : %.2f dps\r\n", x_axis );
            log_printf( &logger, " Y : %.2f dps\r\n", y_axis );
        }
        if ( GYRO7_OK == gyro7_read_temperature ( &gyro7, &temperature ) )
        {
            log_printf( &logger, " Temperature : %.2f C\r\n\n", temperature );
        }
    }
}

void main ( void )
{
    application_init( );

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

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

Additional Support

Resources