View All Posts
read
Want to keep up to date with the latest posts and videos? Subscribe to the newsletter
HELP SUPPORT MY WORK: If you're feeling flush then please stop by Patreon Or you can make a one off donation via ko-fi

Hey there! If you're around my age, you'll probably get nostalgic over the sound of old school tape loading on the ZX Spectrum. I took a deep dive into how the data loads, using my oscilloscope to break it all down, and even built a circuit to handle the signal for my ESP32. Throw in some cool simulations using CircuitLab, and I'm all set! Plus, I discovered a neat trick using diodes to perfect the signal. Hands-on and really quite fun!

Related Content
Transcript

[0:00] Now, if you are similar age to me, these sounds will be very familiar.
[0:27] It certainly takes me back to my childhood.
[0:30] I particularly remember the change in tone when it switches
[0:33] from loading the bytes of the image to individual pixels to the color information.
[0:37] So what are we up to?
[0:39] And obviously PCBWay, channel sponsor.
[0:42] This uh this nice full the color PCB
[0:45] came from them and a link into description, check them out.
[0:49] I’ve used them for my PCBs and uh
[0:51] so far they’ve been great.
[0:53] So what are we doing?
[0:55] I thought it might be fun to take a step back in time and have
[0:58] a look at old school tape loading on my spectrum board.
[1:02] So the ZX Spectrum tap loading is pretty interesting
[1:05] so if I switch over to the oscilloscope, let’s um that’s have a look at what’s actually coming in
[1:11] on the signals.
[1:13] So I think channel two channel
[1:16] one, even, is connected directly to the audio jack of my Mac.
[1:21] So let’s just get that in screen.
[1:24] So what we start off with when we’re loading a tape
[1:28] is a bunch of um what they call pilot tones.
[1:31] So these are alternating high and low signals that
[1:34] are 2168 CPU
[1:38] cycles, which are just under 620 microconds.
[1:42] So in total each tone should be 1.2
[1:45] milliseconds long, and then we have the data bit and
[1:50] a zero bit takes just under 489 microconds
[1:54] and a one takes 977 microconds.
[1:58] So on average, we have an amazing bit rate
[2:01] of 1,364 or around
[2:05] 170 bytes per second, so loading a 48K
[2:09] game takes just under five minutes.
[2:12] and that’s enough time for a cup of tea.
[2:14] Now actually finding a cassette player is pretty hard, so I
[2:17] am just using my laptop and I’ve got a headphone jack connected up to a breakout board.
[2:22] So we’ve seen the signal and one
[2:25] of the issues is if we run this again, it’s is quite loud, but let’s run it again
[2:30] what you can see is the signal goes positive and negative.
[2:33] Now that’s kind of fine if we were using a
[2:36] standard A2D converter, but we’re feeding this straight into our ESP32.
[2:41] And it can’t really handle negative voltages.
[2:44] So what we need to do is um
[2:46] shift up the signal so we can actually feed it directly
[2:49] in to the ESP32 ADC.
[2:52] So let’s build a circuit to do that.
[2:58] So I’ve jumped into CircuitLab.
[3:01] This is becoming my my new favorite way of simulating circuits.
[3:04] It’s really easy to use.
[3:06] I used to use KiCad and spice, but
[3:08] to be honest, I cannot remember how to make it work, so I found
[3:11] this tool and it’s quite a bit easier.
[3:14] So what do we need to do?
[3:16] Well let’s have an input signal?
[3:18] say we’ll get one of these um
[3:20] voltage sources.
[3:22] This will give us a one volt amplitude sine
[3:24] wave at one kiloherse, so that will do for that.
[3:27] Then of course we need our power supply.
[3:30] So we’ve got 3.3 volts.
[3:34] So the easiest way to shift this signal up is to use a resist divider.
[3:39] So we’ll just have a let’s use a one K resistor
[3:42] so that’s the top one and here’s our bottom resisted
[3:45] divider and we’ll connect that up to our
[3:49] voltage and plus sides, so that’ be 3.3 volts at the top.
[3:53] Don’t that down, of course we need a ground at the bottom.
[3:57] So let’s hook that up.
[3:59] So here we should get half a 3.3 volts
[4:01] so around 1.65 volts I think.
[4:05] So let’s connect the bottom of this to ground now
[4:08] the bottom of this to ground and anything we need now is
[4:11] a DC blocking capacitor, so stick a capacitor in here.
[4:16] We connect that to the middle of the voltage divider and
[4:20] this end to our voltage source.
[4:23] so let’s uh let’s simulate this and see what it does.
[4:27] So what we can do is we can do a time domain simulation.
[4:31] Oops, what we need to do is add some expressions.
[4:34] So
[4:36] let’s do that so we need some node names.
[4:38] So we’ve got our input voltage and
[4:42] we’ve got our output voltage.
[4:45] So let’s run that now.
[4:48] So
[4:50] time domain analysis, so we want to do
[4:52] voltage on the input and we want voltage on the output.
[4:57] So I’m just going to start from point
[5:00] one second so that we’ve got time for the second to stabilize.
[5:03] We’ll run for 10 milliseconds and our time step.
[5:07] What’s this going to be d
[5:09] That’s like a ten microconds, I think, so that’s rather than that.
[5:14] So there we go.
[5:16] What have we got?
[5:17] On our input, we have our input signal, which is um
[5:20] around zero volts.
[5:22] It goes up to one volt down to minus one volt and here’s our output signal.
[5:26] So this is perfect.
[5:28] We go up to two point around
[5:31] 2.6 volts and down to
[5:34] around 700 mill volts and we’re oscillating
[5:38] around 1.65 volts.
[5:40] So that’s perfect.
[5:42] Actually, what have we got?
[5:43] 1. point 1.6 volts.
[5:46] That’s close enough.
[5:48] So that’s great.
[5:49] We’ve shifted our signal up into the range that the ESP32 can accept.
[5:53] what happens if we we get a bit crazy, we
[5:56] turn our amplifier up to number 11 and feed in a really high voltage.
[6:01] So let’s run that simulation.
[6:04] And now we’ve got a bit of a problem.
[6:06] So our input signal is fine.
[6:08] It’s doing what we asked to do.
[6:10] It’s from - 11
[6:11] up to 11, but our output signal is now
[6:14] going up to around 12 volts and down
[6:17] to minus eight volts so it’s highly likely
[6:21] this would really damage our ESP32 inputs.
[6:24] So let’s deal with the negative signal.
[6:27] So the easy way to deal with that is to just add in a diode to block negative signals.
[6:33] So we’ll just stick in a um a diary here.
[6:36] want that to actuall join let’s wire it up again.
[6:39] So there’s our stop jumping over.
[6:42] Like let’s try that and there that they want that connected
[6:45] to there and while that connected to there
[6:49] and then we want our output on the output of that.
[6:52] And I think we need a pull down resister otherwise
[6:55] this will just float around when it’s negatively biased, so and it’s put in
[7:00] a we can come a fairly high resistor for this is let’s just
[7:03] is a 10 K. So wire that up
[7:09] and now let’s run our our time domain simulation. and there we go.
[7:13] That’s perfect.
[7:15] So when this signal goes negative, it clamps it at zero volts on the output.
[7:19] But we still got this very high voltage, which could make its way into the ESP 32.
[7:24] So simple way to deal with that is just a zener
[7:27] diode on the output and that will clamp that.
[7:31] So I stretch that across and wire this up and
[7:35] I know I’ve got a 2.8 volt zener diode so I’ll
[7:39] just uh change that to match what I have in my
[7:42] in my bucket of bits.
[7:44] I made a mess with that so neaten that up better
[7:47] get that better. uh so now if we’ run this, so run
[7:50] our time domain analysis so that’s perfect so now we’re
[7:54] clamped at zero volts and we’ clamped to around 2.8 volts.
[7:57] So even though we’re feeding in this massive signal, it shouldn’t damage our ESP 32.
[8:03] Now a thing I might do is let’s go back to
[8:06] our nice sensible one volt.
[8:09] And if we run this timed domain simulation,
[8:11] then you can see that we’re no longer centered around half of 3.3 volts.
[8:17] So we’re now more like a around uh,
[8:20] I guess a round kind of one one volt or 1.1 volts.
[8:25] And the reason for that is obviously we’ve got the voltage drop across this diode.
[8:30] What we can do is we could just change this top resistor value so if we make this smaller
[8:34] and now on the simulation again.
[8:39] then I seem to have messed that up a big time, so what have I done wrong here?
[8:43] I got 470 470k so that’s an all right, what 470 ohms.
[8:48] So let’s try that again and well our time simulation.
[8:51] So there we go.
[8:53] Now we’ve got our nice input wave form minus one to one
[8:56] and on the output we’re back entered back around kind of
[8:59] around 1.6ots sort of half 3.3.
[9:01] So that’s perfect.
[9:03] We can feed that straight into the ESP32 and use the analog to digital converter.
[9:07] So let’s jump over to the work bench and see
[9:10] if um see if reality matches up to the simulation.
[9:16] So I’ve made up the circuit of breadboard and
[9:20] I’ve hooked up my signal generator to it, so we can give it a bit of a testing.
[9:24] So let’s uh let’s look at the oscilloscope
[9:28] and uh we’ll um we’ll see how well this works.
[9:32] It’s turn on the signal generator.
[9:35] I’ve currently got it set to one volt peak to peak.
[9:38] And if we look um down here, we can see the yellow is um
[9:44] it’s the input so voltage peak to peak,
[9:47] one one two and our output is the blue one,
[9:50] getting one on the output, and its midpoint is
[9:54] 1.25 volts can see it’s not getting negative and
[9:58] it’s not maxing out the the input either.
[10:01] So let’s uh let’s bump this up so that’s two volts’s three volts.
[10:05] So see now we’re clipping the negative
[10:08] so we don’t go negative. uh let’s go four volts.
[10:12] Five volts, six volts,
[10:15] seven volts, eight volts, nine v
[10:20] volts so our peak is being clipped, so that’s
[10:23] uh one to it’s around three volts so that’s pretty good.
[10:28] Let’s keep going up.
[10:30] So now my input is at 20
[10:32] volts in Ive maxed out what my signature generator
[10:36] can do, and our input v volted one two three, 3.
[10:40] 3.5 volts.
[10:42] I think let’s have a look.
[10:44] um so on.
[10:46] VPeak.
[10:47] That’s coming out as four volts.
[10:48] It says there, but actually one, two, three, three and a be.
[10:51] I think it’s taking this uh slight negative spike into account and er doing the total.
[10:56] So that’s really good the circuit actually seems to work.
[10:59] Brilliant. um
[11:01] Let’s try it out.
[11:03] I mean, you’ll have seen it already because I’ve shown this at the start of the video.
[11:06] Well let’s try loading some some tape data into
[11:09] the emulator using our amazing circuit.
[11:15] So I got everything hooked up and let’s try loading.
[11:20] So you can see, we’ve shifted the signal up. um it’s
[11:24] working really well. um it never gets old looking
[11:27] at these uh screens being displayed, the way it builds up.
[11:31] I mean, you can see how the
[11:34] crazy layout of the spectrum screen memory
[11:37] is that uh it’s it’s really annoying
[11:40] sometimes trying to work with this screen. drawing sprites
[11:43] and actually turning this into a image for the TFT screen.
[11:47] It’s quite a lot of work.
[11:49] So the circuit’s working really well.
[11:51] now obviously there’s other ways to do this.
[11:54] There’s many ways to skin a cat.
[11:56] I could have used some kind of transistor amplifier
[12:00] or done something else, but this actually works really well.
[12:03] Now obviously, this isn’t the ideal way of doing it.
[12:06] There’s better ways to do this.
[12:10] So what we can do is load these um tap
[12:13] files or TZX files directly, so if we’re going into games, I’ve got a
[12:17] few um tape files already stored in here. um
[12:20] I think I’ve got Knitelore somewhere.
[12:24] So let’s find Knitelore.
[12:26] There we go Knitelore.
[12:28] That’s is probably an interesting one because it’s actually a um accelerated tape reader.
[12:32] But you can see when we’re loading using um directly
[12:36] into the system, we’re loading it at super fast speeds and this is running about
[12:40] four times the speed of what would to be happening
[12:43] with sort of native audio in.
[12:45] We could just see how fast that screen loads to see how quick
[12:49] this is. obviously with
[12:52] Z80 files, they are just complete snapshots of the memory and
[12:55] they load pretty much instantaneously.
[12:58] But if you want to get all the kind of loading effects and see the nice loading
[13:01] screens, then TZX files and tap files are the way to
[13:05] go, and you get to the experience some of the nostalgic
[13:09] excitement of loading a tape and seeing the flashing borders.
[13:13] but this is almost finished loading already normally that would
[13:16] take a few minutes to load, but it’s loaded in the
[13:19] time I’ve been rambling on and talking to you.
[13:21] So any second now it should finish and there we go.
[13:25] That’s Knightlore loaded.
[13:27] Fantastic.
[13:28] So check out my ESP32 Rainbow.
[13:31] It’s on crowd supply right now. um please
[13:35] back it because we’re almost fully funded and I need to get into production.
[13:39] Thanks for watching.
[13:40] I’ll see you soon.


HELP SUPPORT MY WORK: If you're feeling flush then please stop by Patreon Or you can make a one off donation via ko-fi
Want to keep up to date with the latest posts and videos? Subscribe to the newsletter
Blog Logo

Chris Greening

> Image

atomic14

A collection of slightly mad projects, instructive/educational videos, and generally interesting stuff. Building projects around the Arduino and ESP32 platforms - we'll be exploring AI, Computer Vision, Audio, 3D Printing - it may get a bit eclectic...

View All Posts