For the majority of June I was working on making the LED cube featured in my previous post. The next few posts will cover making the cube and writing the software which controls it.
The initial post of the cube working first appeared on the Netduino forums in early July. As you can see, it received some good responses.
This project will require the following materials:
Description
Quantity
LEDs (use which ever colour floats your boat – I went for blue)
512
74HC595 Shift Registers
8
74HC238 3 to 8 line decoder
1
Netduino Mini
1
16 Pin DIL Socket
9
24 Pin DIL Socket (0.6″)
1
TIP122 NPN Transistor
8
100nF Ceramic Capacitor
10
2.2K Resistor
8
68 Ohm 0.25W Resistor (you may need to change these depending upon the LED you choose)
64
8 Way Single Row Socket
8
36 Way Header Strip (Straight)
2
2 Way Single Row Socket
2
2 Way PCB Mount Terminal Connector
1
8 Way Ribbon Cable
2.5 metres
Wire and connectors
Miscellaneous
Pad board 160 x 115 Hole
1
Hex PCB spaces, M3 threaded and M3 screw
4
As well as the above you will need the following items:
5V Power capable of delivering 2A;
Solder – I used about 15 metres over the life of this project;
Wood to make a template.
As well as the physical items you will need a fair amount of patience and good attention to detail. There are a lot of repetitive tasks in this project. The method is detailed in the three articles listed at the head of this article.
March 18th, 2012 • Electronics, Netduino • Comments Off on Making a Cube of LEDs
This is probably the most time consuming part of the project requiring a lot of patience, testing and a 30cm x 30cm piece of wood. Seriously, you’ll need a piece of wood. Here we are going to convert this:
Into this:
Working out the Dimensions of the Cube
The exact dimensions of the cube will depend upon the length of the legs on the LEDs. The legs will be soldered together with the cathodes of the LEDs forming a horizontal plane and the anodes connecting the layers vertically.
Take one of the LEDs and bend the cathode at a point as close to the body of the LED as possible. The cathode should be at 90 degrees to the anode and parallel to the flat base of the LED. Now bend the top 3mm of the leg of the anode through 90 degrees. You are aiming for something which looks like this:
In the final cube we want all of our LEDs to be above each other. If we don’t then each layer will be slightly offset from the on beneath it. We won’t have a cube more of a leaning tower. So the final act of manipulation for the LED is to bend the anode of the LED slightly out from the body of the LED and then to straighten the anode again. The effect should be that the 3mm at the end of the anode should be enough to place the LEDS above each other. When they are connected in the cube they should look like this:
Layer Template
Measure the distance from the centre of the now horizontal cathode to the end of the leg and subtract about 2mm. This will tell you how far apart the LEDs are in the horizontal plane. The 2mm will be used to overlap with the neighbouring LED and will be used to connect the cathodes. Now this is where the wood comes in. You need to drill a grid of holes 8 x 8 which are each this measured distance apart. You will end up with a template in which you can place the LEDs in each layer making soldering easier.
The holes in the template must be small enough to hold the LED firmly but not too firm. The LEDs will need to be removed later without placing too much strain on the soldered joints.
Building the Layers
So now let’s get the soldering iron warmed up and on with the first layer. Take 8 of the LEDs and place them along the top row with the cathodes all pointing to the right (or left if you prefer). The cathodes of the 7 LEDs to the left will overlap slightly with the LED to the right. The rightmost cathode will go off into space. Solder the cathodes together. Congratulations, you now have a line of LEDs.
Now let’s add the remaining LEDs in the layer. I started on the left as I hold the soldering iron in my right hand. Take another 7 LEDs and place these under the top row down the far left column. Again the cathodes should be overlapping. Solder these together. Repeat with the remaining columns. At this point you should have a horizontal row of LEDs connected together with 8 strings of 7 LEDs hanging from it. Eventually you should have something looking like this:
Now test the layer. Simple enough, you just need a power supply and a current limiting resistor. For the LEDs I had chosen a 5V supply fed through a 68 Ohm resistor is adequate. Connect ground to the cathode of the LED which is flying off into space (remember, it’s on the top row, to the right). Now touch each leg of the LEDs in turn with the positive output of the supply (through the current limiting resistor of course). The LEDs should light up and as you touch the anode.
One final bit of soldering is to add a stiffening wire to the layer. Cut and strip a piece of wire. The wire should be long enough to cross the entire layer. Now solder the stiffening wire to the cathodes along the bottom of the layer. See the image above. One thing to note here is that although one piece of wire is sufficient, adding one or two more would not harm.
At this point you will have one complete layer. Time to remove it from the template. This should be done carefully so that you do not put too much stress on the joints. Lifting it up gently with a screwdriver should help. Do not be in a hurry, gently freeing the LEDs first may help. Put this layer to one side and repeat another 7 times.
Connecting the Layers
Now that we have all of the layers built I suggest that they are tested once again. This repeated test may save you pain later. Just imagine how difficult it will be to fix a bad joint in the middle of the cube. We are just checking that the LEDs are still connected and none of the joints have been broken removing the layers from the template.
Now drop one of the layers back into the template. What we now need to do is to place a second layer on top of this one so that the anodes of the layer in the template touch the anodes of the LEDs in this layer. Once in place we need to solder the anodes together – good game, good game. I had the advantage of having a few clamps which could be adjusted vertically as well as horizontally. I would imagine that cardboard (or wood) shaped to the correct height should help support the layers. Remember that whatever you use you will need to be able to remove it without damaging the cube.
Now you have the layer supported, solder the anode of the LEDs in the top layer to the anode of the LED in the layer directly beneath it. Once this has been done – test. Connect the cathode of the bottom layer to ground and touch each of the legs on the top layer in turn with the +ve supply (going through the current limiting resistor). The LED on the bottom layer should light. Move the cathode to the top layer and repeat the test, this time the LED on the top layer should light.
Repeat adding the remaining layers. Just for safety, I would test every layer in the cube as it is built up. This repeated testing sounds like a big overhead but trust me it’s worth it.
So at this point you should now have a cube and if you are like me, lost two days of your life in pursuit of happiness and all that is good in life.
December 1st, 2011 • Dates to Remember, General • Comments Off on Happy Birthday to the BBC Micro
The emergence of low cost computers in the UK market in the early 1980s kick started many a career in IT. The early market was not dominated by one type of machine but rather one full of choices from a myriad of companies. School playgrounds across the country soon became split between two camps, you either loved the Spectrum or the BBC Micro (which quickly became known as the Beeb). There were friends with other computers (Vic 20, Dragon, Commodore 64 to name a few) but these people were in the minority and viewed as weird.
Today marks the day the BBC Micro was first launched on the market. At the time it was expensive compared to the other machines on the market but it was supported by the BBC in the form of a TV series about computers and their uses.
At the time the BBC Micro was launched I had already been programming for several years but it is this machine which I remember with fondness. I had a great time learning how this machine worked and even purchased the Advanced BBC Micro handbook. It was this handbook which allowed me to get closer to the hardware. I even wrote my own disc operating system. This also taught me a very valuable lesson, always backup your work – I accidental tested the format command on the disc containing the only copy of the source code. To my dismay it was one of those occasions where I had managed to write 200 lines of assembler which worked perfectly first time.
The early industry meant that schools had to quickly put together a programme of lessons which taught pupils about the new machines and how to use them. The lack of software such as spreadsheets, presentation software etc. meant that children were taught about the machines and how they worked. Something which is lacking today. This lack of understanding about how computers actually work is slowly being recognised here in the UK and it appears that the government is starting to recognise that something needs to be done. One group of people who remember those early days are already working on a small computer for the education market. Check out the Raspberry Pi for more information on the project.
A while ago I created a circuit and some code to control the TLC5940 LED driver using a Netduino Mini. This chip allowed the programmer to control 16 LEDs using a serial interface. In the conclusions I noted that it should be possible to control two or more of these chips by cascading the serial output from one chip into another. This article discusses the additional hardware required along with the software to control up to 32 LEDs using two of these chips linked together.
It is assumed that you have read and understood the previous article before you proceed further.
Hardware
Linking two of these chips is a relatively simple affair and requires the LEDs you wish to control and only 1 additional component, namely a 2K2 ohm resistor, and some additional wire (assuming you are using breadboard).
Starting with the simplest part, the 2K2 ohm resistor connects the IREF pin on the second TLC5940 to ground. This sets the reference voltage for the LEDs connected to the second TLC5940.
The next part of the problem is to connect the two chips together. This is achieved by connecting the following pins:
TLC5940 (1)
TLC5940 (2)
SCLK
SCLK
BLANK
BLANK
XLAT
XLAT
GSCLK
GSCLK
VPRG
VPRG
SOUT
SIN
XERR
XERR
DCPRG on TLC5940 is connected to Vcc as it is on the first driver chip and the LED controller pins connected to the appropriate LEDs.
Now we have the additional LEDs in the circuit we will need to be able tell the software driver for the chips how many LEDs we want to control and then be able to control the brightness of the LEDs. In order to do this an additional parameter was added to the constructor numberOfLEDs. This parameter allows the system to work out how many TLC5940’s should be connected together. Once we have the number of chips calculated we can then work out the size of the buffers for the Dot Correction and the Grey Scale data.
The class uses two buffers for both the Dot Correction and the Grey Scale data. This may seem superfluous but doing this allows two different modes of operation:
Basic – The LEDs can be controlled using an interface which is simpler to use but is slower.
Fast – This mode is faster but requires the programmer to perform some of the tasks in the driver. The assumption here is that the programmer will have more understanding of the data which is changing and can therefore write more optimised code.
For the moment we will be discussing the basic mode. In this mode, the software driver hides much of the implementation and the user only really needs to perform three tasks:
Construct a new instance of the software driver.
Set the brightness of the LEDs (only the lower 12 bits are used).
Tell the driver to output the data to the TLC5940 chips.
Constructor
Making a new instance of the class in it’s most basic form is simply a case of telling the constructor how many LEDs you wish to control. In this case we have two TLC5940s connected together and so we have 32 LEDs:
Tlc5940 leds = new Tlc5940(numberOfLEDs: 32);
You can of course use the additional parameters to define the pins used for the various control signals or just use the defaults.
Setting a LED
The class contains a method which overloads the array indexing operator. Setting the brightness for a LED is simply a case of using this operator as follows:
leds[10] = 767;
This will set the brightness of LED 10 to the value 767.
An important note here is that the LEDs are numbered from 0 to 15 on the TLC5940 connected to the Netduino Mini, 16 to 31 on the next LED in sequence and so on.
Lighting the LEDs
The final piece of the puzzle is to output the data to the series of TLC5940s connected to the Netduino Mini. This is achieved by calling the Display method in the Tlc5940 class.
Source Code
The source code for the controller class and a simple main program can be found here (CascadedTLC5940.zip).
Conclusion
The work with this chip has not yet finished as there are still some points which need addressing in order to round off this class:
Dot Correction – this current outputs all 1’s and so there is no fine control for any of the outputs.
Error Detection and Status Information – It is possible to detect two types of errors and retrieve the status information from the TLC5940. This needs implementing.
One final item which needs addressing is to round off the code once these final feature have been implemented. A topic for another day.
October 8th, 2011 • Electronics, Netduino • Comments Off on TLC5940 16 Channel PWM Driver
I have recently been working with the TLC5940 LED Driver chip. This provides 16 PWM outputs which can be used to drive common anode LEDs and I suspect motors etc. For the moment I will be using it to drive 16 LEDs to prove the principle and work out how to interface the chip to the Netduino Mini.
The article and code contained here should allow the creation of a circuit capable of doing the following (and a whole lot more):
Objective
The objective of this exercise is to use the TLC5940 to control 16 LEDs under the control of the Netduino Mini. This will require the following to be developed:
Timer circuit to control the grey scale output.
Control signals and reference voltage to control the output of the TLC5940
Control logic and software for the Netduino Mini
A description of PWM and how it works is assumed. If you require more information then you can check out the Wikipedia article on PWM.
Timer (Clock) Circuit
The TLC5940 uses an external timing signal to control the 16 grey scale outputs to the LEDs. This signal can be as high as 30 MHz. The design presented here uses an 8 MHz crystal / resonator. When I was developing the circuit I have little knowledge of how to build the timer and so used a NE555 configured as a 40 kHz astable oscillator. This was crude but was good enough to start the project. The final design uses an oscillator circuit from a document recommended by Mario on the Netduino forums. You can read the original post here. Mario recommended circuit 1d which is the one I finally used:
The final inverter is not really necessary but the chip contains 6 inverters and I was only using two so I fed the output from the timer through an final inverter. This had the effect or producing a squarer signal – although the final signal is still slightly rounded.
In the final circuit I actually used a resonator. I simply dropped this in place of the crystal connecting the outer two pins to the logic gates and the centre pin to ground.
Control Signals
As well as the clock signal, the TLC5940 requires several control signals to determine how the chip should treat the grey scale data. This section looks at each signal and describes its function.
BLANK (Pin 23)
This pin determines the output state of the TLC5940. When this pin is high the outputs are turned off. Setting the pin low turns the outputs back on. More importantly, it changes the internal counter for the PWM control and resets the counter to 0. It is to this counter to which we now turn out attention.
The TLC5940 uses 12 bits to determine the output level for the LEDs connected. Each LED is controlled independently and the full array of 12 bits requires a total of 192 bits (12 bits x 16 LEDs) of data to determine the output levels for the LEDs. The 12 bits for each LED gives a total of 4096 (remember this number, we’ll be using it later) levels for each LED (0 to 4095 inclusive). The TLC5940 uses this data and the current counter to determine the output state of each OUT pin.
Setting BLANK to high and then low causes the counter to be set to zero. An incoming clock pulse causes the counter to be incremented by 1. The chip then turns on all of the outputs which have a greyscale value which is non-zero. Each subsequent pulse cause the chip to do the following:
Increment the counter
For each output compare the counter with the greyscale value for the output pin. If the value is greater than the counter then turn the output on, else turn the output off.
This process repeats until the internal counter reaches 4095 at which point the process stops and the outputs are effectively turned off (the counter value is greater than or equal the output value for the LEDs). This point is important as providing only one pulse to BLANK and a series of 4096 (or more) clock pulses makes this a one time only output. The LED on each output lights for the specified duty cycle and then turns off.
The trick here is to ensure that a BLANK pulse is generated for every 4096 greyscale clock pulses. This is achieved by attaching the output from the timer circuit to both the greyscale clock on the TLC5940 and a divider circuit. The divider counts 4096 clock pulses and then outputs a new BLANK signal to the TLC5940 effectively restarting the counting process. So the modified clock circuit looks something like this:
The clock signal is split and one connection to the GSCLK (grey scale clock) pin on the TLC5940, the other connection is to the clock inputs of a 14-bit counter/divider (74HC4060). The divider counts the clock pulses and sets the output pins of the chip to represent the current value of the counter. The counter is reset once it reaches the maximum value and the whole process restarts. The counter does not output the lower three bits but this is not an issue for us as we are interested in counting to 4096. We can use the output from bit 12 (2 ^ 12 = 4096) as a BLANK signal for the TLC5940. So for the first 4095 pulses the TLC is setting the outputs according to the values held for each pin. When the counter reaches 4096, the TLC stops displaying data but then a BLANK pulse is received from the divider. This then restarts the whole process. The result, we have the outputs continuously cycling the the LEDs on for the required duty cycle.
One final point about the BLANK signal. This could be used by the microcontroller which is controlling the circuit to turn off the outputs. To allow for this, the output from the divider is ORed with the BLANK signal coming from the microcontroller. The output from the OR gate is passed on to the TLC5940.
VPRG (pin 27)
This signal determines the type of data being transmitted to the TLC5940.
When VPRG is high the chip expected 96 bits of data for the Dot Correction (DC) registers. The DC registers allow the controller to scale the output current supplied at each output pin. This is covered later in this article.
When VPRG is low, the TLC5940 expects 192 bits of data for the grey scale registers.
XLAT (pin 24)
A low-high pulse on this pin latches the data received from the microcontroller into the DC or the GS registers. The data is latched on the rising edge (i.e. low to high) of the XLAT signal.
DCPRG (pin 19)
This pin is not used in this circuit and to connected to Vcc
IREF (pin 20)
This pin can be used to set the maximum current output on each of the output pins. This is done by connecting the pin to ground through a resistor. The value of the resistor is determined by the following calculation:
R = (1.24 / Imax) * 31.5
Where Imax is the maximum current to be supplied. The value of 1.24 is the reference voltage on the IREF pin.
For the LEDs I am using I want a maximum current of about 26mA. This gives a resistor value of 1502 ohms, so a 1k5 resistor should do here.
XERR (pin 16)
This pin is an output from the TLC5940 and can be used to report when an error is detected. This pin is not used in this project and is connected through a 10K pull-up resistor to Vcc.
Grey Scale and Dot Correction
The TLC5940 uses a value in the range 0-4095 to represent the duty cycle for each of the outputs. This gives an effective brightness for each LED given by the following calculation:
Percentage brightness = (Grey Scale value for output N / 4095) * 100
The dot correction reduces the current flowing through the output pins. This can have two effects, it can be used to adjust the current to bring it in range for a specific LED or it can be used to fine tune the output current for an output pin. This can effectively reduce the brightness of a LED. The change in maximum current for a pin is given by the following calculation:
Iout = Imax * (Dot correction value for pin N / 63)
Where Imax is set using the resistor connected to the IREF pin (discussed above).
Final Circuit
The final circuit looks like this:
Controlling the Chip
The whole circuit is controlled using a Netduino Mini. The four pink control lines in the above circuit are used by the Netduino Mini to control the TLC5940.
Pin Name
Description
MOSI / SIN
Serial data output from the Netduino Mini (pin 14 on the Netduino Mini)
SPCK / SCLK
Clock signal for the serial data (pin 16 on the Netduino Mini)
XLAT
Data latch signal. This could be connected to the chip select although in the initial implementation this is broken out to it’s own pin.
VPRG
Determine the programming mode for the TLC5940. High: Dot Correction data is being loaded. Low: Grey Scale data is being loaded.
BLANK
Turn the outputs (LEDs) on or off. High: Outputs off. Low: Outputs on.
The application encapsulates the TLC5940 functionality in a single class Tlc5940. This project only deals with one chip controlling 16 outputs (even though several can be linked together). The class only exposes 2 methods:
Constructor
Display
Constructor
The constructor sets up the system to use the SPI interface and takes parameters to determine which additional control pins should be used.
Display
The display method takes two parameters, one for each of the dot correction data and one for the grey scale data.
The main program contains a small demonstration of the functionality of this class and the TLC5940 chip. It slowly fades in 16 LEDs from off to full brightness and then fades them out to the off state again. This is repeated in a loop forever. For an example of the output see the video at the top of this article.
The code is pretty well commented and so further discussion is not provided here.
This article is really a starter for this chip as there is a whole lot more which is possible. There are a number of areas where I would like to expand both the code and the circuit, namely:
Resetting the counter when it reaches 4096. At the moment this runs on until it reaches the maximum value.
Use the dot correction values to allow different LEDs to be used on each pin. Different LEDs have different forward currents and this can be fine tuned using the dot correction data to allow the maximum brightness to be achieved by each individual LED.
Look at using the CS pin on the SPI interface for the BLANK signal from the Netduino Mini to the TLC5940.
Add some error checking code to check if the TLC5940 has detected any errors.
Link two or more TLC5940’s together.
Adding these features will make this class more rounded and fully encapsulate the feature set offered by this circuit.
September 21st, 2011 • Electronics, Netduino • Comments Off on The Cube Goes Travelling
The first cube was completed in July and the initial posting generated some interest. I agreed to make a second and this one has just completed it’s first transatlantic journey and has made an appearance at MakerFare in New York. The following image appeared on Time Out New York’s web site:
Building the second cube was fun as I was able to implement all of the lessons learned from making the first cube.
September 11th, 2011 • Electronics, Netduino • Comments Off on Netduino Cube Information
Whilst the blog may have been a little quiet recently I have never the less been busy writing about the cube. There is a Wiki article on the Netduino web site showing how the cube was constructed.
I have also released the source code to the project on Codeplex.
This website uses cookies to improve your experience and to gather page view statistics. This site does not collect user information. Accept & CloseRead More
Privacy & Cookies Policy
Privacy Overview
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.