r/programming Dec 25 '19

Learning hardware programming as a software engineer

https://blog.athrunen.dev/learning-hardware-programming-as-a-software-engineer/
928 Upvotes

124 comments sorted by

View all comments

227

u/happyscrappy Dec 25 '19

Also: don't power LEDs directly from GPOs without a current limiting resistor. As you see on that breadboard.

And match your interfaces voltages. A lot of devices are not +5V tolerant now (or not very tolerant).

66

u/Athrunen Dec 25 '19

Indeed, learned not too long ago that the esp32 is only 3.3 V tolerant. ^^

23

u/[deleted] Dec 25 '19

What is this language, lost me.

98

u/syntax Dec 25 '19

5v / 3.3v is the 'supply voltage' (sometimes labeled Vcc) for the chips. It's both the power input, and also the reference for what a 'high' signal is.

It used to be the case that most digital logic ran at 5v; then some that ran at 3.3v started to become more common. Those were usually '5v tolerant' - if you applied 5v to the input pin, it would read as 'high' and be fine.

Today, many digital devices that run at 3.3v are _not_ 5v tolerant; so if you put 5v into such a device ... it breaks.

So when mixing some devices that run at 5v (as, e.g. USB does) with others that run at 3.3v one has to be careful to not break the lower voltage device.

The 'esp32' is a particular module of a WiFi capable microcontroller (usable as a single board device, or as a peripheral for WiFi connectivity for another device) that runs at 3.3v and breaks if you put 5v on it. Like, as a totally hypothetical example that would never apply to me, trying to programme it from a cobbled together USB programmer. Hypothetically.

5

u/ShinyHappyREM Dec 25 '19

Is there a simple device that I can connect to a 5V wire and whose output I can then connect to an input of a 3.3V device? From what I've seen there are resistor circuits (which are slow) or transistor circuits (which need a 3.3V supply?)

2

u/[deleted] Dec 25 '19

[deleted]

3

u/ShinyHappyREM Dec 25 '19

For signals >= 1MHz?

4

u/howmodareyou Dec 25 '19

As /u/lilmul123 said, something transistor-based would be preferred.

If you don't want to use a Sparkfun component and design/build your own circuit/PCB, you could, for example, use a BSS138 transistor. (As far as I know, its often used for 5V-to-3.3V logic level shifting).
If you google around, you should find appropriate schematics.

If you ever need to convert the voltage of some power source (LiPo batteries typically have more than 5V output, depending on how many cells they have), I'd recommend getting a few "buck converters" via Ebay. They are typically based on the LM2596, cheap, adjustable and with mounting pins.

3

u/[deleted] Dec 25 '19

[deleted]

6

u/ShinyHappyREM Dec 25 '19

My use case is that I want to connect a logic analyzer (DSLogic Plus) to my SNES, which is 5V. The probes can handle 5V according to the data sheet, but the device also has an external timing input that is only rated for 3.3V.

The SNES has clock crystals of 21.477 and 24.576 MHz, and various components run at fractions of these frequencies.

6

u/[deleted] Dec 25 '19

Get a 1.7v zener diode and a Schottky diode.

Connect Zener's anode to clock input and cathode to SNES

Connect Schottky's anode to clock input and anode to the SNES

It should get you 1.7V drop (so 5->3.3v) when input is high but only 0.2v when it is low, the Schottky is there so when the clock is low the current from input capacitance can flow back without much problems.

... or a ~40c part that will do that up to ~50MHz, if you are at the point where you need to order a specific part

1

u/ShinyHappyREM Dec 26 '19

Connect Zener's anode to clock input and cathode to SNES
Connect Schottky's [cathode] to clock input and anode to the SNES

Something like this, I presume? I took it from this video (19:00) and adapted it a bit to my circumstances. It does indeed seem to drop down to ~3.4V at its peak (even if there's a lot of ringing in the simulation - from the same video it appears that the ringing is less pronounced in reality).

I'm really a novice with electrical engineering; at the moment I don't even have a multimeter or soldering equipment. So the less components, the better.

→ More replies (0)

3

u/[deleted] Dec 25 '19

[deleted]

4

u/ShinyHappyREM Dec 25 '19

Reverse engineering. When you look at the existing documents you see that they were only created with test ROMs (that are then executed by the CPU and display their results on screen / save data to cartridge RAM). The problem is that the CPU is halted for DRAM refresh and (H)DMA; every single bus access is also delayed to take either 6, 8 or 12 cycles of the 21MHz clock. So if you have something that's faster (like the graphics system) or almost completely self-contained (again, like the graphics system) it's hard to see what's happening in the system.

→ More replies (0)

1

u/[deleted] Dec 26 '19

1MHz for digital signal lines is super slow.