Geek went Freak!

# Using 74HCxx with 3.3v

Atmega processors in Arduino boards are powered by 5V power supplies. It makes it easier to work with other ICs that accept 5v Vcc.

But most recent processors including ARM cortex-M operate at 3.3v Vcc. Would the tried and tested 74HCxx series work with 3.3v Vcc? Or should we pick a different low voltage logic series.

The answers, as usual, are in the data sheets.

The characteristics we are interested in are:

1. Allowed Vcc range
2. Vih, input voltage high threshold
3. Vil, input voltage low threshold

## Allowed Vcc range

The data sheet says, allowed Vcc range is -0.5v to 7v. That is great! So, 74HCxx series can be powered from 3.3v.

## Input thresholds at 5v

First lets look at Vih and Vil at 5v Vcc.

1. Vih: 3.5v
2. Vil: 1.5v

## Input thresholds at 3.3v

1. Vih: 2.31
2. Vil: 0.99

That is great! This would work perfectly.

# Introduction

Trimpot or preset resistor is a variable resistor whose resistance can be adjusted using a screw driver.

# Trimpot vs potentiometer

Trimpots are not meant to be tinkered with very often. This is the difference that sets it apart from potentiometers. Although both of them do the same thing, potentiometers offer more change cycles.

# Pinout

Trimpots have three terminals:

1. In1 ( A )
2. In2 ( B )
3. Out or Wiper ( C )
Trimpot pinout

Terminals A and B are the two ends of the voltage divider. Terminal C is the output where the voltage is divided.

Trimpot pinout schematic

# Circuit symbol

Trimpot schematic

# Connection

Lets build a small circuit to control the brightness of the LED with the help of a trim pot.

Trimpot schematic

# Introduction

74244 is a non-inverting octal buffer. Its output can be disabled in groups of four if they are not being used.

## Stats

Lines #: 8
Groups #: 2
Output type: CMOS push-pull
Tristate-able: Yes
ESD protection: Yes
Propagation delay @ 5V: 11ns

Vcc

1. Min: 4.5V
2. Max: 5.5V

Vih @ 5V

1. Typical: 1.6V
2. Minimum: 2.0V Io Max.: 35mA

## Special features

An unique feature about 74HCT245 that is not present in other similar buffers is that, the 8 lines can be split into two buses with up to 4 lines in each bus. The groups are:

1. Group1: 1A0, 1A1, 1A2, 1A3
2. Group2: 1A0, 2A1, 2A2, 2A3

Each of the groups can be separately tristate-ed using respective output enable lines. Thats right, each of these groups have their own output enable lines unlike other similar octal buffer ICs.

# Application

## Buffer

74HCT245 can output a maximum current of 35mA. This can be used to drive heavier loads that microcontroller i/o pins cannot drive directly.

## 3.3V -> 5V Level shifter

Typical Vih for 74HCT244 is 2V which is way below 3.3V. 74HCT244 can be used as 3.3V -> 5V level shifter. 74HCT244 is better than 74HC244 in 3.3V to 5V level shifting because 74HCT series is compatible with TTL logic rather than CMOS logic.

## 5V -> 3.3V level shifter

Maximum input voltage for 74HCT245 cannot be greater than Vcc according to the specification.

But it can be tricked into accepting voltages greater than Vcc. 74HCT245 has ESD protection diodes on input pins. These diodes come into play when input voltage is greater than Vcc. These clamping diodes can take maximum current of 20mA. This means that a current limiting resister can be used to keep the current below 20mA at 5V. Current limiting resistor of 500ohms would work.

The problem with this trick is, it increases the propagation delay. It is fairly useful for low speed circuits. The lower the resistor the better.

For high speed circuits, use 74ACT244, 74ACT245, 74HCT244, 74HCT245.

# Buffers: 74244 vs 74245

74244 is an octal unidirectional buffer. The 8 lines can be split into two groups and each group can be individually disabled.

74245 is an octal bidirectional buffer. The direction of all the lines are controlled using the same line, DIR.

Bidirectional bus can be built using 74244 by

1. Complementing the output enable lines
2. Connecting outputs and inputs together
Bidirectional bus using 74244

But this only gives 4 bidirectional lines. If bidirectional lines are required, it is better to use 74245.

# Introduction

