Find the magnet's absolute angular position
A
A
Hardware Overview
How does it work?
Angle 7 Click is based on the AS5600, an easy-to-program magnetic rotary position sensor with a high-resolution 12-bit analog or PWM output from ams AG. The AS5600 is a Hall-based rotary magnetic position sensor using planar sensors that convert the magnetic field component perpendicular to the surface of the chip into a voltage. It measures the absolute angle of a diametric-magnetized on-axis magnet while at the same time rejecting stray magnetic fields. By default, the output represents a range from 18 to 360 degrees. It is also possible to define a smaller range to the output by programming a zero angle (start position) and a maximum angle (stop position). First, the signals coming from internal Hall sensors are amplified and filtered before their conversion by the ADC and then processed by the hardwired CORDIC block to compute the angle and magnitude of the magnetic field vector. The intensity of the magnetic field is used by the
automatic gain control (AGC) to adjust the amplification level to compensate for temperature and magnetic field variations. After that, the output stage uses the angle value provided by the CORDIC algorithm. The user can choose between an analog output representing the angle as a ratiometric linear absolute value and a digital PWM-encoded output representing the angle as the pulse width. The selection can be made by positioning the SMD jumper labeled OUT SEL in an appropriate position marked as AN or INT. Angle 7 Click communicates with MCU using the standard I2C 2-Wire interface with a maximum clock frequency of 1MHz, fully adjustable through software registers. Also, the DIR SEL jumper allows users to select the polarity of the output relative to rotation direction by positioning the SMD jumper in an appropriate position marked as CW or CCW allowing clockwise or counterclockwise rotation. A unique addition to this board
is a position for a Rotary Magnet Holder designed to be used alongside a magnetic rotary position sensor allowing fast prototyping and quick measurements during development. This Click board™ can operate with either 3.3V or 5V logic voltage levels selected via the VCC SEL jumper. This way, both 3.3V and 5V capable MCUs can use the communication lines properly. Both mikroBUS™ power rails have protection in the form of diode MAX40200, controllable through an EN pin on the mikroBUS™ socket to prevent any unwanted back voltage. However, the Click board™ comes equipped with a library containing easy-to-use functions and an example code that can be used, as a reference, for further development. In the case of using a logic level of 5V, it is necessary first to remove the resistor R6 and then switch the VCC jumper to the 5V position.
Features overview
Development board
EasyPIC PRO v7a is the seventh generation of PIC development boards specially designed to develop embedded applications rapidly. It supports a wide range of 8-bit PIC microcontrollers from Microchip and a broad set of unique functions, such as the first-ever embedded debugger/programmer over USB-C. 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 PRO v7a allows you to connect accessory boards, sensors, and custom electronics more efficiently than ever. Each part of the EasyPIC PRO
v7a development board contains the components necessary for the most efficient operation of the same board. In addition to the advanced integrated CODEGRIP programmer/debugger module, which offers many valuable programming/debugging options and seamless integration with the Mikroe software environment, the board 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-23V AC or 9-32V DC via DC connector/screw terminals, and a power source via the USB Type-C (USB-C) connector. Communication options such as USB-UART,
RS-232, and Ethernet are also included, including the well-established mikroBUS™ standard, two display options (graphical and character-based LCD), and a standard TQFP socket for the seventh-generation MCU cards. This socket covers a wide range of 8-bit PIC MCUs, from PIC18LF, PIC16LF, PIC16F, and PIC18F families. EasyPIC PRO v7a 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.
Microcontroller Overview
MCU Card / MCU
Type
7th Generation
Architecture
PIC
MCU Memory (KB)
128
Silicon Vendor
Microchip
Pin count
80
RAM (Bytes)
3904
You complete me!
Accessories
Rotary Magnetic Holder is an addition designed for use alongside a magnetic rotary position sensor. It comes with a plastic stand measuring 22x16x10 millimeters (L x W x H), as well as an adjustable shaft with a 6mm diameter magnet. The plastic frame has four round feet that fit into holes in the board near the magnetic rotary position sensor, with a 6mm diameter hole on top to match the adjustable shaft that carries the magnet. This shaft has a height adjustment screw on it, allowing the user to adjust it between 18 and 22 millimeters. This way, fast prototyping and quick measurements of the magnet characteristics are allowed during development.
Used MCU Pins
mikroBUS™ mapper
Take a closer look
Schematic
Step by step
Project assembly
Track your results in real time
Application Output via UART Mode
1. Once the code example is loaded, pressing the "FLASH" button initiates the build process, and programs it on the created setup.
2. After the programming is completed, click on the Tools icon in the upper-right panel, and select the UART Terminal.
3. After opening the UART Terminal tab, first check the baud rate setting in the Options menu (default is 115200). If this parameter is correct, activate the terminal by clicking the "CONNECT" button.
4. Now terminal status changes from Disconnected to Connected in green, and the data is displayed in the Received data field.
Software Support
Library Description
This library contains API for Angle 7 Click driver.
Key functions:
angle7_get_status
This function reads the status data.angle7_get_angle
This function reads the calculated angle in degrees.angle7_get_magnitude
This function reads the magnitude 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 main.c
* @brief Angle7 Click example
*
* # Description
* This example demonstrates the use of Angle 7 click board by reading and displaying
* the magnet's angular position in degrees and analog voltage output as well as
* the magnet's status and magnitude.
*
* The demo application is composed of two sections :
*
* ## Application Init
* Initializes the driver and performs the click default configuration.
*
* ## Application Task
* Reads the magnet's angular position in degrees and analog voltage output
* as well as the magnet's status and magnitude and displays the results on the USB UART
* approximately every 100ms.
*
* @author Stefan Filipovic
*
*/
#include "board.h"
#include "log.h"
#include "angle7.h"
static angle7_t angle7;
static log_t logger;
void application_init ( void )
{
log_cfg_t log_cfg; /**< Logger config object. */
angle7_cfg_t angle7_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.
angle7_cfg_setup( &angle7_cfg );
ANGLE7_MAP_MIKROBUS( angle7_cfg, MIKROBUS_1 );
if ( I2C_MASTER_ERROR == angle7_init( &angle7, &angle7_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
if ( ANGLE7_ERROR == angle7_default_cfg ( &angle7 ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
}
void application_task ( void )
{
float voltage, raw_angle, angle;
uint16_t magnitude;
uint8_t status;
if ( ADC_ERROR != angle7_read_an_pin_voltage ( &angle7, &voltage ) )
{
log_printf( &logger, " AN voltage: %.3f V\r\n", voltage );
}
if ( ANGLE7_OK == angle7_get_angle ( &angle7, &angle ) )
{
log_printf ( &logger, " Angle: %.2f Degrees\r\n", angle );
}
if ( ANGLE7_OK == angle7_get_magnitude ( &angle7, &magnitude ) )
{
log_printf ( &logger, " Magnitude: %u\r\n", magnitude );
}
if ( ANGLE7_OK == angle7_get_status ( &angle7, &status ) )
{
log_printf ( &logger, " Status:" );
if ( status & ANGLE7_STATUS_MAGNET_DETECTED )
{
log_printf ( &logger, " Magnet Detected \r\n Magnet Strength:" );
if ( status & ANGLE7_STATUS_MAGNET_TOO_STRONG )
{
log_printf ( &logger, " Too Strong \r\n\n" );
}
else if ( status & ANGLE7_STATUS_MAGNET_TOO_WEAK )
{
log_printf ( &logger, " Too Weak \r\n\n" );
}
else
{
log_printf ( &logger, " Good \r\n\n" );
}
}
else
{
log_printf ( &logger, " Magnet Not Detected \r\n\n" );
}
}
Delay_ms ( 100 );
}
void main ( void )
{
application_init( );
for ( ; ; )
{
application_task( );
}
}
// ------------------------------------------------------------------------ END