Intermediate
30 min

Discover the magnet's angular position with MAQ470GQE and STM32F767BI

It's all about the angle

Angle 6 Click with Clicker 4 for STM32

Published Mar 11, 2023

Click board™

Angle 6 Click

Dev. board

Clicker 4 for STM32

Compiler

NECTO Studio

MCU

STM32F767BI

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

Clicker 4 for STM32 is a compact development board designed as a complete solution that brings the flexibility of add-on Click boards™ to your favorite microcontroller, making it a perfect starter kit for implementing your ideas. It comes with an onboard 32-bit ARM Cortex-M4 microcontroller, the STM32F767BI from STMicroelectronics, four mikroBUS™ sockets for Click board™ connectivity, a USB connector, LED indicators, buttons, a debugger/programmer connector, two 23-pin headers for interfacing with external electronics, and more. Thanks to innovative manufacturing technology, it allows you to build gadgets with

unique functionalities and features quickly. Each part of the Clicker 4 for STM32 development kit contains the components necessary for the most efficient operation of the same board. In addition to the possibility of choosing the Clicker 4 for STM32 programming method, using an external CODEGRIP or mikroProg programmer connected to the onboard JTAG/SWD header, the Clicker 4 board also includes a clean and regulated power supply block. It provides several ways of board-powering; through the USB Type-C (USB-C) connector using a power supply delivered by the USB HOST (i.e., personal computer), USB wall

adapter, or a Li-Po/Li-Ion battery via an onboard battery connector. All communication methods that mikroBUS™ itself supports are on this board (plus USB-DEVICE), including the well-established mikroBUS™ socket, several user-configurable buttons, and LED indicators. Clicker 4 for STM32 is an integral part of the Mikroe ecosystem, allowing you to create a new application in minutes. Natively supported by Mikroe software tools, it covers many aspects of prototyping thanks to a considerable number of different Click boards™ (over a thousand boards), the number of which is growing every day.

Clicker 4 for STM32 double image

Microcontroller Overview

MCU Card / MCU

default

Architecture

ARM Cortex-M7

MCU Memory (KB)

2048

Silicon Vendor

STMicroelectronics

Pin count

208

RAM (Bytes)

524288

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
Magnetic Field Strength Detection (HIGH)
PI9
RST
SPI Chip Select
PC3
CS
SPI Clock
PI1
SCK
SPI Data OUT
PI2
MISO
SPI Data IN
PI3
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
PWM Signal
PF6
PWM
Magnetic Field Strength Detection (LOW)
PA4
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

Clicker 4 for STM32 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Clicker 4 for STM32 as your development board.

Clicker 4 for STM32 front image hardware assembly
Buck 22 Click front image hardware assembly
Prog-cut hardware assembly
Clicker 4 STM32 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
Clicker 4 stm32 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

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.