Beginner
10 min

Experience the future of temperature management with MAX31855 and PIC18F4553

Smart thermometry for a safer world

Thermostat 3 Click with EasyPIC v7

Published Nov 08, 2023

Click board™

Thermostat 3 Click

Dev Board

EasyPIC v7

Compiler

NECTO Studio

MCU

PIC18F4553

Elevate your temperature measurement capabilities with our solution, designed to adapt to the unique demands of your industry.

A

A

Hardware Overview

How does it work?

Thermostat 3 Click is based on the MAX31855, a thermocouple-to-digital converter with a built-in 14-bit analog-to-digital converter (ADC), from Analog Devices. The device also contains cold-junction compensation sensing and correction, a digital controller, a SPI compatible interface, and associated control logic. The Thermostat 3 click is designed to be used with externally connected K-type thermocouple sensor. The communication with the host MCU is performed over the SPI interface, using the dedicated pins of the mikroBUS™. Depending on the temperature information obtained over the SPI interface, the host MCU can take the necessary action: it can either open or close contacts of the relay. The Click board™ uses the G6D series PCB power relay, from Omron. This quality relay can withstand an amazingly large number of mechanical cycles, with no load connected. However, when there is a significant load connected at its output, micro-electric arcs cause the contacts to wear over time. With the maximum load current of 5A, it can sustain up to 70,000 cycles. Its contacts are made of silver alloy, yielding

exceptional ON resistance of only 100mΩ (max). The relay is activated by the host MCU. The voltage for the coil activation is 5V, while the current through the coil is 40mA. The MCU is not able to drive the coil directly, therefore an NPN transistor had to be added. Its base is controlled by the host MCU, allowing the coil to drain enough current from the 5V mikroBUS™ power rail. The base of the transistor is routed to the CS pin of the Click board™. The transistor packs two biasing resistors in the same casing, so it can be directly used on the MCU pin, without external biasing resistors. A red color LED, labeled as ACTIVE is used to indicate that the transistor is in an open state and that the current is running through the relay coil. When the current through a coil (or any other inductor) is suddenly changed, the backEMF will be generated, opposing the changes of the current. This can sometimes lead to damage to the control circuit: in this case, the transistor will become inversely polarized. To prevent this from happening, a flyback diode is added across the coil. During the normal operation, this diode does not conduct any current. However, when the coil is

switched OFF, the inverse polarization will cause the current to pass through this diode with minimum resistance. This prevents inverse (flyback) voltage from building up, so the transistor remains safe. Contacts at the output may be connected to a higher voltage and larger current may run through. To prevent high voltage transients in this case, a flyback diode is not a viable option. Therefore, Thermostat 3 click uses a varistor (VDR). This component rapidly drops its resistance as the voltage rises above its rated clamping voltage. The excessive voltage transient will pass through the VDR since it will become a current path with the least resistance. During the normal operation, while the voltage stays below the rated clamping voltage, VDR has a very high resistance, so the current runs through the electrical circuit, instead. The operating voltage of the Click board™ can be selected by the VCC SEL jumper. This jumper allows selecting either 3.3V or 5V from the mikroBUS™. The selected voltage will be applied to the VCC pin of the connected MAX31855 sensor.

Thermostat 3 Click hardware overview image

Features overview

Development board

EasyPIC v7 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 has 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 in one place, such as switches, buttons, indicators, connectors, and others. With four different connectors for each port, EasyPIC v7 allows you to connect accessory boards, sensors, and custom electronics more efficiently than ever. Each part of

the EasyPIC 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 various 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-B (USB-B) connector. Communication options such as

USB-UART and RS-232 are also included, alongside the well-established mikroBUS™ standard, three display options (7-segment, graphical, and character-based LCD), and several different DIP sockets. These sockets cover a wide range of 8-bit PIC MCUs, from PIC10F, PIC12F, PIC16F, PIC16Enh, PIC18F, PIC18FJ, and PIC18FK families. EasyPIC 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 v7 horizontal image

Microcontroller Overview

MCU Card / MCU

PIC18F4553

Architecture

PIC

MCU Memory (KB)

32

Silicon Vendor

Microchip

Pin count

40

RAM (Bytes)

2048

You complete me!

Accessories

The Type-K thermocouple, equipped with glass braid insulation, is a versatile tool designed for precision temperature measurements, particularly in high-temperature environments. With a calibrated Type-K configuration and a 24 AWG gage wire spanning 2 meters, this probe is engineered to provide reliable readings. Its operational temperature range extends to 480°C (900°F), making it suitable for demanding applications. The glass braid insulation ensures durability and stability during measurements, and the connector body can withstand temperatures up to 220°C (425°F). The Type-K thermocouple probe features a PCC-SMP connector at its end, which offers compatibility with THERMO Click and Thermo K Click boards. This connectivity makes it a valuable tool for various industrial and scientific settings, where precision and reliability in temperature monitoring are essential.

Thermostat 3 Click accessories image

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
NC
NC
RST
SPI Chip Select
RE0
CS
SPI Clock
RC3
SCK
SPI Data OUT
RC4
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Relay Control
RC0
PWM
NC
NC
INT
NC
NC
TX
NC
NC
RX
NC
NC
SCL
NC
NC
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Schematic

Thermostat 3 Click Schematic schematic

Step by step

Project assembly

EasyPIC v7 front image hardware assembly

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