74244 is a non-inverting octal buffer. Its output can be disabled in groups of four if they are not being used.

## Stats

Lines #: 8
Groups #: 2
Output type: CMOS push-pull
Tristate-able: Yes
ESD protection: Yes
Propagation delay @ 5V: 9ns

Vcc

1. Min: 2V
2. Max: 6V

Vih @ 5V

1. Typical: 2.65
2. Minimum: 3.5 Io Max.: 35mA

## Special features

An unique feature about 74HC244 that is not present in other similar buffers is that, the 8 lines can be split into two buses with up to 4 lines in each bus. The groups are:

1. Group1: 1A0, 1A1, 1A2, 1A3
2. Group2: 1A0, 2A1, 2A2, 2A3

Each of the groups can be separately tristate-ed using respective output enable lines. Thats right, each of these groups have their own output enable lines unlike other similar octal buffer ICs.

# Application

## Buffer

74HC244 can output a maximum current of 35mA. This can be used to drive heavier loads that microcontroller i/o pins cannot drive directly.

## 3.3V -> 5V Level shifter

NOTE: Although this might work at room temperatures, this is not recommended. Use 74HCT244, 74HCT245, 74ACT244, 74ACT245.

Typical Vih for 74HC244 at room temperature is 2.65V which is way below 3.3V. 74HC244 can be used as 3.3V -> 5V level shifter.

But important thing to note is, the minimum guaranteed worst case Vih is 3.5V. A 3.3V device will never be able to reach this level. So using 74HC244 as 3.3V to 5V level shifter is very bad idea.

## 5V -> 3.3V level shifter

Maximum input voltage for 74HC244 cannot be greater than Vcc according to the specification.

But it can be tricked into accepting voltages greater than Vcc. 74HC244 has ESD protection diodes on input pins. These diodes come into play when input voltage is greater than Vcc. These clamping diodes can take maximum current of 20mA. This means that a current limiting resister can be used to keep the current below 20mA at 5V. Current limiting resistor of 500ohms would work.

The problem with this trick is, it increases the propagation delay. It is fairly useful for low speed circuits. The lower the resistor the better.

For high speed circuits, use 74ACT244, 74ACT245, 74HCT244, 74HCT245.

# Introduction

74245 is a non-inverting bidirectional octal buffer.

## Stats

Lines #: 8
Output type: CMOS push-pull
Tristate-able: Yes
ESD protection: Yes
Propagation delay @ 5V: 10ns

Vcc

1. Min: 2V
2. Max: 6V

Vih @ 5V

1. Typical: 2.65
2. Minimum: 3.5 Io Max.: 35mA

## Special features

74245 is a bidirectional buffer. The direction of all the lines together can be controlled using the direction pin, DIR.

# Application

## 3.3V -> 5V Level shifter

NOTE: Although this might work at room temperatures, this is not recommended. Use 74HCT244, 74HCT245, 74ACT244, 74ACT245.

Typical Vih for 74HC245 at room temperature is 2.65V which is way below 3.3V. 74HC245 can be used as 3.3V -> 5V level shifter.

But important thing to note is, the minimum guaranteed worst case Vih is 3.5V. A 3.3V device will never be able to reach this level. So using 74HC245 as 3.3V to 5V level shifter is very bad idea.

## 5V -> 3.3V level shifter

Maximum input voltage for 74HC245 cannot be greater than Vcc according to the specification.

But it can be tricked into accepting voltages greater than Vcc. 74HC245 has ESD protection diodes on input pins. These diodes come into play when input voltage is greater than Vcc. These clamping diodes can take maximum current of 20mA. This means that a current limiting resister can be used to keep the current below 20mA at 5V. Current limiting resistor of 500ohms would work.

The problem with this trick is, it increases the propagation delay. It is fairly useful for low speed circuits. The lower the resistor the better.

For high speed circuits, use 74ACT244, 74ACT245, 74HCT244, 74HCT245.

# 74XX164

74XX164 is a serial-in parallel-out shift register.

Unlike 74XX594 and 74XX595, it doesn’t have a front-end with latch or flip-flop.

74HC164 block diagram

## Clock input

CP pin is used as clock to the shift registers. The data is shifted on the positive edge of clock signal.

## Output enable

