Intermediate
30 min

Discover the magnet's angular position with MAQ470GQE and PIC32MX795F512L

It's all about the angle

Angle 6 Click with EasyPIC Fusion v7

Published Mar 11, 2023

Click board™

Angle 6 Click

Dev. board

EasyPIC Fusion v7

Compiler

NECTO Studio

MCU

PIC32MX795F512L

Calculates the absolute angular position of a permanent magnet

A

A

Hardware Overview

How does it work?

Angle 6 Click is based on the MAQ470GQE, 12-bit PWM output angle sensor that detects the absolute angular position of a permanent magnet, typically a diametrically magnetized cylinder on a rotating shaft from Monolithic Power Systems. It allows users to read angle position information and detect the speed or direction of magnet rotation. Fast data acquisition and processing provide accurate angle measurement from 0 to 60,000 rpm. It supports many magnetic field strengths and spatial configurations, with both end-of-shaft and off-axis (side-shaft mounting) supported configurations. The MAQ470GQE features magnetic field strength detection with programmable thresholds to allow sensing of the magnet position relative to the sensor to create functions such as sensing axial movements or diagnostics. It can operate over a wide magnetic field range from 30mT to 150mT (60mT typical) with 5mT accuracy.

Eight magnetic field thresholds are programmable in approximate 15mT steps allowing the detection of changes in the distance between the magnet and the sensor. On-chip non-volatile memory provides storage for configuration parameters, including the reference zero angle position and magnetic field detection thresholds. The magnetic field is detected with integrated Hall devices in the sensors' center. The angle is measured using the Spinaxis™ method, based on phase detection generating a sinusoidal signal with a phase representing the angle of the magnetic field. The angle is then obtained by a time-to-digital converter, representing output from the front end to the digital conditioning block, which measures the time between the zero-crossing of the sinusoidal signal and the edge of a constant waveform. This output delivers a digital number proportional to the angle of the magnetic field at the rate of 1MHz in

a straightforward and open-loop manner. The Angle 6 Click communicates with MCU using the standard SPI serial interface for angle reading and register programming, which supports SPI Mode 0 and 3 and operates at clock rates up to 25 MHz. It also has the magnetic flags used to indicate when the sensor position's magnetic field is out of range, defined by the lower and upper magnetic field thresholds, routed on the RST and INT pins of the mikroBUS™ socket labeled as MGH and MGL. 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.

Angle 6 Click top side image
Angle 6 Click lateral side image
Angle 6 Click bottom side image

Features overview

Development board

EasyPIC Fusion v7 is the seventh generation of PIC development boards specially designed to develop embedded applications rapidly. It supports a wide range of 16/32-bit PIC microcontrollers from Microchip and a broad set of unique functions, such as a powerful onboard mikroProg programmer and In-Circuit debugger over USB-B. The development board is well organized and designed so that the end-user has all the necessary elements, such as switches, buttons, indicators, connectors, and others, in one place. With two different connectors for each port, EasyPIC Fusion v7 allows you to connect accessory boards, sensors, and custom electronics more efficiently than ever. Each part of

the EasyPIC Fusion v7 development board contains the components necessary for the most efficient operation of the same board. An integrated mikroProg, a fast USB 2.0 programmer with mikroICD hardware In-Circuit Debugger, offers many valuable programming/debugging options and seamless integration with the Mikroe software environment. Besides it also includes a clean and regulated power supply block for the development board. It can use a wide range of external power sources, including an external 12V power supply, 7-12V AC or 9-15V DC via DC connector/screw terminals, and a power source via the USB Type-B (USB-B) connector. Communication options such

as USB-UART, USB-HOST, CAN, and Ethernet are also included, including the well-established mikroBUS™ standard, one display option for the TFT board line of products, and a standard TQFP socket for the seventh-generation MCU cards. This socket covers a wide range of 16-bit dsPIC/PIC24 and 32-bit PIC32 MCUs. EasyPIC Fusion v7 is an integral part of the Mikroe ecosystem for rapid development. Natively supported by Mikroe software tools, it covers many aspects of prototyping and development thanks to a considerable number of different Click boards™ (over a thousand boards), the number of which is growing every day.

