Intermediate
30 min

Unlock the full potential of PWM with LTC8500 and ATmega2560

48 channels, 1 SPI connection - Unleash your creativity!

PWM 2 Click with Arduino Mega 2560 Rev3

Published Feb 14, 2024

Click board™

PWM 2 Click

Dev Board

Arduino Mega 2560 Rev3

Compiler

NECTO Studio

MCU

ATmega2560

With 48 channels controlled through one interface, you gain total PWM dominance, giving you the power to manage your devices and applications with precision and efficiency

A

A

Hardware Overview

How does it work?

PWM 2 Click is based on the LT8500, a 48-channel LED PWM generator with 12-bit resolution and 50MHz serial interface from Analog Devices. This IC has 48 independent 12-bit PWM channels, each with 6-bit correction up to 50% of the original duty cycle. The LT8500 IC is clocked by a clock signal at the PWMCK pin. The frequency of the clock signal can go up to 25MHz, generating the PWM output frequency of up to 6.1kHz, which is sufficient for most purposes. The maximum speed of the LT8500 serial interface goes up to 50MHz in theory, but in practice, it will depend on many factors. The clock signal at the PWM pin of the mikroBUS™ is triggering an internal counter register (PWMCK). This register is compared with the content of the PWMRSYNC register, associated with each channel. Whenever the counter value is less than the value written in a specific channel PWMRSYNC register, the PWM output of that channel goes to a HIGH logic level. The frequency of the output PWM signal is therefore determined by the frequency the clock signal at the PWMCK pin. This represents the basic operating principle of the LTC8500 IC. The PWMCK pin is routed to the PWM pin of the mikroBUS™. The device uses an industry-standard SPI interface for the communication. The LDI pin acts as the normal Chip Select, latching the SPI data in, but it has an additional function if held to a HIGH logic level

for more than 50µs. In that case, the IC will be reset, and all outputs will be blanked. Therefore, care should be taken not to hold this pin to a HIGH logic level, for more than 5µs. The LDI pin is routed to the CS pin of the mikroBUS™ and it is labeled as LDI. Besides the usual SPI interface lines, the LT8500 PWM generator IC provides a serial interface clock output signal (SCKO), allowing additional devices to be connected in the parallel 5-wire topology (LDI, SCKI, SDI, SDO, and SCKO). This allows large-scale cascading, without the need for the skew balancing or buffering the signals. These additional pins are available at the standard 2.54 pitch headers on board. These additional pins on the header are described in a table, below. More information about cascading and using the SCKO feature of the IC can be found in the LT8500 datasheet. The device is controlled by sending commands via the SPI interface, embedded in a command frame. There are eight different commands which are used to control the following parameters: PWM outputs update (synchronously or asynchronously to PWM period), the dot correction factor, self-test initialization, phase shifting between banks (groups of 16 channels), enabling/ disabling of the PWM output drivers, and enabling/disabling of the dot correction . A frame consists of a 12-bit data field for each of the 48 PWM channels, followed by an

8-bit command field, which contains one of the eight command codes. The status frame is clocked on the SDO pin, providing the host MCU with the frame information: LED fault status, phase shifting status, correction status, synchronization status, and so on. This information can be used either for troubleshooting or for other purposes by the host MCU application. As already mentioned, additional functionalities of the LT8500 IC are offered via the onboard headers, along with the 48 PWM channel outputs. The outputs are not meant to drive devices with high current, so PWM 2 click is best used as the driver for additional circuitry, whether it is a simple MOSFET LED driver, or a more complex ICs, such as the LT3595A LED driver, for which a special input pin is reserved, allowing open LED conditions to be detected, even on the externally connected LT3595 IC. Onboard headers also offer fixed 5V output from the mikroBUS™ for the auxiliary purposes. This Click board™ can operate with either 3.3V or 5V logic voltage levels selected via the PWR SEL jumper. This way, both 3.3V and 5V capable MCUs can use the communication lines properly. Also, this 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.

PWM 2 Click top side image
PWM 2 Click bottom side image

Features overview

Development board

Arduino Mega 2560 is a robust microcontroller platform built around the ATmega 2560 chip. It has extensive capabilities and boasts 54 digital input/output pins, including 15 PWM outputs, 16 analog inputs, and 4 UARTs. With a 16MHz crystal

oscillator ensuring precise timing, it offers seamless connectivity via USB, a convenient power jack, an ICSP header, and a reset button. This all-inclusive board simplifies microcontroller projects; connect it to your computer via USB or power it up

using an AC-to-DC adapter or battery. Notably, the Mega 2560 maintains compatibility with a wide range of shields crafted for the Uno, Duemilanove, or Diecimila boards, ensuring versatility and ease of integration.