74XX164 doesn’t have an output enable pin. However, master reset (MR) pin can be used to clear all shift registers and drive all outputs low.

## Master reset

A low on the MR pin clears all the registers and all the outputs are driven low.

Q7 of first 74XX164 can be connected to the serial input of the second 74XX164 to cascade them into 16-bit serial register.

# Golang: Channel send behavior

General way to send data to a channel in golang is

lChan := make(chan bool)
lChan <- true


It is important to understand that, golang channels block on send until there is either

1. Space left to buffer the data
2. Until the data is read from the channel, if there is no buffer space left

# Non-buffered channels (default)

This means that, if there is no one reading the data from the channel, the code blocks.

Here is an example:

When the program is run, golang automatically detects the deadlock during runtime and report it:

Note: When buffer size is 0, the channel blocks until the data is read from the channel. This was the behavior witnessed in first example.

This fate can be postponed by increasing the buffer size of the channel. By default, the buffer size is 0.

# Buffered channels

Optional second argument to make function takes length of channel buffer as input and returns a new channel with the requested buffer size. It is not possible to change the size of the channel buffer after it is created.

package main

import (
"fmt"
)

func main() {
lChan := make(chan bool, 5)
lChan <- true

fmt.Println("Finished!")
}


This program doesn’t block. But eventually it will when the buffer is filled up. Consider this example where buffer length is 5, we are trying to send 10 values to the channel but only reading 3. This should deadlock when we try to send 9th value.

When the program is run, golang automatically detects the deadlock during runtime and report it:

And it does!

# Nonblocking send

One can use non-blocking send using the select statement. select statement is generally used to simultaneously send/receive to/from multiple channels.

When select has a default clause, the select statement will not block during send/receive.

Output:

# Nonblocking send with timeout

Nonblocking sends are great. But won’t be nicer if we waited a bit before giving up? time package has a function called After. This function takes Duration as time.Duration type and returns a bool channel that is sent a message after the duration expires. After function can be used in select statement, achieve timeout functionality.

Output:

# Zener diode voltage regulator

Zener diode has a very useful property of dropping a constant voltage (equal to its Zener voltage) across its terminals when it is reverse biased at voltages above its Zener voltage.

Constant Voltage drop
Constant Voltage drop plot

The voltage across the zener diode follows the source V1 until it reaches 8.2V (Zener voltage). Any further increase of source voltage doesn’t change voltage across the Zener diode.

Until the Zener voltage is reached, the Zener diode is open, so there is no current flowing through the circuit. After Zener voltage is reached, the current is,

$$tex I_{R1} = \frac{V_{V1} - V_{ZV}}{R_{R1}} tex$$

This property can be used to build voltage regulators. Voltage regulators are used when the input voltage is higher than the required voltage. But placing the Zener diode across the load, a constant required voltage can be dropped across the load if the input voltage is above this desired voltage.

Zener diodes with various Zener voltage are available in the market. Lets consider a case where we have 24V input voltage and have circuit that operates at 8.2V.

We have chosen the Zener diode BZX84C8V2L which has required Zener voltage of 8.2V.

Voltage regulator

The resistor Rs has two uses

1. To limit current flowing through the Zener diode when Vin is greater than Zener voltage. This sets the minimum limit on the Resistor Rs.
2. It should drop as less voltage as possible so that most of Vin is dropped across the load (Rl) when Vin < Zener voltage. This sets the maximum limit on the resistor Rs.

# GCC: -fprofile-arcs va -ftest-coverage

Two flags we use in gcc to enable code coverage are -fprofile-arcs and -ftest-coverage.

So, what exactly do these flags do?

## Block graph and source location information

-ftest-coverage generates .gcno files for corresponding translation units during compile time. These files have information regarding block graphs and their associated line numbers in platform independent format.

## Profile statistics and counts

Code coverage is performed by instrumenting code into the target source code. This instrumented code then keeps track of statistics and counts of number of times a statement or a block has executed.

Functions in libgcov.a are responsible for recording these statistics information to .gcda file after execution.

The flag -fprofile-arcs links libgcov.a library into the executable.

## Making sense of the information

Thus, during compile time -ftest-coverage generates .gcno and after runtime, -fprofile-arcs generates .gcda. gcov command uses these two files to link statistics in .gcda to block graph and source association information in .gcno.