MIDI->STM32->Beeb->Music 5000

for bbc micro/electron hardware, peripherals & programming issues (NOT emulators!)
Post Reply
User avatar
danielj
Posts: 7160
Joined: Thu Oct 02, 2008 4:51 pm
Location: Manchester
Contact:

MIDI->STM32->Beeb->Music 5000

Post by danielj » Fri May 17, 2019 10:26 pm

So,
Some might have spotted this on the facebook group, but I've been playing around with an STM32F446 Nucleo board with a view to creating a very very cheap MIDI->Music 4000 converter. I've posted a couple of videos...
1) Demonstrating that the STM32 uC can actually pretend to be a Music 4000:
https://youtu.be/QCZ0QqFA-qM

2) Demonstrating that it can deal with a MIDI input and use that to pretend to be a Music 4000:
https://youtu.be/mI7FPRjFH3A

Now, it was misbehaving slightly in that second video (sticky notes) - this was mainly due to it missing key offs in the midi serial stream if an interrupt got in the way. Anyway, I've now fixed that with an interrupt filled ring-buffer and it seems to behave (after having liberally scattered the word volatile across the source-code).

Anyway, the upshot is, the entire thing can be done in the one uC which means any hardware is only going to need that, an opto isolator and voltage regs (plus a 74HC14 if you want through). Added bonus is that USB-midi should be relatively easy to implement too :)

I've stuck the code up on my github page (GPL 3.0): https://github.com/drdpj/MidiKeyboard - feel free to have a play - you'll need an optoisolator to take the midi into the nucleo board. I'm going to now try and getting going on the STM103 which is rather cheaper (no reason why it shouldn't) with a view to pushing out a board design. They will definitely not end up being very expensive. I'm not really intending to make (m)any of these, I suspect I'll do a few simply as I'll have ordered a batch of 10 pcbs and I really don't need 10! but the board will be open source hardware so people will be free to re-jiggle as they see fit. Watch this space :D

All constructive comments welcome!

Edit: and here's a video of it finally behaving: https://youtu.be/kdLP8Cr9hn0
Last edited by danielj on Sat May 18, 2019 12:30 pm, edited 1 time in total.

User avatar
IanS
Posts: 878
Joined: Mon Aug 31, 2009 6:02 pm
Contact:

Re: MIDI->STM32->Beeb->Music 5000

Post by IanS » Sat May 18, 2019 10:02 am

Looks good.

Is this like the one here - viewtopic.php?f=3&t=16893
But keeping track of each key pressed in software, rather than having a hardware latch for every key? (and Open-source)

User avatar
danielj
Posts: 7160
Joined: Thu Oct 02, 2008 4:51 pm
Location: Manchester
Contact:

Re: MIDI->STM32->Beeb->Music 5000

Post by danielj » Sat May 18, 2019 10:08 am

Yes, basically does the same, but less parts and is (and will be) an open design. The keyboard matrix is held in an array, the STM32 has hardware peripherals that can deal with the signals from the user port as it scans the keyboard matrix (it's basically SPI), and dealing with the MIDI is just a question of purposing one one of the UARTS. Interrupt on SPI to display the right byte from the keyboard array on GPIOs, interrupt on the UART to dump bytes into buffer, and the rest is gravy.

d.

User avatar
Elminster
Posts: 3282
Joined: Wed Jun 20, 2012 8:09 am
Location: Essex, UK
Contact:

Re: MIDI->STM32->Beeb->Music 5000

Post by Elminster » Sat May 18, 2019 11:18 am

Daniel's is 'design #4' in the hardware list, but now you made me realise I forgot to put the Hideaway Studio in the hardware list. People just have too much time, they keep inventing stuff.

Edit: Added and pushed to github
Last edited by Elminster on Sat May 18, 2019 11:26 am, edited 1 time in total.

User avatar
danielj
Posts: 7160
Joined: Thu Oct 02, 2008 4:51 pm
Location: Manchester
Contact:

Re: MIDI->STM32->Beeb->Music 5000

Post by danielj » Sat May 18, 2019 3:12 pm

There are a couple of acknowledgements due here :D Chris "BooBip" M. who nudged me firmly towards the ST embedded ARM platform, answered numerous stupid questions, provided reams of expert advice and said of my logic analyser trace of the user port output "that looks exactly like SPI...", and also Simon "Domesday" I. who also has answered a number of dumb questions and musings. It's a pleasure to toy around with building things for the Acorn systems as everyone is just so darn helpful!

d.

jasonl
Posts: 30
Joined: Wed Mar 27, 2019 9:22 am
Contact:

Re: MIDI->STM32->Beeb->Music 5000

Post by jasonl » Sat May 18, 2019 9:09 pm

That's really cool. =D> I'm not familiar with the Nucleo. I tried implementing something similar using a Teensy LC microcontroller a couple of weeks ago (because I've got a few) - but it isn't able to respond to the keyboard scanning fast enough on its own.

In the end I made the Midi controller using 8x 74HC595 shift registers to store the keyboard state, updated using SPI from the Teensy. The registers are then enabled in turn by a 74HCT164 shift register connected to the Beeb's user port, as in the original M4000 controller. I got a small PCB made for my DIY Hybrid system. Just added the Midi code and footswitch handling today which works quite nicely. Then I saw your post. :D

Interestingly I notice the Hybrid music software only appears to react to the 49 keys of the 4 octaves of the M4000, though the keyboard controller should allow for 62 keys. And although there are two footswitches allowed for, the Hybrid software treats them the same - as a sustain pedal in the keyboard program. I've not explored the other modules yet.

User avatar
danielj
Posts: 7160
Joined: Thu Oct 02, 2008 4:51 pm
Location: Manchester
Contact:

Re: MIDI->STM32->Beeb->Music 5000

Post by danielj » Sat May 18, 2019 10:10 pm

Good work :) - I'm fairly sure that's approximately the same as Dan's interface (although I think he's using an AVR by the looks of things to do the MIDI)? It's a shame the teensy didn't work - were you using a similar arrangement with the SPI input on interrupts?

