Note: This is part one of a three-part guide.
Part 1 - Getting Started Guide for the Infineon RGB LED Shield (you are here!)
Part 2 - Building a White LED Lamp
Part 3 - Building a Full Color Lamp
Introduction
Infineon have produced an Arduino shield for LED dimming and lightingArduino shield for LED dimming and lighting, and it is quite impressive. It is supplied ready-to-use, just solder up some pin headers, connect up LEDs using the spring connectors, plug it onto the Arduino and give the boards some power. Example Arduino code is supplied too.
The board actually contains an ARM Cortex-M processor but you could use it without realizing it. The processor does explode the ways of using it and amount of possibilities that one can use this shield for.
This post investigates how to make the most of the shield, to help the Internet of Holiday Lights challenge contestants. Also, if you want to build home LED lighting and need a fairly powerful board to control it, then the LED shield from Infineon is likely to be a very good option.
What is the RGB LED Shield?
The RGB LED Shield is a board from Infineon that is designed to be plugged on top of Arduino boards such as the Arduino Uno and others. It has connections for up to three chains of LEDs; the idea is that the three channels could be chains of red, green and blue (e.g. color LEDs). Here is a typical scenario that you could use the shield for:
The shield is is plugged onto an Arduino, and is used to control four RGB LEDs in the example above (it is not necessary to use integrated RGB LEDs of course; separate red, green and blue LEDs could be used, or in fact any color including white). The maximum amount of LEDs that can be controlled in this manner depends on the forward voltage of the LEDs, which typically may be about 2V but varies greatly, from around 1.6V to 4V (check the LED datasheets). Furthermore some LEDs may internally have several LED dies [i.e. chips] inside, and their forward voltage may be a multiple of the ballpark that is mentioned above. Since the LEDs are in series, the supply voltage needed will be a minimum of Vf x N where N is the number of LEDs (or LED dies) in a channel. The shield accepts up to 48V, so close to a dozen or more LEDs of high power should be possible, at up to 700mA current per channel. This could result in a huge amount of light capable of greatly illuminating a room!
Typical power LEDs (the variety which require heatsinks) are often available in 350mA and 700mA versions, and both are suitable for this LED shield. Check out part 2 of this blog post which uses the shield to control high power LEDs.
The shield is great for lighting effects too, because it contains 12-bit resolution brightness control per channel. Some low-cost options (e.g. Neopixels) only offer 8bit resolution, and transition/dimming effects have visible flaws; a minimum of 10-bit resolution is highly useful, and 12-bit is exceptional.
Note that no series resistor is required because the LED shield provides a constant current (which is programmable in software).
Getting Started with the Arduino
Download the PDF quick start guide and user guide and the example Arduino code from the Infineon website (scroll down to the 'GETTING STARTED – XMC1100 BOOT KIT and ARDUINO UNO R3' section and the file you want is titled Getting Started Examples . When run, it will extract into a folder.
If you’ve never used an Arduino before (like me), then before you plug anything in, go to the Arduino site, download and install the software, and then plug in the Arduino board into your PC. Once you know which COM port the Arduino was assigned by your PC (if you are not sure, check using Device Manager in Windows; for other operating systems, the Arduino site can be checked). Next, in the Arduino software, select Tools->Serial Port and choose that port. Select File->Open and navigate to the Arduino_Getting_Started_Examples/Arduino Uno R3/RGBLED_2_SAFE folder and select the file inside there (called RGBLED_2_SAFE.ino).
Click the ‘Verify’ icon (looks like a check-mark) and after a few seconds you’ll see some text saying ‘Binary sketch size’ at the bottom of the window. Now click on the ‘upload’ icon (looks like an arrow pointing right).
The process is complete when the text says ‘Done uploading’ as shown here:
Unplug the Arduino from the PC, and then connect up the LED shield.
I didn’t have any RGB LEDs but I had some high power white LEDs, so I connected two in series to a single channel, just to test out the board. With the demo code, the LEDs must be rated to support at least 300mA and the combined forward voltage for a channel must be at least 6V.
The LEDs need heatsinking, so I used the nearest heatsink I could find (extremely oversized, but it was what I had handy). Really these LEDs should be soldered to a PCB, however I used thermally conductive tape for the test:
Plug in the USB cable into the Arduino (either to a PC, or to any USB 5V supply). The white LEDs had an approximate 3.6V forward voltage each, so I used a 9V DC supply to power the two LEDs. The LEDs dimmed in and out (this is what the demo program does). Clearly with RGB LEDs the result would be more interesting!
It would be a simple step to now begin to modify the Arduino code to suit your project, and use with LED chains of your choice.
How Does It Work?
The LED shield contains a buck converter topology per channel. Each channel contains a MOSFET which is turned on by the Infineon integrated circuit. Current begins to flow through the LEDs in series with an inductor. Because of this, the current rises over time. Because there is also a small fixed resistance in series with this circuit, the current can be measured because it will produce a voltage across the resistor. In other words, the circuit current path consists of LED-inductor-MOSFET-resistor (where the MOSFET and resistor have a low resistance).
The Infineon device (XMC1202) measures the current (by measuring the tiny voltage across the resistor) and powers off the MOSFET once a certain current is reached. At this point, the energy that was stored in the inductor during the time the MOSFET was on continues to flow through a diode (as a result of back-EMF as the magnetic field collapses).
The oscilloscope traces below show the voltage across the resistor. It can be seen to rise until the MOSFET switches off and disconnects the resistor from the remainder circuit (LED-inductor-flywheel diode).
The XMC1202 has been programmed to have a short delay before it switches the MOSFET back on, and this is clearly visible in the oscilloscope traces too (a delay of about 1usec). The first trace was captured using a 9V supply:
The second trace used the same LEDs, but a 24V supply:
The XMC1202 was programmed to switch off the MOSFET at 25mV, but it can be seen that the peaks exceed this. This is normal because of comparator and processing delays. Even at 24V, the peak current is lower than 300mA (I=V/R and the resistor is 0.2 ohms). The design could be optimised by adjusting the peak current and the delay values once suitable LEDs and a supply voltage has been selected. The default values in the code are “safe” values for the worst-case scenario (48V input, and LED chain forward voltage total of 6V). Even without optimisation the operation is good enough to begin to create projects.
The XMC1202 contains a microcontroller inside it, based on an ARM Cortex-M core. It is programmed to operate as an I2C slave. There are very few connections between the LED shield and the Arduino:
The very few connections means that it is very easy to swap the Arduino for a different board if desired (see the next section below).
The XMC1202 has been programmed with quite a rich command set. The user guide explains what values to program to achieve a desired result. The Arduino code was self-explanatory.
Adjusting the Desired Current
In the code, the peak current value at which the XMC1202 begins to switch off the MOSFET can be adjusted by setting this value:
I2CWRITE2BYTES(ADDRESS, CURRENT_RED, x); (and repeat for the other two channels)
where x is an integer, x= I*163.84 (this was based on the formula in the user docs, I just calculated it for the current sense resistor [0.2 ohms] on the LED shield board). As an example, to set the value to 200mA, x would be 32.
However, due to delays in detecting the peak value, the current can exceed this, so it should be checked on a scope, or use an integer smaller than this initially. See the oscilloscope screenshots above (in the How Does it Work section) for the traces to expect. With the demo code, the peak value in the traces there can be seen to be around 40mV and 60mV (for source supply voltage 9V and 24V respectively which were the values I tested with), which corresponds to 200mA to 300mA through the LED(and this looks correct, since this is with the 'safe' demo settings).
There is another setting per channel (parameter OFFTIME_RED, OFFTIME_GREEN, OFFTIME_BLUE), which also needs adjusting when trimming with a scope, the safe default will be a higher value than an optimised value. See the user documentation for more details. If you're not sure, or do not have a means to check, then it is advised to only use 350mA or higher rated LEDs and use the default demo settings since these are safe for 350mA rated LEDs.
Experimenting with FRDM boards
Since the LED shield on top of the Arduino Uno feels top-heavy, it was decided to replace the Arduino with a FRDM board from Freescale. If you’ve not used these boards before, you are missing out. I selected the FRDM-K22F boardFRDM-K22F board, but the better board for beginners is the FRDM-KL25ZFRDM-KL25Z because it has the most examples/demos.
The FRDM boards have 3.3V logic unlike the 5V logic levels of the Arduino Uno. In the case of the LED shield, it pulls up the I2C lines to 5V, however it was decided to go with this. The Freescale processor contains protection diodes, and according to the specification can tolerate 3mA when the voltage exceeds the rated values. The LED shield has 10k resistors as pull-ups, so the 3mA level is not exceeded. If you don’t feel comfortable with this, then the LED shield’s 10k resistors would need to be removed (or the track to the 5V pin would need to be cut) and the I2C pins pulled up to 3.3V instead, with a custom modification.
To test the LED shield, the two built-in buttons on the FRDM board were used to switch on/off the LEDs by sending the appropriate I2C commands. The code is attached to this post.
Creating Your Own XMC1202 Applications
Since the processor inside the XMC1202 is accessible, it becomes possible to create your own applications for it. For example, the I2C instruction set could be extended. Alternatively a complete application could be written for it so that it doesn’t need to behave as an I2C slave. This would allow the LED shield to be used on its own, unplugged from any Arduino or FRDM board. As another example the I2C address could be modified, so that multiple LED shields could be stacked on top of each other (might need very long headers for that, to overcome the height of the connectors on the LED shield).
To program the LED shield, there is a tiny (1.27mm pitch) DIL header already soldered on the board. Cables for this are expensive. An alternative approach is to solder on a 2.54mm header in the space adjacent to the smaller connector, as shown here:
You’ll also need a J-Link emulatorJ-Link emulator or Infineon’s other development board (code KIT_XMC12_BOOT_001). I used a Segger J-Link emulator. It comes in various versions including an educational versioneducational version too.
The first step is to download the development environment, called DAVE, from the Infineon website and install it (this will also install Segger J-Link software). When DAVE is run, let it auto-update itself. Select a folder to act as a workspace for all your projects. Something like C:\projects\DAVE_work would be fine.
Next, download the source code for the default software that is running on the LED shield as shipped. It is at the Infineon website, scroll to the bottom, in the section RGB LED Lighting Shield – XMC1202, titled RGB LED Lighting Shield – XMC1202 Source Code.
Once installed, select File->Import->Infineon->DAVE Project and choose the root directory to be the folder RGB_LED_Shield_v5, and then it should appear in the Project List. Select Copy Projects into Workspace and then click Finish.
You should now have a folder RGB_LED_Shield_v5 in your workspace folder (c:\projects\DAVE_work).
Now you can observe the code and make changes! For example if you wish the LED shield to start up with the red channel at full brightness (i.e. standalone, regardless of if it is plugged into an Arduino or not, but still allow for the Arduino to subsequently control it), then in the main.c file it can be clearly seen where the red intensity and dimming levels are configured, and they can be modified:
Lamphandle.Intensity_Red = 0xfff; BCCUDIM01_AbortDimming(&BCCUDIM01_Handle0, GET_CHANNEL_DIM_MASK(BCCUDIM01_Handle0.DE_Num)); // Abort previous dimming BCCUDIM01_SetDimLvl(&BCCUDIM01_Handle0, 0xfff); // dimming engine 2 BCCUDIM01_StartDimming(&BCCUDIM01_Handle0, GET_CHANNEL_DIM_MASK(BCCUDIM01_Handle0.DE_Num));
The code snippet above will set the red channel to full brightness before the code starts up the I2C slave function. See the screenshot below for where to insert this code.
To compile the code, click on the ‘build all’ icon (highlighted in the screenshot) or go to Project->Build All. The console output should indicate that the code was built successfully, as shown in the screenshot too.
After DAVE has been installed, you are ready to connect up the J-Link device to your board. Four connections are needed, as shown here:
Writing code, and testing it are two separate ‘views’ in DAVE, so you’ll need to go into the ‘TASKING Debug Perspective’ to run the code (a ‘view’ is just a collection of windows that makes sense for the task at hand). You can select that from the top-right (if you can’t see it, you may have to drag the curvy tab left to bring it into view). Now click on the bug icon (highlighted below). Once you do that, you’ll see the stack trace, and the program waiting at the main() entry point. Click the ‘play-shaped’ button to run the code (or you could single-step as desired) and the LED should light up! The code is now programmed into the XMC1202, so after you have finished with the debug session and disconnected the J-Link and power-cycled the LED shield, the new code will still function. You can go back to the code view by clicking on ‘DAVE CE’ at the top-right.
Summary
The RGB LED Shield from Infineon is a nice, high quality way of controlling LED lighting. It is extremely easy to use with an Arduino. With some adjustments, it is possible to fine-tune the output to get the maximum output from LEDs safely. The shield can also be used with any other microcontroller board (e.g. FRDM board, RPI etc) because it is controlled by the standard I2C interface. The I2C commands are extensive and are listed in the user guide. The Arduino code is easy-to-follow. The LED shield was tested on a Freescale board too.
If desired, the software running on the LED shield itself can be easily modified too; this is not essential since the built-in commands are extremely flexible but it allows for the shield to run stand-alone if desired, or with additional custom commands to meet user needs as an example.
If you’re looking to use the RGB shield, then it is also worth purchasing headers, an Arduino or perhaps a FRDM board, lots of LEDs!, a 24V or 48V power supply and also a JTAG emulator if you want to modify the code on the LED shield.
Top Comments