I pretty quickly landed on the idea that I would be doing a vinyl record that could be touched to control the playback speed of a beat, to create the classic "wacka-wacka" record-scratching sound of the late 20th century.
The problem of course, was that I've never done capacitive touch (either in hardware or software), I've never done software for audio use, I would have to fit everything within the physical constraints of the contest (40x50 mm), and I initially wanted to do it on a cheap Chinese microcontroller that did not have a hardware peripheral for I2S to talk to the amplifier. I could bit bang that though. Or so I thought.
With nothing but naïve optimism and a head full of unanswered questions I did what any sane hardware hacker would do: as little research and maths as possible. I crossed my fingers and started the hardware layout.
Step 1: What is a capacitive touch sensor?
Ok, I had a general understanding of this already, and I'm not going to dive into the details of the physics behind it in this post. But I had a surprisingly hard time figuring out how the seemingly simple sensor could actually be designed and wired up to a microcontroller. What were the requirements for the pin on the MCU?
All the App Notes I could find in the beginning were tens to hundreds of pages long, and written by big companies trying to convince me that I would have to buy their custom ASIC to solve this incredibly difficult issue.
After skimming through a lot of mind numbingly long PDFs I realized I had heard someone talk about the wiring of capacitive touch sensors on a Discord server a while ago. And that's where I found my answer from prolific badge maker Bradán Lane:
Step 2: How does one design circular capacitive touch pads?
Righty-o, schematics out of the way. Now on to the layout... Let's have a quick look at some inspiration, and:
Eeeh... That looks... complicated. Where do you even start designing something like that?
Luckily, this time, there's an app note to the rescue. This excellent app note from TI named Automating Capacitive Touch Sensor PCB Design Using OpenSCAD Scripts was exactly what I was looking for. The app-note provides OpenSCAD scripts for parametric generation of all the most common capacitive touch geometries, along with a thorough explanation of the parameters.
Since KiCAD has a healthy plugin-system I seriously considered porting the script to a python extension, but felt like that was a bit out-of-scope for this project, especially considering the contest deadline. I may have a closer look at that if I ever start another project where I need various sized captouch pads.
My final workflow ended up being as follows:
- Export only the top touchpad geometry from OpenSCAD (Touch 1 in the figure above), as described in the app note.
- Import the DXF into the footprint editor of KiCAD as a graphic (File -> Import -> Graphics... )
- Convert it to a polygon (Right click -> Create from Selection -> Create Polygon from Selection...) using centerlines seems to work best in KiCad 8.
- Merge it with a pad ( I used an SMD pad in my original design, but a THT pad in the screenshot below - not sure which one I prefer to be honest). Click "Add pad", place it somewhere within the polygon, click "Tools -> Repair Graphics..." (for some reason), select "merge overlapping graphics into pads:
- Duplicate it 3 times by "creating an array". "Right click -> Create from Selection -> Create Array...", select the "Circular Array" tab. Verify the circled settings, and remember to check the "rotate items" checkbox
Result:
Nice. Time to slap in a cheap microcontroller and order the boards while moving on to the code. I opted for the Puya PY32F003 as it is dirt cheap ($0.25 in the lowest quantity at LCSC), and I've recently used the even cheaper PY32F002A in another design and had the programming and debugging environment set up and ready to go. The main reason I upgraded to the F003 was to get more unique timer capable pins (TIM), and route one to each of the touch pads.
Full schematics:
Layout:
Step 3: Bit banging I2S
Using the older F002 based design I had laying around I got to work attempting to bit bang I2S. Fairly quickly I was shuffling out what looked like I2S on my logic analyzer, and I was super happy about that. It was operating at speeds that were good enough for the low quality speakers I would be using here anyway. I had it shuffling 8 bit data at roughly 2k samples per second. Terrible, yes, but I tested the configuration out in Audacity on the beat I was hoping to use, and on my laptop it sounded OK for what I was trying to achieve.
However, when hooking this datastream up a breakout board with an I2S amplifier, everything stayed silent. I could not get the data to be recognized by the amplifier I had selected.
After reading the fine print in the datasheet it turned out that I wasn't meeting the surprisingly strict timing requirements of the amp (ok, the print wasn't actually that fine. Anyway: do you remember all that math and research I did before? Me neither).
My plan until this point had been to shuffle out samples with a varying inter-sample delay to adjust the playback speed, but the amp wouldn't have it. It required an entirely stable data rate, presumably due to some internal PLL or ILO circuit, and a minimum of 8k 16-bit samples per second.
Step 4: Shock/Denial
Step 5: Pain/Anger
Step 6: Bargaining
Step 7: Depression
Step 8: Acceptance
The timing requirements and minimum sample rate of the amp was way beyond what I would be able to do on this MCU. I wouldn't even be able to meet the requirements if shuffling out bits was the only necessary processing task - which it wasn't. I also had to shuffle samples in memory, read captouch pads, calculate finger position and adjust playback speed.
Ok, I had to redesign the board. But I had already spent quite a lot of time and money making it this far, so before lunging into new unknown territory I figured I should first make a working proof of concept with a different MCU.
Luckily, I had forseen this possibility and routed the touch pads out to the 4 "unused" pins on my SAO connector (all the ones that are "not power"), so the boards were not manufactured in vein. I could use them for developing the second prototype with a more capable MCU.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.