Intermediate
30 min

Improve system reliability with TLP241A and PIC32MZ1024EFH064 through robust electrical isolation

Elevate signal integrity: OptoLink isolation at Its best!

Opto 3 Click with PIC32MZ clicker

Published Sep 21, 2023

Click board™

Opto 3 Click

Dev Board

PIC32MZ clicker

Compiler

NECTO Studio

MCU

PIC32MZ1024EFH064

Provide complete electrical isolation, ensuring your sensitive signals remain unaffected by external interference.

A

A

Hardware Overview

How does it work?

Opto 3 Click is based on two pairs of normally opened, high-quality solid-state relays labeled as TLP241A, from Toshiba Semiconductor. The TLP241A is an optically isolated solid-state relay (SSR), featuring an integrated IR LED and two output MOSFETs. The output stage does not have any electrical contact with the input stage; it is activated by infrared light, produced by an integrated IR LED. This allows reinforced galvanic isolation between the input and the output stage. The output stage can sustain up to 40V while OFF. When activated, due to a very low RDSON of the integrated MOSFETs, it can conduct up to 2A of current. The TLP241A are able to effectively replace traditionally used mechanical relays, bringing up the full set of inherited benefits: virtually unlimited number of cycles since there are no moving parts that would wear off, no bouncing effect on the output contacts, high resistance to mechanical shock and environmental influence, low current required for the activation, constant resistance since no carbon and rust can build up on contacts, there is no sparking or electric arc forming while operated, compact size, higher isolation voltage, and so on. However, unlike optocouplers (similar devices which are designed for much lower currents and voltages), SSRs are not designed

to be used as signal line isolators. SSR typically has a slow signal propagation time. Still, it can be used for various communication protocols which use lower data rates, including UART/RS232, 1-Wire, and similar. One pair of SSRs is driven by the host MCU. This pair can be used to activate an external circuit, utilizing the full potential of the TLP241A SSR. One or two SSRs can be used as relays, allowing the host MCU to control heavier loads such as DC motors, some other electrical circuit which operates on higher potential, LED strips, LED arrays, and more. A HIGH logic level on mikroBUS™ pins AN or RST labeled as OU1 and OU2 respectively, will activate the integrated IR LED. It will turn ON the MOSFETs in the SSR, allowing the current to flow through an external circuit. Two red LEDs, labeled as OUT1 and OUT 2, are connected to each of the MCU output pins. These LEDs provide visual feedback about the SSR state: if ON, the respective SSR is in a conductive state. SSR outputs are routed to two screw terminals labeled as OUT1 and OUT2, allowing an external circuit to be securely connected. The other pair of SSRs is used to provide optical isolation for external signals, offering protection for sensitive MCU pins that way. While the SSR is not activated, PWM and INT pins of the mikroBUS™

labeled as IN1 and IN2 respectively, are pulled to a HIGH logic level by a resistor. A signal on the input terminal will activate the respective SSR, pulling the IN1 (IN2) pin to a LOW logic level. Since galvanically isolated, the signal at the input terminal can be at a different potential than the host MCU, preventing any stray currents to flow between two GNDs. This will also protect the host MCU from the electrostatic discharge (ESD) that might occur. It is important to connect the input signal correctly. Therefore, two input terminals have their ports clearly labeled with + and - signs. A Schottky diode in series provides some protection to the input IR LED, however, care should be taken not to exceed specifications from the TLP241A datasheet. Pull-up resistors on the input side SSRs are connected to the power supply from mikroBUS™, providing a HIGH logic level while the SSR is not active. The voltage of the power supply directly determines the voltage level that will be applied to IN1 and IN2 pins in this case. Therefore, an SMD jumper labeled as VCC SEL is provided on the Click board™, allowing the user to select the logic voltage level between 3.3V and 5V, depending on the used MCU and its capabilities.

Opto 3 Click top side image
Opto 3 Click bottom side image

Features overview

Development board

PIC32MZ Clicker is a compact starter development board 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 PIC32MZ microcontroller with FPU from Microchip, a USB connector, LED indicators, buttons, a mikroProg connector, and a header for interfacing with external electronics. Thanks to its compact design with clear and easy-recognizable silkscreen markings, it provides a fluid and immersive working experience, allowing access anywhere and under

any circumstances. Each part of the PIC32MZ Clicker development kit contains the components necessary for the most efficient operation of the same board. In addition to the possibility of choosing the PIC32MZ Clicker programming method, using USB HID mikroBootloader, or through an external mikroProg connector for PIC, dsPIC, or PIC32 programmer, the Clicker board also includes a clean and regulated power supply module for the development kit. The USB Micro-B connection can provide up to 500mA of current, which is more than enough to operate all onboard

and additional modules. All communication methods that mikroBUS™ itself supports are on this board, including the well-established mikroBUS™ socket, reset button, and several buttons and LED indicators. PIC32MZ Clicker 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.

PIC32MZ clicker double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

PIC32

MCU Memory (KB)

1024

Silicon Vendor

Microchip

Pin count

64

RAM (Bytes)

524288

Used MCU Pins

mikroBUS™ mapper

Relay 1 Output
RE4
AN
Relay 2 Output
RE5
RST
NC
NC
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Relay 1 Input
RB3
PWM
Relay 2 Input
RB5
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

Opto 3 Click Schematic schematic

Step by step

Project assembly

PIC32MZ clicker front image hardware assembly

Start by selecting your development board and Click board™. Begin with the PIC32MZ clicker as your development board.

PIC32MZ clicker front image hardware assembly
GNSS2 Click front image hardware assembly
Prog-cut hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
Micro B Connector Clicker Access - 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
Flip&Click PIC32MZ 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 Opto 3 Click driver.

Key functions:

  • opto3_get_in1 - This function gets input 1 pin state

  • opto3_get_in2 - This function gets input 2 pin state

  • opto3_set_out1 - This function sets output 1 pin state.

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 Opto 3 Click example
 * 
 * # Description
 * Opto 3 click to be used in applications that require reinforced galvanic 
 * isolation for both their input and output stages.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes GPIO interface.
 * 
 * ## Application Task 
 * Reads the input pins state and sets their respective output pins to the same logic state.
 * The output pins state will be displayed on the USB UART where you can track their changes.
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "opto3.h"

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

static opto3_t opto3;
static log_t logger;

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

void application_init ( void )
{
    log_cfg_t log_cfg;
    opto3_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.
    opto3_cfg_setup( &cfg );
    OPTO3_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    opto3_init( &opto3, &cfg );

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

void application_task ( void )
{
    static uint8_t out1_state = 0;
    static uint8_t out2_state = 0;
    uint8_t in1_state = 0;
    uint8_t in2_state = 0;

    in1_state = opto3_get_in1( &opto3 );
    in2_state = opto3_get_in2( &opto3 );
    
    if ( in1_state != out1_state )
    {
        out1_state = in1_state;
        opto3_set_out1( &opto3, out1_state );
        log_printf( &logger, " OUT1 state: %u\r\n", ( uint16_t ) out1_state );
    }
    
    if ( in2_state != out2_state )
    {
        out2_state = in2_state;
        opto3_set_out2( &opto3, out2_state );
        log_printf( &logger, " OUT2 state: %u\r\n", ( uint16_t ) out2_state );
    }
}

int main ( void ) 
{
    /* Do not remove this line or clock might not be set correctly. */
    #ifdef PREINIT_SUPPORTED
    preinit();
    #endif
    
    application_init( );
    
    for ( ; ; ) 
    {
        application_task( );
    }

    return 0;
}


// ------------------------------------------------------------------------ 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.