EasyPIC v7 front image hardware assembly
GNSS2 Click front image hardware assembly
MCU DIP 40 hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
EasyPIC v7 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 Compiler Selection Step Image hardware assembly
NECTO Output Selection Step Image hardware assembly
Necto image step 6 hardware assembly
Necto DIP image step 7 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

After pressing the "FLASH" button on the left-side panel, it is necessary to open the UART terminal to display the achieved results. By clicking on the Tools icon in the right-hand panel, multiple different functions are displayed, among which is the UART Terminal. Click on the offered "UART Terminal" icon.

UART Application Output Step 1

Once the UART terminal is opened, the window takes on a new form. At the top of the tab are two buttons, one for adjusting the parameters of the UART terminal and the other for connecting the UART terminal. The tab's lower part is reserved for displaying the achieved results. Before connecting, the terminal has a Disconnected status, indicating that the terminal is not yet active. Before connecting, it is necessary to check the set parameters of the UART terminal. Click on the "OPTIONS" button.

UART Application Output Step 2

In the newly opened UART Terminal Options field, we check if the terminal settings are correct, such as the set port and the Baud rate of UART communication. If the data is not displayed properly, it is possible that the Baud rate value is not set correctly and needs to be adjusted to 115200. If all the parameters are set correctly, click on "CONFIGURE".

UART Application Output Step 3

The next step is to click on the "CONNECT" button, after which the terminal status changes from Disconnected to Connected in green, and the data is displayed in the Received data field.

UART Application Output Step 4

Software Support

Library Description

This library contains API for Thermostat 3 Click driver.

Key functions:

  • thermostat3_relay_control - This function enables control of the relay.

  • thermostat3_get_fault_data - This function returns Fault data Value.

  • thermostat3_get_thermocouple_temperature - This function returns 14-Bit Thermocouple Temperature 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 Thermostat3 Click example
 * 
 * # Description
 * This application enables usage of the general puprose Thermostat click to be used with temperature sensors.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initialization driver init
 * 
 * ## Application Task  
 * Waits for valid user input and executes functions based on set of valid commands
 * 
 * *note:* 
 * - Additional Functions :
 *      -void _displayFault( uint8_t f_error )  - Display fault
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "thermostat3.h"

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

static thermostat3_t thermostat3;
static temp_vals_t temp_val;
static log_t logger;

// ------------------------------------------------------- ADDITIONAL FUNCTIONS

static void display_fault ( uint8_t f_error )
{
    switch ( f_error )
    {
        case 3:
        {
            log_printf( &logger, "# Active - Fault flag " );
            break;
        }
        case 2:
        {
            log_printf( &logger, "# SCV - Fault flag " );
            break;
        }
        case 1:
        {
            log_printf( &logger,"# SCG - Fault flag " );
            break;
        }
        case 0:
        {
            log_printf( &logger,"# OC - Fault flag " );
            break;
        }
    }
}

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

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

    Delay_ms( 100 );

    //  Click initialization.

    thermostat3_cfg_setup( &cfg );
    THERMOSTAT3_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    thermostat3_init( &thermostat3, &cfg );

    // Power on delay
    Delay_ms( 200 );
    log_printf( &logger, "---- Start Thermostat 3 ----\r\n" );
}

void application_task ( void )
{
    //  Task implementation.

    float internal_temp;
    float thermocouple_temp;

    thermostat3_process( &thermostat3, &temp_val );

    internal_temp = thermostat3_get_internal_temperature( &temp_val, THERMOSTAT3_TEMP_IN_CELSIUS );
    log_printf( &logger, "# Internal Temperature: %.2f", internal_temp );
    Delay_ms( 200 );
   
    thermocouple_temp = thermostat3_get_thermocouple_temperature( &temp_val, THERMOSTAT3_TEMP_IN_CELSIUS );
    log_printf( &logger, "# Thermocouple Temperature: %.2f", thermocouple_temp );
    Delay_ms( 200 );
    
    if( thermostat3.relay_flag == 1)
    {
        thermostat3.relay_flag = 0;
        thermostat3_relay_control( &thermostat3, THERMOSTAT3_RELAY_OFF );
        log_printf( &logger, "# Relay OFF\r\n" );
    }
    else
    {
        thermostat3.relay_flag = 1;
        thermostat3_relay_control( &thermostat3, THERMOSTAT3_RELAY_ON );
        log_printf( &logger, "# Relay ON\r\n" );
    }
    Delay_ms( 200 );

    if( thermostat3.fault_flag == 1 )
    {
        thermostat3.fault_flag = 0;
        log_printf( &logger, "# Fault status -- OFF\r\n" );
    }
    else
    {
        thermostat3.fault_flag = 1;
        log_printf( &logger, "# Fault status -- ON\r\n" );
    }
    Delay_ms( 200 );

    if( thermostat3.fault_flag == 1 )
        {
            thermostat3.f_error++;
            if( thermostat3.f_error > 3 )
            {
                thermostat3.f_error = 0;
            }
            display_fault( thermostat3.f_error );
            
            thermostat3.fault_status = thermostat3_get_fault_data( &temp_val, 0x01 << thermostat3.f_error );
            
            if ( thermostat3.fault_status == 1 )
            {
                log_printf( &logger, " -- ERROR\r\n" );
            }
            else
            {
                log_printf( &logger, " -- OK\r\n" );
            }
        }
}
void main ( void )
{
    application_init( );

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


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

Additional Support

Resources