The nucleo is pretty cheap for prototyping - around the £10 mark. It's basically an STM32something with an STLINK built in. The one I'm using runs at 86MHz. If I can get it to work on the 103 version (72MHz), I'll see if I can get it to play nicely on a bluepill board, which is also a 103. - those come in at about £4/pop. I would like to design a nice little PCB though, which is under 10x10cm for maximum cheapness at JLCPCB :)

I was surprised it didn't deal with more keys - I guess they just hard coded it :(

User avatar
Elminster
Posts: 3282
Joined: Wed Jun 20, 2012 8:09 am
Location: Essex, UK
Contact:

Re: MIDI->STM32->Beeb->Music 5000

Post by Elminster » Sat May 18, 2019 10:47 pm

deisgn #5 ?

Definitely going Music n000 crazy this month.

jasonl
Posts: 30
Joined: Wed Mar 27, 2019 9:22 am
Contact:

Re: MIDI->STM32->Beeb->Music 5000

Post by jasonl » Sat May 18, 2019 10:48 pm

danielj wrote:
Sat May 18, 2019 10:10 pm
Good work :) - I'm fairly sure that's approximately the same as Dan's interface (although I think he's using an AVR by the looks of things to do the MIDI)? It's a shame the teensy didn't work - were you using a similar arrangement with the SPI input on interrupts?

The nucleo is pretty cheap for prototyping - around the £10 mark. It's basically an STM32something with an STLINK built in. The one I'm using runs at 86MHz. If I can get it to work on the 103 version (72MHz), I'll see if I can get it to play nicely on a bluepill board, which is also a 103. - those come in at about £4/pop. I would like to design a nice little PCB though, which is under 10x10cm for maximum cheapness at JLCPCB :)

I was surprised it didn't deal with more keys - I guess they just hard coded it :(
Thanks. The Arduino SPI library I was using can't act as a slave device, so I was using a pin interrupt to read the userport CB1 and CB2 pins. It was able to cope with that, but couldn't write the byte of data (using port manipulation) of the keyboard status fast enough (i.e. within 1uS). Reading the VIA datasheet helped understand what's going on. It's similar to SPI, but is described as a shift register which latches the userport state once the byte is clocked out.

Using the 595 shift registers frees the Teensy to deal with the decoding of Midi and other stuff, at the cost of a few more parts, and it simplified the programming a lot. I've underclocked the Teensy LC at 24Mhz. Somehow it seems wrong to use a uC that's a arguably more powerful than the host Beeb just as a keyboard controller. Hey ho. :wink: My PCB (another JLCPCB fan) is 10cm x 7cm, using all through-hole parts and the Teensy.

I understand Dan is using a PIC microcontroller, and some latched buffers. Whatever works. :)

Good to have clarification about the 4 octave limitation. I wonder if that's hackable...

BrokenARM
Posts: 33
Joined: Sat Jul 22, 2017 11:07 am
Location: UK
Contact:

Re: MIDI->STM32->Beeb->Music 5000

Post by BrokenARM » Sat May 18, 2019 11:30 pm

I am indeed using a PIC clocked at 20MHz which has been my go-to controller for MIDI applications for many years now. My interface may have a few more parts (although none are expensive) but it certainly responds very spritely to even the most intense of midi thrown at it.

I'm not convinced extending the range beyond 4 octaves is worthwhile - especially in the upper registers where I have found the Music 5000 seems to produce all manner of weird intermodulation effects causing a whole raft of nasty harmonics (which leads me to a theory on why the anti-aliasing filter was rather heavy handed on these little wonders).
Last edited by BrokenARM on Sat May 18, 2019 11:32 pm, edited 2 times in total.

Post Reply