Beginner
10 min

Experience excellence in resistance measurement with MAX4208 and PIC18LF45K42

Mastering resistance with Wheatstone's magic

Wheatstone Click with Curiosity HPC

Published Nov 01, 2023

Click board™

Wheatstone Click

Dev Board

Curiosity HPC

Compiler

NECTO Studio

MCU

PIC18LF45K42

Discover the ultimate tool for precision resistance measurement – our Wheatstone bridge circuit solution is here to empower your journey towards accurate and reliable data.

A

A

Hardware Overview

How does it work?

Wheatstone Click is based on the MAX4208, an ultra-low offset/drift, precision instrumentation amplifier, from Analog Devices. A Wheatstone bridge is an electrical circuit used to measure an unknown electrical resistance by balancing two branches of a bridge circuit, one branch of which includes the unknown component. The primary benefit of the circuit is its ability to provide extremely accurate measurements, in contrast with a simple voltage divider. The R2, R3, and R4 are resistors of known resistance (1k ohm), while the resistance R1 is brought to the terminal block and therefore it is changeable. With no resistance connected to the terminal block, the bridge on this Click board™ is in balance. At this point, the voltage between the two midpoints (IN- and IN+) will be zero. Therefore the ratio

of the two resistances in the known branch (R1 and R3) is equal to the ratio of the two resistances in the unknown leg (R2 and R4). If the external resistance is connected to the terminal block, bridge is unbalanced, and the voltage on the midpoints is proportional to the external resistor value. Wheatstone click is based around the MAX4208 IC, which is connected to an onboard Wheatstone bridge circuit, in order to precisely measure the resistance of an external element. The mentioned IC uses a spreadspectrum, autozeroing technique that constantly measures and corrects the input offset, eliminating drift over time and temperature and the effect of 1/f noise. This technique achieves less than 20μV offset voltage, allows ground-sensing capability, provides ultra-low CMOS input bias current and increased

common-mode rejection performance. It also provides high-impedance inputs, optimized for small-signal differential voltages (±100mV), which makes it ideal for an application such as wheatstone bridge disbalance measurement. This Click board™ also has TPL0501 onboard - 256-Taps, Single-Channel, Digital Potentiometer With SPI Interface, from texas instruments. It is connected to the MAX4208 in a way that it serves an gain adjust instead of with two external resistors The power supply voltage selection for the logic section is done by moving the SMD jumper labeled as VCC SEL to a desired position: left position to select 3.3V, right position to select 5V. This will allow both 3.3V and 5V MCUs to be interfaced with the Click board™ directly.

Wheatstone Click hardware overview 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

PIC18LF45K42

Architecture

PIC

MCU Memory (KB)

32

Silicon Vendor

Microchip

Pin count

40

RAM (Bytes)

2048

Used MCU Pins

mikroBUS™ mapper

Analog Output
RA1
AN
NC
NC
RST
SPI Chip Select
RA3
CS
SPI Clock
RB1
SCK
NC
NC
MISO
SPI Data IN
RB3
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
NC
NC
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

Wheatstone 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
GNSS2 Click front image hardware assembly
MCU DIP 40 hardware assembly
Prog-cut hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
Curiosity HPC 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
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 Wheatstone Click driver.

Key functions:

  • wheatstone_set_potentiometer - Set potentiometer ( 0 - 100k )

  • wheatstone_read_an_pin_voltage - This function reads results of AD conversion of the AN pin and converts them to proportional voltage level.

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 Wheatstone Click example
 * 
 * # Description
 * This example demonstrates the use of Wheatstone click board by measuring the input
 * resistance.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes the driver and logger and sets the default potentiometer (gain) level.
 * 
 * ## Application Task  
 * Reads the AN pin voltage and calculates the input resistance from it.
 * All data are being displayed on the USB UART where you can track their changes.
 * 
 * @note
 * The following formulas you may find useful:
 * AN_PIN(V) = ( ( 1kOhm + R_INPUT(kOhm) ) / ( 1kOhm + 2*R_INPUT(kOhm) ) - 1/2 ) * VCC(V) * GAIN
 * VOUT(V) = AN_PIN(V) / GAIN
 * R_INPUT(kOhm) = ( VCC(V) * GAIN - 2*AN_PIN(V) ) / ( 4*AN_PIN(V) )
 * R_INPUT(kOhm) = ( VCC(V) - 2*VOUT(V) ) / ( 4*VOUT(V) )
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "wheatstone.h"

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

static wheatstone_t wheatstone;
static log_t logger;

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

void application_init ( void )
{
    log_cfg_t log_cfg;
    wheatstone_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.
    wheatstone_cfg_setup( &cfg );
    WHEATSTONE_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    wheatstone_init( &wheatstone, &cfg );

    wheatstone_set_potentiometer ( &wheatstone, WHEATSTONE_POT_MAX );

    log_info( &logger, " Application Task " );
}

void application_task ( void )
{
    float an_pin_v = 0;
    float vout = 0;
    float r_kohm = 0;
    if ( WHEATSTONE_OK == wheatstone_read_an_pin_voltage ( &wheatstone, &an_pin_v ) ) 
    {
        vout = an_pin_v / wheatstone.gain;
        if ( 0 != vout )
        {
            r_kohm = ( WHEATSTONE_VCC_5V - 2 * vout ) / ( 4 * vout );
        }
        log_printf( &logger, " VCC     : %.3f V\r\n", WHEATSTONE_VCC_5V );
        log_printf( &logger, " GAIN    : %.3f\r\n", wheatstone.gain );
        log_printf( &logger, " AN_PIN  : %.3f V\r\n", an_pin_v );
        log_printf( &logger, " VOUT    : %.3f V\r\n", vout );
        log_printf( &logger, " R_INPUT : %.3f kOhm\r\n\n", r_kohm );
        Delay_ms( 1000 );
    }
}

void main ( void )
{
    application_init( );

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

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

Additional Support

Resources