10 Cent Microcontroller Makes Tracker Music

We are absurdly spoiled these days by our microcontrollers. Take the CH32V00X family– they’ve been immortalized by meme as “the ten cent micro” but with a clock speed of 48MHz and 32-bit registers to work with, they’re astoundingly capable machines even by the standards of home computers of yore. That’s what motivated [Tim] to see if he could use one to play MOD files, with only minimal extra parts– and quite specifically no DAC.

Well, that’s part of what motivated him. The other part was seeing Hackaday feature someone use a CH32V003 making chiptune-like beeps. [Tim] apparently saw that post as a gauntlet thrown down, and he picked it up with an even smaller chip: the CH32V002, which he proceeded to turn into a MOD player. For those of you who slept through 80s and early 90s (or for those precocious infants reading this who hadn’t then yet been born), MOD files are an  electronic music format, pioneered on the Amiga home computers. Like MIDI, the file specifies when to play specific voices rather than encoding the sound directly. Unlike MIDI, MOD files are self-contained, with the samples/voices used being stored inside the file. The original version targeted four-channel sound, and that’s what [Tim] is using here.

As you can see from the demo video, it sounds great. He pulled it off by using the chip’s built-in PWM timer. Since the timer’s duty cycle is determined by a variable that can be changed by DMA, the CPU doesn’t end up with very much to do here. In the worst case, with everything in flash memory instead of SRAM, the CPU is only taxed at 24%, so there’s plenty of power to say, add graphics for a proper demo. Using the existing MODPlay Library, [Tim]’s player fits into 4kB of memory, leaving a perfectly-usable 12kB for the MOD file. As far as external components needed, it’s just an RC filter to get rid of PWM noise.

[Tim] has put his code up on GitHub for anyone interested, and has perhaps inadvertently cast down another gauntlet for anyone who wants to use these little RISC V microprocessors for musical tasks. If you can do better, please do, let us know.

15 thoughts on “10 Cent Microcontroller Makes Tracker Music

  1. Sounds like an interesting microchip to play with, can it be used with Arduino IDE or similar C based IDE that is free to use, free of ad, and free of restriction? I need to move away from PAL chip when making a custom Atari 2600 that requires bankswitching and some ATTiny isn’t quite fast enough (8MHz max internal)

        1. You have to buy an external programmer sold by WCH, or use an Arduino 328p (Arduigler) supported by Minichlink. For the Arduino port, I filed an issue long ago to update the Minichlink shipped with it:

          https://github.com/AlexanderMandera/arduino-wch32v003/issues/15
          https://github.com/AlexanderMandera/arduino-wch32v003/issues/27

          I also made static builds of minichlink for Linux and Windows, but they are somewhere on a branch here:

          https://github.com/zoobab/ch32v003fun/tree/minichlink-static

          Arduigler:

          https://gitlab.com/BlueSyncLine/arduino-ch32v003-swio

          I am working on a .ino fork of BlueSyncLine version to support many other microcontrollers:

          https://github.com/zoobab/zooswio

        2. There are tons of open-source programmers based on your particular microcontroller of choice as well, so you can just use whatever you’ve got lying around.

          For grins, Charles and I ported his programmer to micropython https://github.com/Hack-a-Day/2024-Supercon-8-Add-On-Badge/tree/main/i2c_proto_petal_tutorial on the badge last year because we made some CH32v003 based add ons. We needed micropython b/c it was supposed to program them on the fly, but there is no shortage of similar projects.

          Or you pay a couple bucks. The programmers are dirt cheap too, and highly recommended.

    1. hahah no way – i had the exact opposite thought.

      On seeing the first article (with the mere beeps), i didn’t respect it because modplay (MP.COM) could passably decode 4-channel tracker files using 1-bit DAC (PC speaker) on a 286-12. So i think i understand exactly how Tim felt. In the end, i bet using the PWM peripheral almost felt like cheating…modplay was a ridiculous hack because it had to interleave mod decoding/resampling/mixing with doing that PWM in software for each ‘sample’.

      Really, the CH32V003 is much more capable than my old 286. Faster clock, wider word size, more registers, and (i haven’t looked but probably) much fewer clocks per instruction. Nevermind the advantage we get by a great set of compilers targeting CH32V003. Just a question of how to live within the tiny built-in RAM/ROM.

Leave a Reply to EricCancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.