pico-zxspectrum
pico-zxspectrum copied to clipboard
Audio input suggestion
Since I figure that the ultimate goal is to recreate all functionality of the original ZX Spectrum, I am thinking that by using some modified hardware (or some new one even) from this microphone library, this goal can be achieved. By adding a 100uF for isolation purposes as the guidelines for the analog module say maybe we can reach the goal. I may be able (and willing) to test some hardware... I'm no audiophile but I got the tools to make what I usually need so that the analog "Line In" function can be available for the old cassette players out there... maybe even a save to ".tap" directly to the SD Card at the end... for comparison purposes since I still remember how error prone was this process in the old days. I can try some different ways with the hardware part (will research more this part so we don't fry the pico) but since all this work is your baby, only you know if the analog part of the library can be adjusted to work with all the different layouts and if one input pin is available.
This may be of interest : http://www.zxdesign.info/cassette.shtml
Might be fun to be able to load from a real audio source 🙂.
The software side will be tricky. There are moments when the z80 is paused to read the keyboard etc. It catches up afterwards but any audio input will need to be kept in sync.... I think it will require the CPU speed moderation to be rewritten and based on the depth of an audio queue.
From the above, I extracted this:
As for the loading part, how about adding an Cassette mode - F2 key is free - that sets the CPU to 3,5MHz and monitors only the F2 key... just a thought...
I'm not 100% sure but I think Vcc in their design is 5v... So we need to adjust R42 & R41 so that the gate bias is correct for 3.3v. Also, the author says his audio signal goes from -2.3 to +2.6 which seems high to me, I would expect more like -1.1 to +1.1v. The threshold voltage on the pico is about 1.8 volts, rather than 3.7 for the 74hc gate.
Hmm, also this circuit has no gain, which we may want a little of if I am right about the voltage range on the input pin... May need to give this a little thought. If you can take some measurements of actual voltage ranges into a 1k load that would really help. E.g a pc audio jack, a phone, an old tape player.
...Maybe the higher voltage is to able to drive headphones?
On the pico...
"Normally the voltage threshold is about 1.8V, but it isn't guaranteed; it can be anywhere between the maximum input low and minimum input high, that is, between about 0.8 and 2.0V."
Could just try it with 39k for R42. Please correct my junior school maths if I have got it wrong.
Centre voltage... (2.0v - 0.8v) / 2 + 0.8v = 1.4v
Add in the BE voltage... 1.4v + 0.6v = 2v
So... 2 = 3.3 R42 / (R42 + 27) => R42 ~ 40kohm
And pick one that is easy to buy... 39kohms!
Been on the road all day and will be the same for the next two days... we had a planned family trip. As soon as I'll be home, I can take some measurements with actual components and different audio signals.
I hope you have a nice time with your family.
Thank you! I had a nice time with the family ^_^
As for the tests, today I did some measurements and here they are:
I set volume to max from PC and had playing sound from Fuse (game menu - ADayInTheLife 1985
- has some really loud sounds):
- PC headphone source:
1k resistor = maximum of 290mV AC and 7mV DC
output voltage ~= 1,48V-1,5V DC
- TV line out source (PC HDMI audio through TV):
1k resistor = maximum of 650mV AC and 3mV DC
output voltage ~= 1,53-1,55V DC
As for actual components, for the 27K I used 22K+4,7K (~26,3K measured), for the 39K I used 33K+3,9K+3,9K (~39,4K measured) and for the 56K I used 47K+10K (~54K measured). I used a 2N2222A since it was already in my components stack and it's an equivalent for BC548.
For the VCC (3,3V) I used a USB-TTL adapter.
Thanks for those measurements. It looks like the voltage swing is not really big enough 🙁. It's a shame the adc doesn't work, it would be ideal for this. Maybe we need an amplifier (rather than an emitter-follower) or a Schmitt trigger? Don't want it to get too complicated but I've seen some 2 transistor designs for a Schmitt trigger.
At first glance, an amplifier may be too much (on the other hand it's late and I might not have all the marbles in place right now). I did found some explained details about a Schmitt trigger here and also here. Now regarding the details, we could learn from some actual builds, as this was another find. What should the actual voltage swing need to be? Also as I seem to understand from an alternative design there might be also a need to invert or non-invert the signal... (?)
Well, if the 0.8 to 2.0 volts thing is correct, at least 1.2v.I I don't think it matters if it is inverting or not. Thanks for the links I will read through them when I get a mo.
I've done some more reading and found the rp2040 inputs have their own hysteresis...
https://raspberrypi.github.io/pico-sdk-doxygen/group__hardware__gpio.html#ga1f52eecc12d4348ef8bd1e17bdb4b107
I probably need to find out more about that.
I found an example with hysteresis experimentation on the raspberry pi forums. Unfortunately I don't have an oscilloscope to play with. If it takes too much of the CPU though, the hardware way is the way to go.
Been reading this... https://en.m.wikipedia.org/wiki/Line_level ... which suggests 10k (rather than the 1k) load resistance. Perhaps that would give a bit more of a voltage swing.
As I should have expected, when using the 10K, with the PC headphone source (it was the only test I did), the AC voltage is the only difference encountered:
10k resistor = maximum of 65mV AC and 7mV DC
output voltage ~= 1,5V DC
Also the same AC voltage seems to be present at the output line (same as before witch I failed to mention above)... so this is definitely not the way to go. I'll try to find components for the Schmitt trigger schematic... something equivalent to what the 74C/HC14 does.
They are easy to make with an op amp. I've ordered some that will run at 3v to have a play with. We can compare notes then 🙂. I'll post the circuit when I get a mo.
This site is good...
https://www.random-science-tools.com/electronics/inverting-schmitt-trigger-calculator.htm
Something like this...
The pot is there to adjust the threshold, which we could fix if we find a good value. I'm not sure about the lm224n, just need something that will work at 3.3v.
...but it does turn out the op-amps I have ordered are going to take a long time to get to me!
I dug and found some schematics from different clones of the ZX:
HC-2000
CIP-01
After that I changed the testing procedure:
I set volume to max from PC and had playing sound from PlayTZX inside DosBox (same game -
ADayInTheLife 1985
):
With the first schematic (transistors) the test had the same result as before.
For the op-amp schematic, I used a βM358N instead of a LM224N and also changed the 10k+100kVR to 100k+100kVR(with the actual value set at about 150k).
Results:
- PC headphone source:
output voltage in idle mode ~= 1.71V DC and 0V AC
output voltage in play mode ~= 1.06-1.08V DC and 1.15-1.27V AC (1.23V mostly)
- TV line out source (PC HDMI audio through TV and TV volume set to at least 30):
output voltage in idle mode ~= 1.71V DC and 0V AC
output voltage in play mode ~= 1.01-1.08V DC and 1.17-1.23V AC (1.20V mostly) | I'm not sure but I think I noticed DC voltage going down when TV volume goes up
Hi, sorry for the slow reply, 'real-life' has been distracting me!
The 1st circuit looks like a non-inverting comparator, without hysteresis. I like the way the bias is arranged; the single (rather than dual) voltage divider means you don't have worry about tolerance on the resistor values.
The 2nd circuit looks like a high gain inverting amp... but I'm not sure what R30, R70, D9 & D10 are up to! Do you know what VMED gets connected to?
I know what you mean about 'real life'. I've been pinned to the bed for the last two days due to a nasty cold... better now. I changed the above labels for the schematics since I mislabeled them. I only just noticed by searching through the schematic for VMED witch goes through at least three pages (pages 2,3 and 4). There are other schematics on that site that could prove to be useful.
Thanks for finding those... I will get back to this at some point!
I've added a little test program which reads GP11 at 44Khz and sends 1s and 0s to the USB uart. Not as good as a dual-channel scope but it's something!
cp uf2/ear_in_test.uf2 /media/pi/RPI-RP2/
tio /dev/ttyACM0
See https://github.com/fruit-bat/pico-zxspectrum/pull/54/files
There is even a small chance this may work! It samples GP11 once a microsecond using the PIO and feeds it into the emulator. Should cope with 32x32 microsecond delay in instruction emulation.
I'ts going to take a bit of work to fix all of the targets so only ZxSpectrumBreadboardHdmi4PinAudio is working at the moment. Let me know if you want a binary to play with.
Been a bit busy digging the net for anything Spectrum for a while now (I lost at least four hours tonight just to find this in the end). Also I've been checking some wav dumps of some tapes since I'll surely need them to test the audio input. I will have to put together another Pico and test it with the breadboard since it's easier in the long run (I ordered a while back one piece of Wren's module and a micro sd card module). For now I'm off to bed (huge headache) but a binary and some instructions to test in a couple of days would be nice. As soon as I can test it (using the components with βM358N), I'll be back with feedback. By the way... when I tested the op amp circuit, I used 3.3V. Since the 3.3V has to be stable for the SD Card, maybe I should test the circuit beforehand using 5V from VSYS just like I used for the HXJ8002 amplifier circuit?
Hope your headache is better. Stick to 3.3v on the opamp. I think 5v will damage the pico.
I've just loaded Frogger from a WAV file 🙂 The circuit I used is a mess but it proves that the software sort of works!!!