Author |
Message |
BananaPlug
Joined: Jul 04, 2007 Posts: 307 Location: Philly
Audio files: 5
|
Posted: Sun Mar 30, 2008 3:49 pm Post subject:
Help with UART for MIDI clock source project? |
|
|
Here's the goal:
Analog pulse input triggers a UART to send hex F8 (that's MIDI Clock) out of a MIDI jack at 31.25 kbaud.
I'm pretty ignorant of MIDI matters but from what I've read that's all it takes to send MIDI clock. I can use my synth to generate the 24 pulses per quarter note and plug that into this proposed little black box.
Any fundamental flaws with that?
I can handle the buffering on either side of the UART but am not finding practical advice on setting up the UART or which UART chip to use. Everybody seems to use microcontrollers for MIDI (PIC, AVR, etc.) but this is such a simple application I'd rather just use the UART.
If I go for any frills it would be to add some logic to send a few other codes; MIDI start, stop, continue are also single byte codes.
Help me out with this and I'll make PCBs or kits available.
Thanks! |
|
Back to top
|
|
|
DrJustice
Joined: Sep 13, 2004 Posts: 2114 Location: Morokulien
Audio files: 4
|
Posted: Sun Mar 30, 2008 4:20 pm Post subject:
Re: Help with UART for MIDI clock source project? |
|
|
BananaPlug wrote: | Here's the goal:
Analog pulse input triggers a UART to send hex F8 (that's MIDI Clock) out of a MIDI jack at 31.25 kbaud.
I'm pretty ignorant of MIDI matters but from what I've read that's all it takes to send MIDI clock. I can use my synth to generate the 24 pulses per quarter note and plug that into this proposed little black box.
Any fundamental flaws with that?
|
Not that I can see, but see below.
Quote: |
I can handle the buffering on either side of the UART but am not finding practical advice on setting up the UART or which UART chip to use. Everybody seems to use microcontrollers for MIDI (PIC, AVR, etc.) but this is such a simple application I'd rather just use the UART.
|
But wouldn't you then need a microcontroller or some programmable logic to drive the UART?
Unless there is missing element in your setup above that I've missed, I definitely think the problem is best solved with a microcontroller with an onboard UART - most microntrollers have one or more UARTs on board (as well as of other handy perhiperals!). It will be cheaper and simpler than a separate UART and control system.
I'd suggest looking into a small AVR or PIC. E.g. an ATtiny2313 (datasheet) would do nicely and only costs a couple of dollars (I mention an AVR since it's what I'm used to, but PICs are also very popular).
Quote: |
If I go for any frills it would be to add some logic to send a few other codes; MIDI start, stop, continue are also single byte codes.
|
If you have a microcontroller, you easily get all that and more 'for free'.
DJ
-- |
|
Back to top
|
|
|
BananaPlug
Joined: Jul 04, 2007 Posts: 307 Location: Philly
Audio files: 5
|
Posted: Sun Mar 30, 2008 4:33 pm Post subject:
|
|
|
Quote: | But wouldn't you then need a microcontroller or some programmable logic to drive the UART? |
The UART (as shown in my ancient CMOS Cookbook) has a parallel input. So I was thinking just wire up those 8 bits for F8 and give it a kick. |
|
Back to top
|
|
|
blue hell
Site Admin
Joined: Apr 03, 2004 Posts: 24079 Location: The Netherlands, Enschede
Audio files: 278
G2 patch files: 320
|
Posted: Sun Mar 30, 2008 4:55 pm Post subject:
|
|
|
A UART is a pretty complicated device that can have a parallel input to send commands and data to it, usually it has to be set up first before it will do any data transmissions. There used to be very simple UARTS in the past that maybe could be used for this projects, but those have been obsolete for decades ...
When you do not want to use a processor you could look into parallel in / serial out shift registers. You would need a shift register of at least 10 bits, one start bit, one stop bit and 8 data bits (MIDI doesn't use parity I think? I forgot .. anyway when it needs parity the shift register will have to be 11 bits long).
A processor solution will be cheaper I think, but it needs some tooling. _________________ Jan
also .. could someone please turn down the thermostat a bit.
|
|
Back to top
|
|
|
BananaPlug
Joined: Jul 04, 2007 Posts: 307 Location: Philly
Audio files: 5
|
Posted: Sun Mar 30, 2008 5:04 pm Post subject:
|
|
|
Maybe I have to put my 30 year old book away and use the 21st century approach. Just seems like overkill. Even if it's only a few bucks for the chip I need to get the development kit and load the chip with software and debug that and... |
|
Back to top
|
|
|
DrJustice
Joined: Sep 13, 2004 Posts: 2114 Location: Morokulien
Audio files: 4
|
Posted: Sun Mar 30, 2008 5:07 pm Post subject:
|
|
|
[I did type an answer that seemed to disappear as I posted it, but Blue Hell has basically made the same point]
I just checked and s small microcontroller is cheaper than a typical stand alone UART. A microcontroller really is the rational solution.
@ Blue Hell: you're right, there's no parity for MIDI
DJ
-- Last edited by DrJustice on Sun Mar 30, 2008 5:12 pm; edited 1 time in total |
|
Back to top
|
|
|
DrJustice
Joined: Sep 13, 2004 Posts: 2114 Location: Morokulien
Audio files: 4
|
Posted: Sun Mar 30, 2008 5:09 pm Post subject:
|
|
|
BananaPlug wrote: | Just seems like overkill |
Well, nowadays the situation is such that any other solution than a microcontroller would generally be seen as overkill for a task like this. You should really check it out - once you get going with microcontrollers, a world of opportunities will open up and you will have lots of fun.
DJ
-- |
|
Back to top
|
|
|
BananaPlug
Joined: Jul 04, 2007 Posts: 307 Location: Philly
Audio files: 5
|
Posted: Sun Mar 30, 2008 5:49 pm Post subject:
|
|
|
Yeah, I know I might as well use a micro but I was thinking in terms of there being just the right part for this task. Thanks for the sane guidance. |
|
Back to top
|
|
|
jksuperstar
Joined: Aug 20, 2004 Posts: 2503 Location: Denver
Audio files: 1
G2 patch files: 18
|
Posted: Mon Mar 31, 2008 11:17 am Post subject:
|
|
|
You can get really complicated ... get a PLD (programmable logic device), download the source code (hardware source code) for a UART (see opencores.org), then program the part. Doing TX like you said would be easy, but it'd also allow you to maybe receive clocks, and send a pulse back to your synth from MIDI.
Again, there's tools, learning, TIME, etc.... |
|
Back to top
|
|
|
BananaPlug
Joined: Jul 04, 2007 Posts: 307 Location: Philly
Audio files: 5
|
Posted: Mon Mar 31, 2008 12:18 pm Post subject:
|
|
|
Interesting but I think I'll use this as an excuse to get my feet wet in AVR land. My half baked idea is to get the basics working and then do coding similar to a tap clock function so that you could input a clock at whatever rate you like. In other words first tell the box how many pulses you plan to give it over the span of one quarter note and then let it figure out the correct MIDI clock timing for that.
Let's say the user wants to feed this box 16 PPQN and get standard MIDI clock out (24 PPQN) at the same tempo. Measure the time between incoming pulses, intervalOut = intervalIn * 16/24, set the interval for the send clock. So there'd be a timer for triggering the sending of the MIDI clock, and a timer counting up during each input interval and then setting the value the output clock will reload itself with. I need to read up one how they do timers and interrupts.
Feature-wise, a few more input jacks for start, stop, continue and maybe a mode where those are issued automatically based on what your input clock does. Probably use up/down buttons and 7-seg display for telling it how many PPQN you want to input. Maybe offer 8 choices (1,2,4,8,10,12,16,24) and use individual LEDs to indicate your choice. Also some way to adjust the phase of the MIDI clock. Probably use the same pair of up/down buttons.
I would also supply a pulse out so if you don't care about MIDI you could set it for 1:1 timing ratio and use it as a tap-tempo clock source.
This is not my top priority project right now and I have to learn about AVR and pick out development tools. Eventually this will get going though and if you have use for something like this post your suggestions. |
|
Back to top
|
|
|
widdly
Joined: Jun 25, 2007 Posts: 268 Location: singapore
G2 patch files: 2
|
Posted: Tue Apr 01, 2008 8:15 pm Post subject:
|
|
|
There is a project on MFOS using CMOS shift registers for receiving midi.
http://www.musicfromouterspace.com/analogsynth/midi2cv.htm
No uC's or UART's. Might give you some ideas. Last edited by widdly on Thu Aug 05, 2010 10:16 pm; edited 1 time in total |
|
Back to top
|
|
|
BananaPlug
Joined: Jul 04, 2007 Posts: 307 Location: Philly
Audio files: 5
|
Posted: Wed Apr 02, 2008 6:14 am Post subject:
|
|
|
Wow. That's very cool. It's also a great argument for using a $3 PIC chip instead of the 10 or 12 chips it took to do that.
I've pretty much settled on using a PIC16F628A as the basis for my MIDI clock generator and then following that up with a slightly more ambitious module that would be a programmable pulse divider with a few separate outputs and resets, and would have tap-clock capability. This and a few logic gates would make a nice rhythm source and it would easily handle big divisors that are kind of hard to produce with analog modules, especially prime numbers.
If anybody has some links to tutorials and overviews specific to the PIC16F628A please send them along (perhaps to one of existing microcontroller threads). I've got the datasheet and have some long-ago experience with programming micros but I'm a little short on practical advice and strategies for applying this chip to real-world tasks. |
|
Back to top
|
|
|
blue hell
Site Admin
Joined: Apr 03, 2004 Posts: 24079 Location: The Netherlands, Enschede
Audio files: 278
G2 patch files: 320
|
Posted: Wed Apr 02, 2008 6:26 am Post subject:
|
|
|
Pic 16 is a bit ugly with ROM banking, be sure to look into how that works - when your application idea still is what you've sketched before you probably won't run into it, but when things get bigger it might get a bit nasty.
Be sure to read the silicon errata sheets for the processor, all Pics have some silicon bugs.
http://forum.microchip.com/ might be useful. _________________ Jan
also .. could someone please turn down the thermostat a bit.
|
|
Back to top
|
|
|
BananaPlug
Joined: Jul 04, 2007 Posts: 307 Location: Philly
Audio files: 5
|
Posted: Wed Apr 02, 2008 6:55 am Post subject:
|
|
|
I was guessing this little $3.00 PIC would be up to the task given that this application is all about watching and wiggling IO pins and doing a little bit of simple arithmetic. It's more hardware than software, not much data either.
Are you suggesting that I start with a heftier micro, even if it's overkill for this project, so that over the long haul I don't have to end up learning about so many different chips?
Thanks for the link. |
|
Back to top
|
|
|
blue hell
Site Admin
Joined: Apr 03, 2004 Posts: 24079 Location: The Netherlands, Enschede
Audio files: 278
G2 patch files: 320
|
Posted: Wed Apr 02, 2008 7:07 am Post subject:
|
|
|
No I think it will do, I was just suggesting you read up a bit on it so you'll know upfront what trouble you'll run into .. or rather what I ran into _________________ Jan
also .. could someone please turn down the thermostat a bit.
|
|
Back to top
|
|
|
blue hell
Site Admin
Joined: Apr 03, 2004 Posts: 24079 Location: The Netherlands, Enschede
Audio files: 278
G2 patch files: 320
|
Posted: Wed Apr 02, 2008 7:09 am Post subject:
|
|
|
A PIC 12 might even do it, but I suppose that such would cause a few headaches. _________________ Jan
also .. could someone please turn down the thermostat a bit.
|
|
Back to top
|
|
|
State Machine
Janitor
Joined: Apr 17, 2006 Posts: 2809 Location: New York
Audio files: 24
|
Posted: Mon Apr 14, 2008 4:18 pm Post subject:
|
|
|
Guys, I have a very simple solution that does not require any fancy MCU or USART at all if all you want to do is receive a trigger at 24 PPQN and send a corresponding MIDI clock message which happens to be "F8h". All you would need is a one-shot that produces a single pulse.
The 8 bit MIDI data is sent least significant (LSB) first at a rate of 31.25 KHz which equates to a 32 uS bit time. Also, it is a classic NRZ type serial transfer in the 8N1 format. Thats 8 data bits, no parity, and one stop bit. Preceding this is a start bit which is logic zero. Breaking down "F8h" :
"11111000"
Luckily for us, there are 3 consecutive zeros in the LSB bit positions and one start bit that is also a logic zero which makes for 4 bit times your pulse needs to be a logic zero or (4 * 32 uS). The pulse would be 128 uS. All you need is a one-shot that will generate a low going 128 uS pulse and drive your MIDI current loop (5 milliamperes) with that. No programming necessary or setting up of any USART at all
The MIDI receiver does not know if a USART sent it or some silly little pulse generator.
Sounds right anyway .........
If you want to get fancy,l then go with the 16F627A, an 18 pin PIC with USART, timers, A/D's, etc ....... for about $2.50 in single piece quantities.
Bill |
|
Back to top
|
|
|
State Machine
Janitor
Joined: Apr 17, 2006 Posts: 2809 Location: New York
Audio files: 24
|
Posted: Mon Apr 14, 2008 4:21 pm Post subject:
|
|
|
Quote: | A PIC 12 might even do it, but I suppose that such would cause a few headaches. |
Naaah, just bit bang the little bastard ........
Bill |
|
Back to top
|
|
|
BananaPlug
Joined: Jul 04, 2007 Posts: 307 Location: Philly
Audio files: 5
|
Posted: Mon Apr 14, 2008 6:03 pm Post subject:
|
|
|
Good point! I'm trying to clear out some partly finished projects first but at some point I'll breadboard something to push a pulse out MIDI style and see if it works. |
|
Back to top
|
|
|
DrJustice
Joined: Sep 13, 2004 Posts: 2114 Location: Morokulien
Audio files: 4
|
Posted: Tue Apr 15, 2008 6:25 am Post subject:
|
|
|
State Machine wrote: | All you would need is a one-shot that produces a single pulse. |
I like that - Should work like a charm! Who needs UARTs anyway
DJ
-- |
|
Back to top
|
|
|
Joel
Joined: Sep 12, 2006 Posts: 97 Location: London, UK
|
Posted: Tue Apr 15, 2008 8:09 am Post subject:
|
|
|
State Machine wrote: | Naaah, just bit bang the little bastard ........ |
I've seen the the term used, especially in relation to midi data, but am not really sure what it means? Can anyone point to an explanation/tutorial/example? |
|
Back to top
|
|
|
DrJustice
Joined: Sep 13, 2004 Posts: 2114 Location: Morokulien
Audio files: 4
|
Posted: Tue Apr 15, 2008 8:37 am Post subject:
|
|
|
Bit banging usually refers to the method of simulating a hardware device, like e.g. an UART, by using just general purpose IO pins and and software to do the job.
DJ
-- |
|
Back to top
|
|
|
State Machine
Janitor
Joined: Apr 17, 2006 Posts: 2809 Location: New York
Audio files: 24
|
Posted: Tue Apr 15, 2008 9:23 am Post subject:
|
|
|
Thanks DJ ..... If the highs and lows were dispersed then it would have been harder to impliment and in such a case, a cheap microcontroller would suffice with just some general purpose I/O you can just toggele under firmware control.
One other question in response to the comment below in the opening post.
Quote: | Analog pulse input triggers a UART to send hex F8 (that's MIDI Clock) out of a MIDI jack at 31.25 kbaud. |
What it's electrical characteristices of this "pulse" such as amplitude, width, rise/fall times ....
Bill |
|
Back to top
|
|
|
BananaPlug
Joined: Jul 04, 2007 Posts: 307 Location: Philly
Audio files: 5
|
Posted: Tue Apr 15, 2008 11:15 am Post subject:
|
|
|
The input pulse referred to in the original post would be any kind of common modular synth clock pulse, the sort of thing you would clock a sequencer with. In other words something we would clean up first so as to trigger off of the leading edge of the pulse. |
|
Back to top
|
|
|
State Machine
Janitor
Joined: Apr 17, 2006 Posts: 2809 Location: New York
Audio files: 24
|
Posted: Tue Apr 15, 2008 12:17 pm Post subject:
|
|
|
Quote: | The input pulse referred to in the original post would be any kind of common modular synth clock pulse, the sort of thing you would clock a sequencer with. In other words something we would clean up first so as to trigger off of the leading edge of the pulse. |
OK, I see. The Klee sequencer, for example, has a CLOCK input but you can use a sine wave signal of 10V peak to peak to clock it because it is conditioned using a fast voltage comparator and hysteresis feedback to prevent oscillation during very slow clock transitions. Thus clocks can vary wildly from traditional fast TTL level pulses to analog waveforms of any shape which can traverse below your ground reference. To cover all possibilities then, the similar circuit that conditions the Klee clock input would most likely be most suitable for your application. The corrisponding pulse edge derived from such a circuit can then be used to generate your 5V, 128 uS low going pulse I spoke of in my earlier post.
ref:
http://electro-music.com/forum/topic-24821.html
Most likely a dual single supply comparator can do the conditioning duties and 128 uS pulse generation. I could show you examples but I urge that you try for yourself. More hands on and mistakes along the way make you a better engineer/technician
Bill` Last edited by State Machine on Tue Apr 15, 2008 12:36 pm; edited 2 times in total |
|
Back to top
|
|
|
|