Vary Voltage/Current of Shift Register Outputs?

Our range of tiny modules are designed to make it easy for you to quickly add functionality to your projects. [Module List]
Julia*5
Posts: 7
Joined: Thu Jun 13, 2013 5:15 am

Vary Voltage/Current of Shift Register Outputs?

Post by Julia*5 » Thu Jun 13, 2013 5:36 am

Hi,

I recently bought the shift register expansion module and have been playing around lighting up LED's in different sequences with my Eleven and all is great. Specifically though, I want to be able to power several different circuits from the shift register as well as adjust the voltage/current sent to these circuits as specified in code. Is this possible? Was thinking of somehow using a digital potentiometer to vary the voltage/current?

I am quite new to all of this and so any help is very appreciated.

angusgr
Freetronics Staff
Freetronics Staff
Posts: 853
Joined: Tue Apr 09, 2013 11:19 pm
Location: Melbourne, Australia
Contact:

Re: Vary Voltage/Current of Shift Register Outputs?

Post by angusgr » Thu Jun 13, 2013 10:42 pm

Hi Julia,

Good to hear you're exploring the possibilities with shift registers.

While it is possible to fade LEDs in and out by varying voltage/current, the easiest way is to use PWM. This is what the Arduino "analogWrite" functions do if you use them to dim an LED.

You can do PWM through a shift register. It involves sending the same on/off data to the shift register that you're sending now, just at a very high speed. There are some Arduino libraries to help with PWMing through shift registers, one is ShiftPWM: http://www.elcojacobs.com/shiftpwm/

Please let us know how you get on.

- Angus

Julia*5
Posts: 7
Joined: Thu Jun 13, 2013 5:15 am

Re: Vary Voltage/Current of Shift Register Outputs?

Post by Julia*5 » Sat Jun 15, 2013 3:06 am

Hi Angus,

Thanks for your reply, was very helpful. I was looking into using PWM, but I wasn't sure if it would work for my situation. I have some heating elements on a few of my circuits that the shift register is outputting to. Probably a stupid question but if I use PWM, which I know pulses between values for a certain duty cycle which gives the illusion of dimming LEDs, would it be able to supply an actual increase or decrease in voltage to heat or cool the heating elements? I saw something about using a filter to average out a PWM signal? Or is that a little to overboard?

Thanks again,
Julia

angusgr
Freetronics Staff
Freetronics Staff
Posts: 853
Joined: Tue Apr 09, 2013 11:19 pm
Location: Melbourne, Australia
Contact:

Re: Vary Voltage/Current of Shift Register Outputs?

Post by angusgr » Mon Jun 17, 2013 10:03 pm

Hi Julia,

Definitely not a stupid question!

PWM is also very often used for heater controls, it can be very suitable for that application - just by switching it on and off at high speed you can vary the total amount of power drawn (ie heat produced) over time. However you need to be sure your heating element (and whatever else is driving it) can be switched on and off very fast without a problem.)

If you do some web searches for "pwm heating element" then you'll probably get some inspiration. Otherwise if you can give some more details of how the shift register is wired to the heating elements, and what kind of elements they are, then we can probably help.

- Angus

Julia*5
Posts: 7
Joined: Thu Jun 13, 2013 5:15 am

Re: Vary Voltage/Current of Shift Register Outputs?

Post by Julia*5 » Thu Jun 20, 2013 1:51 am

Hi Angus,

Again as this is my first time using a microcontroller board and stuff, I not too sure about hardware but I was thinking of using Nichrome or Copper wire as the heating elements connected to the shift register like the LED's used in most shift register examples/tutorials. Is this ok? I kind of have a sneaking suspicion though after talking with you, that there is a lot more involved that I should be aware of....

Also thanks for the link to the ShiftPWM library. Downloaded it and I think I have a code which varies the voltages of certain LED's in a specific pattern that is close to working!

angusgr
Freetronics Staff
Freetronics Staff
Posts: 853
Joined: Tue Apr 09, 2013 11:19 pm
Location: Melbourne, Australia
Contact:

Re: Vary Voltage/Current of Shift Register Outputs?

Post by angusgr » Fri Jun 21, 2013 1:33 am

Julia*5 wrote: Again as this is my first time using a microcontroller board and stuff, I not too sure about hardware but I was thinking of using Nichrome or Copper wire as the heating elements connected to the shift register like the LED's used in most shift register examples/tutorials. Is this ok? I kind of have a sneaking suspicion though after talking with you, that there is a lot more involved that I should be aware of....
The key is how much heat you need to produce. The shift register chip will have limits on the voltage and current it can provide, which limits the amount of heat you can produce.

Generating larger amounts of heat will require you to possibly add some more devices like Field Effect Transistors (FETs) to switch the high voltage and current to the heater elements on and off. The shift register output can be connected to the gate of the FET, and then the FET acts like an electronic switch to turn the heater current on and off. If you do some web searches you can hopefully find some examples of using FETs with Arduinos or shift registers to explain.
Julia*5 wrote:Also thanks for the link to the ShiftPWM library. Downloaded it and I think I have a code which varies the voltages of certain LED's in a specific pattern that is close to working!
Excellent news! :)

- Angus

