Using a Motor Controller to Drive a LED Chain

In a previous post I explored a technique to connect a chain of LEDs in parallel and enable the LEDs to blink alternatively in a series of animations using an H-Bridge. Since the H-Bridge is used extensively in motor controllers, in this post I take the experiment one level further and use an integrated motor controller to drive the LED chain.

GOAL

Using what was learned from the LED Chain Driver experiment – it should be possible to use an integrated motor controller and create the same animated effects with a chain of LEDs that are connected to a two wire bus in alternate directions.

Fig 1. The connection of the LEDs.

METHOD

Equipment

  • Teensy LC.
  • Integrated Motor Controller.

Connections

It is always fun to use for other experiments and purposes. I had implemented a motor controller a while back for the 2016 revision of Contextual Electronics – The Go, go, go! project. This project used a TB6593FNG integrated motor controller. I checked the specifications of this chip and was confident it would be able to handle the loads that I was intending to use with ease.  All I needed then was a microcontroller. For this purpose, I used a Teensy LC that I had available.

Fig 2. Motor controller board

The connections were made as per the Fritzing diagram below. The Teensy was powered and programmed through its USB connector to the PC. The motor controller board was powered through a 9V battery with an adapter attached and configured to 3.3V. Out1 and Out2 from the motor controller board were connected to the bus lines of a breadboard. LEDs were arranged on the bus lines in an alternate configuration of anodes and cathodes. 

Fig 3. The experiment connection diagram.

The four control lines between the Teensy and the motor controller board were connected as shown in Table 1.

Teensy PinMotor Controller Board
3PWM
4Stand by
5In1
6In2
Table 1. Teensy to motor controller board Connections.

Firmware

I based the firmware off one of the original test programs for the Motor Controller project. I figured this would be the easiest place to start as it uses the Arduino library with the Teensy LC. This sample was then expanded to encompass the animations created for the original LED Chain driver project. 

The original approach to control the discrete components version of the H-Bridge used a PWM signal to control the enabling of the respective banks of LEDS. At that stage I did not consider any additional PWM for the intensity of the LEDs. When driving the LEDs through the motor controller, I have a PWM signal to control the intensity of the LEDs but no clear means to toggle between the respective banks of LEDs. The solution I came up with was to utilise two interrupting timers in the Teensy. One controlled the enabling of the LED banks, whose configuration was changed depending on the effect – slow side to side blinking (5 – 10 Hz) or 100Hz to create a persistence-of-vision effect so that all LEDs are perceived to be on at the same time. The other timer provided a one second pulse to keep track of the duration for the various animation effects.

Fig 4. The algorithm for handling the delay and enabling the LED banks.

Figure 4. depicts a part of the algorithm where the respective interrupt handler routines set a flag. These flags are checked in the main loop. When “delay_tick” is set to true, then the delay handler is called. The delay handler is responsible for monitoring the length of time an effect is running for and for selecting a new effect when the time has expired. The new effects are randomly selected as is the duration. The effect selected would dictate what the pulse timer should be set to i.e. 5Hz, 10Hz or 100Hz. The pulse timer handler, called when the pulse_tick is set to true,  is responsible for the setting of the intensity of the LED via the PWM value and enabling the appropriate LED bank.

Once the firmware was working for the basic set of animations, they were expanded to take advantage of the PWM signal that was not available in my original project. This meant I could introduce LED breathing effects. Table 2. describes the attempts and the signal usage.

FunctionDiscrete component H-BridgeMotor controller
Driving the LEDsThe PWM signal is applied to the enable input of the JK flip flop .Explicitly driving the Input 1 and input 2 using an interrupt timer.
Changing the LED blinking frequencyChange the value of the PWM signal.Change the frequency value of the timer interrupt.
Alter the LED intensityNot supported.Alter the PWM signal to the motor controller.
Table 2. Signal usage between the respective attempts.

Results

All the animation effects created for the original project using the discrete component H-Bridge were able to be implemented using the motor controller. The motor controller variant gave an additional feature of being able to control the intensity of the LEDs. This was not possible with my implementation of the H-Bridge. 

The simple approach to controlling the intensity of the LEDs, although the values were set in a linear fashion, the effect on the eye was not uniform and gave a perceived  bouncing effect. 

Fig 5. Basic PWM effect on the LEDS.

Since the effect of the LEDs did not give the impression of a Sine pattern. An additional experiment was made to convert the PWM values into their sine equivalents in order to provide a more uniform breathing effect. The PWM value was remapped such that 0 -> 255 became 0 -> 90 degrees. To save CPU cycles, the values were calculated out and added as an array of uint8_t in the firmware.

PWMSine Equiv
00
50
100
152
203
255
308
3511
4015
4519
5023
5528
6033
6538
7044
7550
8056
8563
9070
9577
10084
10592
11099
115107
120115
125123
130131
135138
140146
145154
150162
155169
160176
165184
170191
175197
180204
185210
190216
195221
200226
205231
210236
215240
220243
225246
230249
235251
240253
245254
250255
255255
Table 3. PWM Sine Values.
Fig 6. PWM as Sine

CONCLUSION

The overall results of driving the LEDs through a motor controller were consistent with the original attempt with the H-bridge using discrete parts. The advantage seen with using the motor controller was that it was now possible to implement some LED breathing effects where the intensity of the LEDs slowly increased and decreased.

When setting the values of the PWM in a linear fashion, the end result of the breathe effect is not uniform. When the values were converted to follow a sine pattern, there was an improvement but there was a feeling that the effects were still not uniform. Further adjustments to these calculated values would be required to achieve a better result. However, this was not the purpose of this experiment.

REFERENCES

Demonstration of the LED effects (no audio)
  1. LED Chain Driver
  2. Go, go, go! Motor Controller – Contextual Electronics 
  3. TB6593FNG

Leave a comment