Arduino Mega 2560 Rev3 double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

AVR

MCU Memory (KB)

256

Silicon Vendor

Microchip

Pin count

100

RAM (Bytes)

8192

You complete me!

Accessories

Click Shield for Arduino Mega comes equipped with four mikroBUS™ sockets, with two in the form of a Shuttle connector, allowing all the Click board™ devices to be interfaced with the Arduino Mega board with no effort. Featuring an AVR 8-bit microcontroller with advanced RISC architecture, 54 digital I/O pins, and Arduino™ compatibility, the Arduino Mega board offers limitless possibilities for prototyping and creating diverse applications. This board is controlled and powered conveniently through a USB connection to program and debug the Arduino Mega board efficiently out of the box, with an additional USB cable connected to the USB B port on the board. Simplify your project development with the integrated ATmega16U2 programmer and unleash creativity using the extensive I/O options and expansion capabilities. There are eight switches, which you can use as inputs, and eight LEDs, which can be used as outputs of the MEGA2560. In addition, the shield features the MCP1501, a high-precision buffered voltage reference from Microchip. This reference is selected by default over the EXT REF jumper at the bottom of the board. You can choose an external one, as you would usually do with an Arduino Mega board. There is also a GND hook for testing purposes. Four additional LEDs are PWR, LED (standard pin D13), RX, and TX LEDs connected to UART1 (mikroBUS™ 1 socket). This Click Shield also has several switches that perform functions such as selecting the logic levels of analog signals on mikroBUS™ sockets and selecting logic voltage levels of the mikroBUS™ sockets themselves. Besides, the user is offered the possibility of using any Click board™ with the help of existing bidirectional level-shifting voltage translators, regardless of whether the Click board™ operates at a 3.3V or 5V logic voltage level. Once you connect the Arduino Mega board with Click Shield for Arduino Mega, you can access hundreds of Click boards™, working with 3.3V or 5V logic voltage levels.

Click Shield for Arduino Mega accessories 1 image

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
NC
NC
RST
Latch Data Input
PL4
CS
SPI Clock
PB1
SCK
SPI Data OUT
PB3
MISO
SPI Data IN
PB2
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Clock Input
PE4
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

Click board™ Schematic

PWM 2 Click Schematic schematic

Step by step

Project assembly

Click Shield for Arduino Mega front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Arduino Mega 2560 Rev3 as your development board.

Click Shield for Arduino Mega front image hardware assembly
Arduino Mega 2560 Rev3 front image hardware assembly
Charger 27 Click front image hardware assembly
Prog-cut hardware assembly
Charger 27 Click complete accessories setup image hardware assembly
Arduino Mega 2560 Rev3 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
Arduino MEGA 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 PWM 2 Click driver.

Key functions:

  • pwm2_set_channel - Set channel function.

  • pwm2_pwm_start - Start PWM module.

  • send_output_enable_frame - Enable frame.

Open Source

Code example

The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.

/*!
 * \file 
 * \brief Pwm2 Click example
 * 
 * # Description
 * This application send the PWM signal in one or more outputs.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Configures the click board and sets all PWM channels on the click board to
 * 50% duty cycle with the phase shift enabled.
 * 
 * ## Application Task  
 * The first 10 PWM channels of PWM2 Click board are switched back and forth 
 * from 25% duty cycle to 75% duty cycle every 10 seconds.
 *
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "pwm2.h"

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

static pwm2_t pwm2;
 
void application_init ( void )
{
    pwm2_cfg_t cfg;

    //  Click initialization.

    pwm2_cfg_setup( &cfg );
    PWM2_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    pwm2_init( &pwm2, &cfg );
    
    pwm2_set_duty_cycle( &pwm2, 0.5 );
    pwm2_pwm_start( &pwm2 );

    pwm2_default_cfg( &pwm2 );
    pwm2_toggle_phase_shift( &pwm2 );

    //setting all 48 PWM channels of the PWM2 click to 50% duty
    for( uint8_t cnt = 1; cnt < 49; cnt++ ) 
    {
        pwm2_set_channel( &pwm2, cnt, PWM2_50_PERCENT_DUTY, PWM2_NO_CORRECTION );
    }
}

void application_task ( void )
{
    for ( uint8_t cnt = 1; cnt < 10; cnt++ )
    { 
        pwm2_set_channel( &pwm2, cnt, PWM2_25_PERCENT_DUTY, PWM2_NO_CORRECTION );
    }
    Delay_ms( 10000 );
    
    for ( uint8_t cnt = 1; cnt < 10; cnt++ )
    { 
        pwm2_set_channel( &pwm2, cnt, PWM2_75_PERCENT_DUTY, PWM2_NO_CORRECTION );
    }
    Delay_ms( 10000 );
}

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.