Julia*5
Posts: 7
Joined: Thu Jun 13, 2013 5:15 am

Re: Vary Voltage/Current of Shift Register Outputs?

Post by Julia*5 » Mon Jul 01, 2013 12:42 am

Hey Angus,

Thanks for the heads up. Had a look online and found that the maximum output voltage from the 74HC595 can be as high as 7V which I think will do me at the moment. If I need any more output, will definitely have a look at FETs.

Was just wondering if you could help on one last thing? I have this code, and I think it should be sending specified duty cycles/brightness to specific LEDs. To me it looks ok, and it actually does cycle through the LEDs, but for some reason it doesn't vary the duty cycle/brightness? I was wondering if you can see where I am going wrong? I can do what I want without the for loops, but it involves a lot more lines of code - which I am trying to avoid.

Thanks in advance. :)

const int ShiftPWM_latchPin = 8;
#define SHIFTPWM_NOSPI
const int ShiftPWM_dataPin = 11;
const int ShiftPWM_clockPin = 13;
const bool ShiftPWM_invertOutputs = false;
const bool ShiftPWM_balanceLoad = false;
#include <ShiftPWM.h>
unsigned char maxVoltage = 255;
unsigned char pwmFrequency = 75;
int numRegisters = 1;

int currentValue[] = {0, 1, 2, 3, 4, 5, 6, 7};
int ledcount = 8;
int brightness[] = {76, 102, 127, 153, 178, 204, 229, 255};
int voltagecount = 8;

void setup() {
//pinMode(dataPin, OUTPUT);
//pinMode(latchPin, OUTPUT);
//pinMode(clockPin, OUTPUT);
ShiftPWM.SetAmountOfRegisters(numRegisters);
ShiftPWM.Start(pwmFrequency,maxVoltage);
}

void loop() {
for (int Led = 0; Led < ledcount; Led++) {
ShiftPWM.SetAll(0);
for(int Voltage = 0; Voltage < voltagecount; Voltage++){
ShiftPWM.SetOne(currentValue[Led], brightness[Voltage]);
}
delay(500);
}
}

angusgr
Freetronics Staff
Freetronics Staff
Posts: 853
Joined: Tue Apr 09, 2013 11:19 pm
Location: Melbourne, Australia
Contact:

Re: Vary Voltage/Current of Shift Register Outputs?

Post by angusgr » Mon Jul 01, 2013 10:52 pm

Hi Julia,

Glad it's coming along nicely for you. A useful debugging technique is to walk yourself through what each line of code in your program does, thinking about the state of the program at each line:

(I've also indented inside each set of curly braces {}, which makes it easier to see what goes with what.)

Code: Select all

for (int Led = 0; Led < ledcount; Led++) {
  ShiftPWM.SetAll(0);
  for(int Voltage = 0; Voltage < voltagecount; Voltage++){
    ShiftPWM.SetOne(currentValue[Led], brightness[Voltage]);
  }
}
- First 'Led' is set to 0 (first for loop)
- Then set all outputs off (ShiftPWM.SetAll())
- Then 'Voltage' is set to 0 (second for loop)
- Then set LED #0 ('Led') to brightness #0 ('Voltage')
- Then 'Voltage' is set to 1 (second for loop again)
- Then set LED #0 ('Led') to brightness #1 ('Voltage')
- Then 'Voltage' is set to 2 (second for loop again)
- Then set LED #0 ('Led') to brightness #2 ('Voltage')
... and so on until Voltage is 8

- Then 'Led' is set to 1 (back to the first for loop)
- Then set all outputs off (ShiftPWM.SetAll())
- Then 'Voltage' is set to 0 (second for loop)
- Then set LED #1 ('Led') to brightness #0 ('Voltage')
... and so on.

Does walking through it line by line like this help you see the problem? Let me know if you're still stuck.

- Angus

Julia*5
Posts: 7
Joined: Thu Jun 13, 2013 5:15 am

Re: Vary Voltage/Current of Shift Register Outputs?

Post by Julia*5 » Fri Jul 05, 2013 11:05 pm

Hey Angus,

Yes I can totally see my mistake! Have now replaced that offending line with:

ShiftPWM.SetOne(currentValue[Led], brightness[Led]);
delay(500);

and it works superbly! Thank you so much for all your help.

Julia

Julia*5
Posts: 7
Joined: Thu Jun 13, 2013 5:15 am

Re: Vary Voltage/Current of Shift Register Outputs?

Post by Julia*5 » Mon Dec 02, 2013 3:24 am

Hi,

It's been a long time coming, but I am now trying to use mosfets combined with the shift register for the heating elements (nichrome), but testing with some leds first. I encounter a problem though.

The shift register circuit is the same as the schematic here: http://www.appelsiini.net/2012/driving- ... -registers.

I have connected the outputs of the register to the gates of the mosfets, with the drains to the leds and the sources to ground like everyone says, but nothing happens. I then tested the shift register and mosfets independently of each other and they work fine turning on the leds, yet when I combine the two together, it doesn't work.

I am using a TPIC6B595 register and P16NF06 mosfets. If anyone has any insight, it would be greatly appreciated, as it seems simple enough yet I've looked online and cannot find a solution.

Thanks in advance.

Post Reply