Go Down

Topic: Uno and HCC4514B assistance (Read 303 times) previous topic - next topic

99Valkyrie

Hello,

Noob here.  I'm trying to use my Uno to test a circuit board that has 4 HCC4514B chips (4 bit latch/4 to 16 decoder) which drive a total of 60 outputs.  Each chip has 4 DATA lines, 1 INHIBIT line, 1 STROBE line and 15 OUTPUT lines.  Each output is individually addressable.  For now I used the blinking led sketch as a basis of addressing the specific chip and hence it's output.  It does what I want it to do but seems inefficient.  Below is a snippet of the modified code (didn't include addressing all output lines and but you get the idea; I know I haven't included how I handle the INHIBIT and STROBE function in this example but I think I have a good handle on how to):

Code: [Select]
int DATA3 = 13;
int DATA2 = 12;
int DATA1 = 11;
int DATA0 = 10;
int INHIBIT3 = 9;
int INHIBIT2 = 8;
int INHIBIT1 = 7;
int INHIBIT0 = 6;
int STROBE = 5;

void setup()
{
pinMode (DATA3, OUTPUT);
pinMode (DATA2, OUTPUT);
pinMode (DATA1, OUTPUT);
pinMode (DATA0, OUTPUT);
pinMode (INHIBIT3, OUTPUT);
pinMode (INHIBIT2, OUTPUT);
pinMode (INHIBIT1, OUTPUT);
pinMode (INHIBIT0, OUTPUT);
pinMode (STROBE, OUTPUT);
}

void loop()
{
  digitalWrite (DATA3, LOW);
  digitalWrite (DATA2, LOW);
  digitalWrite (DATA1, LOW);
  digitalWrite (DATA0, LOW);
  delay(10);
  digitalWrite (DATA3, HIGH);
  digitalWrite (DATA2, LOW);
  digitalWrite (DATA1, LOW);
  digitalWrite (DATA0, LOW);
  delay(10);
  digitalWrite (DATA3, LOW);
  digitalWrite (DATA2, HIGH);
  digitalWrite (DATA1, LOW);
  digitalWrite (DATA0, LOW);
  delay(10);
}


Here's the truth table for the chip:
D3   D2   D1   D0      INH   STR
0   0   0   0      0   1
0   0   0   1      0   1
0   0   1   0      0   1
0   0   1   1      0   1
0   1   0   0      0   1
0   1   0   1      0   1
0   1   1   0      0   1
0   1   1   1      0   1
1   0   0   0      0   1
1   0   0   1      0   1
1   0   1   0      0   1
1   0   1   1      0   1
1   1   0   0      0   1
1   1   0   1      0   1
1   1   1   0      0   1
1   1   1   1      0   1


My basic question is this.  Is there a better way to handle the sequence above without using delay?  I tried to modify the "blink without delay" sketch but could not make it work.  I'm not asking for someone to write the code for what I should do but rather point me to some possible arguments/syntax that would work better or more efficient.  I'm of the old school, "give a man a fish and he eats for a day; teach a man to fish and he eats for a lifetime".  Please help me learn.  Thanks for your time.



PaulS

Quote
Is there a better way to handle the sequence above without using delay?

That would depend on why you are using delay(). If it is just so that you can see that an individual output went HIGH, then I don't see any disadvantage to using delay() in a test sketch.

Quote
I tried to modify the "blink without delay" sketch but could not make it work.

You need to at least supply the rod and reel, or be willing to buy one. What did you try? What went wrong?

99Valkyrie


Quote
Is there a better way to handle the sequence above without using delay?

That would depend on why you are using delay(). If it is just so that you can see that an individual output went HIGH, then I don't see any disadvantage to using delay() in a test sketch.


Yes, the intent was to drive each output high.  It worked as I expected but then thought there may be a more efficient way to get the same result.


Quote
I tried to modify the "blink without delay" sketch but could not make it work.

You need to at least supply the rod and reel, or be willing to buy one. What did you try? What went wrong?


