Tuesday 11 February 2014

42. Working with the 74193 - 4 bit binary up/down counter.

The 74193 is quite a useful IC to have in your collection.  It can count up or down in binary from 0000 to 1111.  You can reset the value to zero, you can pre-set the start value (useful as a buffer when not used as a counter) and if you count above or below the four bits it can flag a carry or borrow condition. This last bit is quite important as it means you can daisy chain lots of 74193s together to count with 8, 12, 16 bits and so on.

The pins are:

16 Vcc        Input Voltage
 8 GND        Ground

15 A      IN  Input Bit 0
 1 B      IN  Input Bit 1
10 C      IN  Input Bit 2
 9 D      IN  Input Bit 3

11 LOAD   IN  Load Inputs   - Inactive state HIGH.  Go LOW/HIGH to load inputs.

 3 QA     OUT Output Bit 0
 2 QB     OUT Output Bit 1
 6 QC     OUT Output Bit 2
 7 QD     OUT Output Bit 3

14 CLEAR  IN  Reset Outputs - Inactive State LOW.  Go HIGH/LOW to reset.

 4 DOWN   IN  Count Down    - Inactive state HIGH.  Go LOW/HIGH to count down.
 5 UP     IN  Count Up      - Inactive State HIGH.  Go LOW/HIGH to count up.

13 BORROW OUT Count has gone below 0000.  Connect this to DOWN of IC below.
12 CARRY  OUT Count has gone above 1111.  Connect this to UP of IC above.

In this example below I have daisy chained 3x Philips 74HC193Ns together to produce a 12 bit value:



The red jump wires are connected to the UP input. Initially from an Arduino UNO providing a simple pulse with a 100ms delay, then from the CARRY to the UP of the next IC.

A/B/C/D and BORROW are not connected. LOAD and DOWN connected to +5V as I'm not going to load a value and I am not going to count down.

Just to show how this works I connect the outputs to some red LEDs followed by some inline 1K resistors (which are hidden behind the LEDs in the picture).

Using this method, these 3x 74193s create a 12 bit address line which could be used help program or read a 4K by 8 bit EEPROM.



Here's the Arduino code to pulse the 74193:
/*
  74193 Synchronous 4 bit binary up/down counter
*/

int RESET = 2;    // Connect to Pin 14 on the IC
int COUNT_UP = 3; // Connect to Pin  5 on the IC

void setup() {
  
  // Initialise Pins
  pinMode(RESET,OUTPUT);
  pinMode(COUNT_UP,OUTPUT);
  
  // Set default pin states
  digitalWrite(COUNT_UP,HIGH);
  digitalWrite(RESET,LOW);
  
  // Perform a reset.  Clears outputs to low state i.e. 0000
  digitalWrite(RESET,HIGH);
  digitalWrite(RESET,LOW);

}

void loop() {
  
  // Clock Up Pulse
  digitalWrite(COUNT_UP,LOW);
  digitalWrite(COUNT_UP,HIGH);
  delay(100);

}