EasyPIC Fusion v7 horizontal image

Microcontroller Overview

MCU Card / MCU

default

Type

7th Generation

Architecture

PIC32

MCU Memory (KB)

512

Silicon Vendor

Microchip

Pin count

100

RAM (Bytes)

131072

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
Magnetic Field Strength Detection (HIGH)
RC1
RST
SPI Chip Select
RC2
CS
SPI Clock
RD15
SCK
SPI Data OUT
RF2
MISO
SPI Data IN
RF8
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
PWM Signal
RD0
PWM
Magnetic Field Strength Detection (LOW)
RE8
INT
NC
NC
TX
NC
NC
RX
NC
NC
SCL
NC
NC
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

Angle 6 Click Schematic schematic

Step by step

Project assembly

EasyMx PRO v7a for STM32 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the EasyPIC Fusion v7 as your development board.

EasyMx PRO v7a for STM32 front image hardware assembly
Buck 22 Click front image hardware assembly
EasyMx PRO? v7 for STM32 MCUcard with STM32F407VGT6 front image hardware assembly
v7 TQFP 2SOC 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 Compiler Selection Step Image hardware assembly
NECTO Output Selection Step Image hardware assembly
Necto image step 6 hardware assembly
EasyPIC PRO v7a MCU Selection Necto Step hardware assembly
EasyPIC PRO v7a Display Selection Necto Step hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Necto PreFlash Image hardware assembly

Track your results in real time

Application Output

1. Application Output - In Debug mode, the 'Application Output' window enables real-time data monitoring, offering direct insight into execution results. Ensure proper data display by configuring the environment correctly using the provided tutorial.

2. UART Terminal - Use the UART Terminal to monitor data transmission via a USB to UART converter, allowing direct communication between the Click board™ and your development system. Configure the baud rate and other serial settings according to your project's requirements to ensure proper functionality. For step-by-step setup instructions, refer to the provided tutorial.

3. Plot Output - The Plot feature offers a powerful way to visualize real-time sensor data, enabling trend analysis, debugging, and comparison of multiple data points. To set it up correctly, follow the provided tutorial, which includes a step-by-step example of using the Plot feature to display Click board™ readings. To use the Plot feature in your code, use the function: plot(*insert_graph_name*, variable_name);. This is a general format, and it is up to the user to replace 'insert_graph_name' with the actual graph name and 'variable_name' with the parameter to be displayed.

Software Support

Library Description

This library contains API for Angle 6 Click driver.

Key functions:

  • angle6_write_register This function writes a data byte to the selected register by using SPI serial interface.

  • angle6_read_register This function reads a data byte from the selected register by using SPI serial interface.

  • angle6_read_angle This function reads raw angle data and converts it to degrees.

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 main.c
 * @brief Angle6 Click example
 *
 * # Description
 * This example demonstrates the use of Angle 6 click board by reading and displaying
 * the magnet's angular position in degrees.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and performs the click default configuration which 
 * sets the rotation direction to clockwise.
 *
 * ## Application Task
 * Reads the magnet's angular position in degrees and displays the results on the USB UART
 * approximately every 100ms.
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "angle6.h"

static angle6_t angle6;
static log_t logger;

void application_init ( void )
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    angle6_cfg_t angle6_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.
    angle6_cfg_setup( &angle6_cfg );
    ANGLE6_MAP_MIKROBUS( angle6_cfg, MIKROBUS_1 );
    if ( SPI_MASTER_ERROR == angle6_init( &angle6, &angle6_cfg ) )
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    if ( ANGLE6_ERROR == angle6_default_cfg ( &angle6 ) )
    {
        log_error( &logger, " Default configuration." );
        for ( ; ; );
    }
    
    log_info( &logger, " Application Task " );
}

void application_task ( void )
{
    float angle = 0;
    if ( ANGLE6_OK == angle6_read_angle ( &angle6, &angle ) )
    {
        log_printf ( &logger, " Angle: %.2f Deg \r\n\n", angle );
        Delay_ms ( 100 );
    }
}

void main ( void )
{
    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.