Intermediate
30 min

Achieve stable connection between high-voltage components and low-voltage equipment using TLP2770 and PIC18F47K42TQFP

Optocouplers: Where light and data high-five

Opto 2 Click with Curiosity Nano with PIC18F47K42

Published Feb 13, 2024

Click board™

Opto 2 Click

Dev Board

Curiosity Nano with PIC18F47K42

Compiler

NECTO Studio

MCU

PIC18F47K42TQFP

Safeguard delicate signals from potential harm, such as electrical noise or voltage fluctuations, ensuring they reach their destination intact and unaltered.

A

A

Hardware Overview

How does it work?

Opto 2 Click is based on four TLP2770, 20Mbps low-power optocouplers from Toshiba Semiconductor. These are fast optocouplers, with their output stages shielded against EMI, allowing them to work on higher speeds, providing common-mode transient immunity of ±20 kV/μs. The internal LED elements are driven with 4mA for 5V operation or 2.6mA for 3.3V operation. The input stages are also equipped with (Schottky) diodes, which prevents inverse polarization of the LED elements and thus, a permanent damage that might occur in that case. The working principle of the optocouplers is quite simple: A photo-emitting element - usually a LED, is encapsulated inside the die along with the photo-sensitive element, which can be a photo-sensitive transistor or a photo-diode. LEDs and photo-sensing elements are galvanically isolated, making the input and output electrical networks completely independent of each other. When the LED is biased, it emits light which in return causes the current to flow through

the photo-sensitive element. In these particular optocouplers, the output stage is additionally conditioned by a Schmitt trigger and it drives the output transistors which form a totem pole output stage. Having a totem pole output configuration allows the output stage to both sink and source current. The optocoupler inputs - the anodes (labeled as A) and cathodes (labeled as C) of the internal optocoupler LEDs, are routed to the screw terminals, which allow connection the external electrical circuit, used to trigger an event on the isolated MCU. The electrical potential between the anode and the cathode input of each optocoupler element should stay within the range between 3.3V and 5V. The optocoupler outputs are routed to the mikroBUS™ The mikroBUS™ pins INT, CS, RST, and AN, are routed to the optocoupler outputs 1, 2, 3, and 4, respectively, and are labeled as IN1, IN2, IN3, and IN4. As already mentioned, the output stages are conditioned with the Schmitt trigger circuit, reducing the input noise sensitivity

and false triggering. The Faraday shield protects the output stages against EMI and provides common-mode transient immunity of ±20 kV/μs. Although these mikroBUS™ pins are labeled as IN1 to IN4, they are actually outputs from the optocouplers, and it is highly recommended to use them as the INPUT pins on the host MCU. The Click board™ is equipped with an SMD jumper labeled as LOGIC, which allows selection of the voltage, applied to the optocoupler output stage. This voltage effectively determines the logic voltage level for the MCU pins. It can be selected between 3.3V and 5V, allowing this Click board™ to be interfaced with both 3.3V and 5V MCUs. The provided library offers functions that simplify and speed up the application development. The included example application demonstrates their use. This application can be used as a reference for custom projects.

Opto 2 Click top side image
Opto 2 Click bottom side image

Features overview

Development board

PIC18F47K42 Curiosity Nano evaluation kit is a cutting-edge hardware platform designed to evaluate the PIC18F47K42 microcontroller (MCU). Central to its design is the inclusion of the powerful PIC18F47K42 microcontroller (MCU), offering advanced functionalities and robust performance. Key features of this evaluation kit include a yellow user LED and a responsive mechanical user switch

providing seamless interaction and testing. The provision for a 32.768kHz crystal footprint ensures precision timing capabilities. With an onboard debugger boasting a green power and status LED, programming and debugging become intuitive and efficient. Further enhancing its utility is the Virtual serial port (CDC) and a debug GPIO channel (DGI GPIO), offering extensive connectivity options.

Powered via USB, this kit boasts an adjustable target voltage feature facilitated by the MIC5353 LDO regulator, ensuring stable operation with an output voltage ranging from 2.3V to 5.1V (limited by USB input voltage), with a maximum output current of 500mA, subject to ambient temperature and voltage constraints.

PIC18F47K42 Curiosity Nano double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

PIC

MCU Memory (KB)

128

Silicon Vendor

Microchip

Pin count

40

RAM (Bytes)

8192

You complete me!

Accessories

Curiosity Nano Base for Click boards is a versatile hardware extension platform created to streamline the integration between Curiosity Nano kits and extension boards, tailored explicitly for the mikroBUS™-standardized Click boards and Xplained Pro extension boards. This innovative base board (shield) offers seamless connectivity and expansion possibilities, simplifying experimentation and development. Key features include USB power compatibility from the Curiosity Nano kit, alongside an alternative external power input option for enhanced flexibility. The onboard Li-Ion/LiPo charger and management circuit ensure smooth operation for battery-powered applications, simplifying usage and management. Moreover, the base incorporates a fixed 3.3V PSU dedicated to target and mikroBUS™ power rails, alongside a fixed 5.0V boost converter catering to 5V power rails of mikroBUS™ sockets, providing stable power delivery for various connected devices.

