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]
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 » Wed Dec 04, 2013 5:48 am

Hi Julia,

I think that particular shift register may not be able to directly drive the gates of the MOSFETs without additional components.

The description page for the TPIC6B595 says the outputs are "low-side, open-drain DMOS transistors". This means that unlike more common registers like the 74HC595, each shift register output on the TPIC6B595 doesn't drive both high (~5V) and low (0V) depending on the state. What happens instead is that turning on the output actually turns on a small transistor internally - so the output goes from being not connected to anything to being connected to ground through the transistor. This is the so-called "low-side" switching, and it's the same as the FETs you are using.

One option would be to keep using this low-side shift register, and just add some pullup resistors to the outputs so they go to 5V when the shift register output is off (when it's turned on, the low side switch will turn on and pull them back down to 0V.)

However, instead you might want to consider just buying some 74HC595 compatible shift registers that can drive both high and low (our EXPAND module is one such.)

- 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 Dec 09, 2013 2:46 am

Hi Angus,

Thanks for your help, I m back on the 74HC495 module.

I have a another, different question however....so to receive some information about the performance of the heating elements I brought a CD4021BE shift register which would apparently be able to handle several sensors (I was thinking one for each heating element). My code for this register is going off the shiftIn example 1.3 from http://arduino.cc/en/Tutorial/ShftIn13. But I keep getting this error "invalid types 'byte[int]' for array subscript" on line "CD4021BEValue = shiftIn(dataPin, clockPin);" I know this error arises when you define an integer and then call it as an array but when I change it to an array like this - CD4021BEValue = [] - it still comes up with the same error. I don't know what's going on, considering that it is written like this in the example code. Below is a rough draft of my code. Thanks in advance.

Code: Select all

const int ShiftPWM_latchPin = 12;
const int potPin = A0;
const int ShiftPWM_outputenablePin = 3;
const int sensor1Pin = A1;
int latchPin = 8;
int dataPin = 9;
int clockPin = 7;

int potValue = 0; //variable to store the value coming from the pot.
int shiftValue = 0; //value output to the 74hc595 shift register (analog out).
int sensor1Value = 0; //variable to store the value read from the force sensor.
int shiftValue2 = 0; //value output to the shift register from force sensor (analog out)
byte CD4021BEValue = 72; //variable to hold the data for CD4021be shift register (analog in).

#define SHIFTPWM_NOSPI
const int ShiftPWM_dataPin = 11;
const int ShiftPWM_clockPin = 13;
const bool ShiftPWM_invertOutputs = true; //If your LED's turn on if the pin is low, set this to true, otherwise set it to 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[] = {255, 230, 200, 170, 120, 80, 50, 10}; // 7% pressure gradient 
//define an array that corresponds to values for each 
//of the shift register's pins

void setup() {
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT); 
  pinMode(dataPin, INPUT);
  ShiftPWM.SetAmountOfRegisters(numRegisters); // Sets the number of 8-bit registers that are used.
  ShiftPWM.Start(pwmFrequency, maxVoltage);
  Serial.begin(9600);
}

void loop() {
  ShiftPWM.SetAll(0);
  
  potValue = analogRead(potPin); //read the analog value from the pot
  shiftValue = map(potValue, 0, 1023, 0, 255); //map it to the range of analog out. See page 120 of dummies book.
  analogWrite(ShiftPWM_outputenablePin, shiftValue);
  delay(2);
  
  digitalWrite(latchPin,1);
  delayMicroseconds(20);
  digitalWrite(latchPin,0);
  CD4021BEValue = shiftIn(dataPin, clockPin); //while the shift register is in serial mode collect each shift register into a byte the register attached to the chip comes in first.  
  
  for (int n=0; n<=7; n++){ //This for-loop steps through the byte bit by bit which holds the shift register data and if it was high (1) then it prints the corresponding location in the array
    //so, when n is 3, it compares the bits in switchVar1 and the binary number 00001000 which will only return true if there is a 1 in that bit (ie that pin) from the shift register.
    if (CD4021BEValue & (1 << n) ){     
       Serial.print("Force: ");
       Serial.println(CD4021BEValue[n], DEC);
           for (int Led = 0; Led < 7; Led++) {
                ShiftPWM.SetOne(currentValue[Led], brightness[Led + CD4021BEValue[n]]);
                delay(500);
                ShiftPWM.SetOne(currentValue[Led], 0);
   }
                //ShiftPWM.SetOne(currentValue[n], shiftarray[n]);
                //delay(3000);
                //ShiftPWM.SetOne(currentValue[n], 0);  
  }
   else {
    for (int Led = 0; Led < ledcount; Led++) {
      ShiftPWM.SetOne(currentValue[Led], brightness[Led]);
      delay(500);
      ShiftPWM.SetOne(currentValue[Led], 0);
   }
  }
 }
}

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 » Wed Dec 11, 2013 10:25 pm

Hi Julia,

I think the error is probably on this line:

Code: Select all

Serial.println(CD4021BEValue[n], DEC);
And this is because CD4021BEValue isn't an array, it's just a number (a single byte) where we're looking at each individual bit in the byte and using those as individual values from the shift register (1 or 0).

That print line is inside this test:

Code: Select all

if (CD4021BEValue & (1 << n) ){     
Which means we know that bit number N is set in CD4021BEValue, so I think all you need to print here is the number of the bit (you already know that it's value is set), ie

Code: Select all

Serial.println(n, DEC);
Hope this helps,

Angus

LukeW
Posts: 91
Joined: Tue Nov 01, 2011 10:14 am

Re: Vary Voltage/Current of Shift Register Outputs?

Post by LukeW » Sun Feb 23, 2014 2:05 pm

Can you post a drawing or schematic of what you've set up?

Post Reply