Yes, you are correct (and thanks for the gentle 'kick in the pants").  Thinking ahead for my ultimate goal to be able to bench test the circuit board with 4 HCC4514 chips on it by creating a "menu-based" system whereby I can isolate one or more chips and set their outputs as desired.  I was thinking of using a button (or two) to "select which "test" to run.  During my readings I found that using a delay can be a disadvantage while other things needs to happen, hence trying to find a more efficient way to "blink" or address the inputs (0000 through 1111).  I saw the "Blink without delay" sketch and thought it may serve my purpose.  Here is the code as I modified it (apologies to the folks that wrote/modified it for hacking their work).

Code: [Select]
/* Blink without Delay

Turns on and off a light emitting diode(LED) connected to a digital 
pin, without using the delay() function.  This means that other code
can run at the same time without being interrupted by the LED code.

The circuit:
* LED attached from pin 13 to ground.
* Note: on most Arduinos, there is already an LED on the board
that's attached to pin 13, so no hardware is needed for this example.


created 2005
by David A. Mellis
modified 8 Feb 2010
by Paul Stoffregen

This example code is in the public domain.


http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
*/

// constants won't change. Used here to
// set pin numbers:
const int D3 =  12;      // the number of the LED pin
const int D2 =  11;      // 12-27-12, added this line to send data to D2 on HCC4514 chip
const int D1 =  10;      // 12-27-12, added this line to send data to D1 on HCC4514 chip
const int D0 =  9;       // 12-27-12, added this line to send data to D0 on HCC4514 chip

// Variables will change:
int ledState = LOW;             // ledState used to set the LED
long previousMillis = 0;        // will store last time LED was updated

// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 1000;           // interval at which to blink (milliseconds)

void setup() {
  // set the digital pin as output:
  pinMode(D3, OUTPUT);
  pinMode(D2, OUTPUT);
  pinMode(D1, OUTPUT);
  pinMode(D0, OUTPUT); 
}

void loop()
{
  // here is where you'd put code that needs to be running all the time.

  // check to see if it's time to blink the LED; that is, if the
  // difference between the current time and last time you blinked
  // the LED is bigger than the interval at which you want to
  // blink the LED.
  unsigned long currentMillis = millis();

  if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;   

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;

    // set the LED with the ledState of the variable:
    digitalWrite(D3, ledState);
    digitalWrite(D2, ledState);
    digitalWrite(D1, ledState);
    digitalWrite(D0, ledState);   
  }
}


The outputs I get are 0000, 0001, 0011, 0111 and 1000.  Not what I expected.  I expected all outputs to be driven high as the program ran eventually ending with 1111.  I suspect that the outputs are being generated so fast that the chip cannot keep up.  I need to confirm that with my logic analyzer.

For now, I can get the outputs to blink using delay and I may stick with that.  I did run across another method that sounded intriguing that I'm going to look into further.  It is using rows and columns addressing scheme.  It may not be what I need but sounds like it could be interesting to learn.

Again, many thanks for your time.

PaulS

Quote
The outputs I get are 0000, 0001, 0011, 0111 and 1000.

I don't understand what you mean by this. With the code you posted, since you set the state of all 4 pins to the same state, I don't see how you get anything other than 0000 and 1111.

99Valkyrie


Quote
The outputs I get are 0000, 0001, 0011, 0111 and 1000.

I don't understand what you mean by this. With the code you posted, since you set the state of all 4 pins to the same state, I don't see how you get anything other than 0000 and 1111.


Forgive me, I did not make clear what I am doing.  You are correct, the Uno is supplying 0000 and 1111.  I take the output of the Uno and drive the HCC4514's 4 DATA lines.  The HCC4514 acts as a latch so as it sees the 4 DATA lines change it stores the result and sends that result to its output, hence the 0000, 0001, 0011, 0111 and 1000.  I should have made clear those came from the HCC4514 and not the Uno.

What I thought would happen is that using the output from the Uno would cause the HCC4514 to "count up".  I thought I was on the right track as the resultant output does count up, albeit incorrectly.  Currently I'm leaving the STROBE on the HCC4514 as HIGH so the chip latches whatever input it sees.  The goal is to get the HC4514 to have its output (S0 through S15) count up from 0000 to 1111.

I'm going to try to further modify the "Blink without Delay" code above to add sections for each pin in the hopes that if the Uno outputs are "counting" then the HCC4514 should respond accordingly and latch more output choices.  As you said earlier, my first attempt using the "Blink with Delay" code works just fine the way it is.  Perhaps I should count that as progress and move on.  However, I want to clearly understand what is happening here before I move on to more difficult things.  I don't want to just regurgitate other people's code, I want to know and understand why things react the way they do.

Again, thank you for your time.

Go Up