Intermediate
30 min

Attain accurate and real-time absolute angular positioning with MA302 and STM32F412ZG

From 0 to 60.000 RPM: Accurate angle measurement simplified

Angle 5 Click with Nucleo-144 with STM32F412ZG MCU

Published Feb 26, 2024

Click board™

Angle 5 Click

Development board

Nucleo-144 with STM32F412ZG MCU

Compiler

NECTO Studio

MCU

STM32F412ZG

Detect the absolute rotor position of brushless motors with ease, allowing for seamless control and optimization of motor performance

A

A

Hardware Overview

How does it work?

Angle 5 Click is based on the MA302, a 12-bit digital contactless angle sensor with ABZ and UVW incremental outputs from Monolithic Power Systems. This Click board™ can detect the absolute rotor position of a Brushless motor in real-time, even without a target magnet, by measuring the fringe field of the rotor. The sensor must be positioned at the correct place (in this case, below the rotor) to get the maximum value of the rotor magnetic field without being disturbed by other fields. The rotor magnetic field is then measured, and an adequate position was determined from that information. It uses the SPI serial interface for digital angle readout and configuration alongside a programmable magnetic field strength detection function for diagnostic checks. The magnetic field is detected with integrated Hall devices located in the center of the package. The angle is measured using the Spinaxis™ method, based on phase detection,

and generates a sinusoidal signal with a phase that represents the angle of the magnetic field. The angle is then obtained by a time-to-digital converter, which measures the time between the zero-crossing of the sinusoidal signal and the edge of a constant waveform. The time-to-digital represents an output from the front end to the digital conditioning block. 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 5 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 for indication when the magnetic field at the sensor position is out of range, defined by the lower and upper magnetic field thresholds, routed on the PWM and INT pin of the mikroBUS™ socket labeled as MGH

and MGL. This Click board™ possesses an incremental encoder and block commutation function that uses three output pins each: ABZ and UVW. The ABZ output emulates a 10-bit incremental encoder (such as an optical encoder) providing logic pulses in quadrature, while the UVW output emulates the three Hall switches usually used for the block commutation of a three-phase electric motor. The ABZ and UVW pins of the MA302 are routed on two standard 2.54 mm (0.1 inches) pitch 1x3 header mounted on the Angle 5 Click so an external application can easily access it. 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.

Angle 5 Click top side image
Angle 5 Click bottom side image

Features overview

Development board

Nucleo-144 with STM32F412ZG MCU board offers an accessible and adaptable avenue for users to explore new ideas and construct prototypes. It allows users to tailor their experience by selecting from a range of performance and power consumption features offered by the STM32 microcontroller. With compatible boards, the

internal or external SMPS dramatically decreases power usage in Run mode. Including the ST Zio connector, expanding ARDUINO Uno V3 connectivity, and ST morpho headers facilitate easy expansion of the Nucleo open development platform. The integrated ST-LINK debugger/programmer enhances convenience by

eliminating the need for a separate probe. Moreover, the board is accompanied by comprehensive free software libraries and examples within the STM32Cube MCU Package, further enhancing its utility and value.

Nucleo 144 with STM32F412ZG MCU double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

ARM Cortex-M4

MCU Memory (KB)

1024

Silicon Vendor

STMicroelectronics

Pin count

144

RAM (Bytes)

262144

You complete me!

Accessories

Click Shield for Nucleo-144 comes equipped with four mikroBUS™ sockets, with one in the form of a Shuttle connector, allowing all the Click board™ devices to be interfaced with the STM32 Nucleo-144 board with no effort. This way, MIKROE allows its users to add any functionality from our ever-growing range of Click boards™, such as WiFi, GSM, GPS, Bluetooth, ZigBee, environmental sensors, LEDs, speech recognition, motor control, movement sensors, and many more. Featuring an ARM Cortex-M microcontroller, 144 pins, and Arduino™ compatibility, the STM32 Nucleo-144 board offers limitless possibilities for prototyping and creating diverse applications. These boards are controlled and powered conveniently through a USB connection to program and efficiently debug the Nucleo-144 board out of the box, with an additional USB cable connected to the USB mini port on the board. Simplify your project development with the integrated ST-Link debugger and unleash creativity using the extensive I/O options and expansion capabilities. This Click Shield also has several switches that perform functions such as selecting the logic levels of analog signals on mikroBUS™ sockets and selecting logic voltage levels of the mikroBUS™ sockets themselves. Besides, the user is offered the possibility of using any Click board™ with the help of existing bidirectional level-shifting voltage translators, regardless of whether the Click board™ operates at a 3.3V or 5V logic voltage level. Once you connect the STM32 Nucleo-144 board with our Click Shield for Nucleo-144, you can access hundreds of Click boards™, working with 3.3V or 5V logic voltage levels.

Click Shield for Nucleo-144 accessories 1 image

2207V-2500kV BLDC Motor is an outrunner brushless DC motor with a kV rating of 2500 and an M5 shaft diameter. It is an excellent solution for fulfilling many functions initially performed by brushed DC motors or in RC drones, racing cars, and much more.

Angle 5 Click accessories image

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
NC
NC
RST
SPI Chip Select
PA4
CS
SPI Clock
PB3
SCK
SPI Data OUT
PB4
MISO
SPI Data IN
PB5
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Magnetic Field Strength Detection (HIGH)
PC6
PWM
Magnetic Field Strength Detection (LOW)
PF13
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

Angle 5 Click Schematic schematic

Step by step

Project assembly

Click Shield for Nucleo-144 accessories 1 image hardware assembly

Start by selecting your development board and Click board™. Begin with the Nucleo-144 with STM32F412ZG MCU as your development board.

Click Shield for Nucleo-144 accessories 1 image hardware assembly
Nucleo 144 with STM32F446ZE MCU front image hardware assembly
Charger 27 Click front image hardware assembly
Prog-cut hardware assembly
Charger 27 Click complete accessories setup image hardware assembly
Nucleo 144 with STM32F413ZH MCU 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
STM32F413ZH Nucleo 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

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 Angle 5 Click driver.

Key functions:

  • angle5_read_raw_angle - Use this function to read raw angle data

  • angle5_read_angle_deg - Use this function to read angle data

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 
 * \brief Angle5 Click example
 * 
 * # Description
 * Angle 5 click is a magnetic rotational sensor. 
 * It communicates with the target microcontroller over SPI interface.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes the driver.
 * 
 * ## Application Task  
 * Reads the angle position of the magnet and displays the results on the USB UART.
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "angle5.h"

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

static angle5_t angle5;
static log_t logger;

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

void application_init ( void )
{
    log_cfg_t log_cfg;
    angle5_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.

    angle5_cfg_setup( &cfg );
    ANGLE5_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    angle5_init( &angle5, &cfg );
}

void application_task ( void )
{
    float new_angle = 0;
    
    new_angle = angle5_read_angle_deg( &angle5 );
    log_printf( &logger, "Angle: %.2f\r\n", new_angle );

    Delay_ms( 100 );
}

void main ( void )
{
    application_init( );

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


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

Additional Support

Resources