Curiosity Nano Base for Click boards accessories 1 image

Used MCU Pins

mikroBUS™ mapper

Optocoupler 4 Output
PA0
AN
Optocoupler 3 Output
PA7
RST
Optocoupler 2 Output
PD4
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
Optocoupler 1 Output
PA6
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 2 Click Schematic schematic

Step by step

Project assembly

Curiosity Nano Base for Click boards accessories 1 image hardware assembly

Start by selecting your development board and Click board™. Begin with the Curiosity Nano with PIC18F47K42 as your development board.

Curiosity Nano Base for Click boards accessories 1 image hardware assembly
Charger 27 Click front image hardware assembly
PIC18F47K42 Curiosity Nano front image hardware assembly
Prog-cut hardware assembly
Charger 27 Click complete accessories setup image hardware assembly
Curiosity Nano with PIC18F47XXX 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
PIC18F57Q43 Curiosity 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 via Debug Mode

1. Once the code example is loaded, pressing the "DEBUG" button initiates the build process, programs it on the created setup, and enters Debug mode.

2. After the programming is completed, a header with buttons for various actions within the IDE becomes visible. Clicking the green "PLAY" button starts reading the results achieved with the Click board™. The achieved results are displayed in the Application Output tab.

DEBUG_Application_Output

Software Support

Library Description

This library contains API for Opto 2 Click driver.

Key functions:

  • opto2_check_out1 - OUT1 Check function

  • opto2_check_out2 - OUT2 Check function

  • opto2_check_out3 - OUT3 Check function

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 2 Click example
 * 
 * # Description
 * This application used to provide an optical isolation of sensitive microcontroller.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes device selects the outputs (OUT1 - OUT4) which state be checked.
 * 
 * ## Application Task  
 * Performs the check procedure for selected outputs and logs the states from that
  outputs on USB UART. Repeat the check procedure every 2 seconds.

 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "opto2.h"

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

static opto2_t opto2;
static log_t logger;

static uint8_t sel_output;

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

void opto2_set_logger ( uint8_t sel_out1, uint8_t sel_out2, uint8_t sel_out3, uint8_t sel_out4 )
{
    
    if ( sel_out1 > 1 )
    { 
        sel_out1 = 1;
    }
    if ( sel_out2 > 1 )
    {
        sel_out2 = 1;
    }
    if ( sel_out3 > 1 )
    {
        sel_out3 = 1;
    }
    if ( sel_out4 > 1 )
    {
        sel_out4 = 1;
    }

    sel_output = 0;
    sel_output |= sel_out1;
    sel_output |= sel_out2 << 1;
    sel_output |= sel_out3 << 2;
    sel_output |= sel_out4 << 3;
}

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

    opto2_cfg_setup( &cfg );
    OPTO2_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    opto2_init( &opto2, &cfg );

    log_info( &logger, "---- Application Init ----" );

    opto2_set_logger( 1, 1, 0, 0 );
    log_printf( &logger, "OPTO 2 is initialized \r\n" );
    log_printf( &logger, "" );
    Delay_ms( 200 );
}

void application_task ( void )
{
    uint8_t check_output;
    uint8_t cnt;
    uint8_t tmp;

    tmp = 1;

    for ( cnt = 0; cnt < 4; cnt++ )
    {
        switch ( sel_output & tmp )
        {
            case 0x01 :
            {
                check_output = opto2_check_out1( &opto2 );

                if ( check_output == 0 )
                {
                    log_printf( &logger, "OUT1 is low\r\n" );
                }
                else
                {
                    log_printf( &logger, "OUT1 is high\r\n" );
                }
                break;
            }
            case 0x02 :
            {
                check_output = opto2_check_out2( &opto2 );

                if ( check_output == 0 )
                {
                    log_printf( &logger, "OUT2 is low\r\n" );
                }
                else
                {
                    log_printf( &logger, "OUT2 is high\r\n" );
                }
                break;
            }
            case 0x04 :
            {
                check_output = opto2_check_out3( &opto2 );

                if ( check_output == 0 )
                {
                    log_printf( &logger, "OUT3 is low\r\n" );
                }
                else
                {
                    log_printf( &logger, "OUT3 is high\r\n" );
                }
                break;
            }
            case 0x08 :
            {
                check_output = opto2_check_out4( &opto2 );

                if ( check_output == 0 )
                {
                    log_printf( &logger, "OUT4 is low\r\n" );
                }
                else
                {
                    log_printf( &logger, "OUT4 is high\r\n" );
                }
                break;
            }
            default :
            {
                break;
            }
        }

        tmp <<= 1;
    }

    Delay_ms( 2000 );
}

void main ( void )
{
    application_init( );

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

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