'Midi in to PIC problems'
Can anybody help me? (no smart comments please :-)
I am trying to get MIDI data into my 16C77. It kind of works, but seems to
get some wrong values through (I have examined the same stream on the PC and
it is being transmitted correctly)
PIC is running at 10 Mhz (oscillator using 22pf capacitors). SPBRG is set to
4 (which should give me the 31250 bps right?)
The circuit I am using for input is basically a standard circuit (see the
input section of http://www.borg.com/~jglatt/tech/midi.gif ), but I am using
a 6N139 opto isolator (because I cannot easily get hold of a 6n138).
I would imagine that there is a slight difference that I need to get over
1) I have no specs for the 138 to compare with
2) My analogue electronics is pants
has anybody got any ideas I could try (like maybe a new hobby :-)
Peter L. Peres
|On Sun, 17 May 1998, Catch-It wrote:
> a 6N139 opto isolator (because I cannot easily get hold of a 6n138).
imho, if a scope shows a clean symmetrical vaweform after the opto,
there should be no problem. pay attention to the rise and fall times, they
should be negligible vs. the used baud rate (~30 usec/bit -> edges should
be 3 usec wide or narrower).
Well, one of the reasons that can make your thing fail at such speeds,
is interrupts. You should get 1 byte to save every about 300 usec. If you
do something else meanwhile, that lasts more than that, you will get an
overrun in the receiver register. At 10 MHz this is about 1200 T cycles to
waste. (do you check for overruns ?)
Try to analyze the failed data to see a pattern. If you get overruns
(the same byte twice) you know what's up. If you get garbled bits, check
the signal after the OC. If you get skewed bit patterns look for a timing
problem. The best data for this sort of analysis is a stream of random
numbers on 8 bits, of about 256 bytes length.
Print the sent and received data as binary numbers, 8 bits in a group,
on screen or paper, such that the 1st sent byte is in the line above the
1st received byte etc, then look sharp. You may have to write a small C
program to do this for you...
hope this helps,
Peter (nospam.actcom.co.il) plp
|I have built a 16C73-based MIDI send/receive device with basically the same
circuit, using a 6N138. The system ran off a 4 MHz resonator and used
polling on the serial port send and receive. Here are several things to
look at, given the MIDI interface schematic shown in the GIF file you
referenced (see link in quoted original below).
1) The only difference between the 6N138 and 139 is one is optimized for
TTL (6N138) and the other for CMOS (6N139). Either should work in this
application, and they are pin-compatible.
2) The 6N138/139 (8-pin part) has a different pin-out than the Sharp PC-900
(6-pin part). For the 6N138/139, connect as follows (again referencing the
- MIDI IN Connector pin 4 to 220 ohm resistor
- Other side of 220 ohm resistor to cathode of
external diode and pin 2 of 6N139 (anode)
- MIDI IN connector pin 5 to anode of external
diode and pin 3 of 6N139 (cathode)
- 6N139 pin 8 to +5V
- 6N139 pin 6 (output) to pull-up and PIC input
- 6N139 pin 5 to GND
- 6N139 pins 1, 4 and 7 are "no connect"
3) Yes, SPBRG=4 should give 31250 baud for 10MHz oscillator IF you set
BRGH=0 (and assuming you crystal is really oscillating at 10MHz).
4) You imply that you receive some bytes correctly and some incorrectly.
What percentage of bytes do you receive correctly? Are you using
interrupts to read the receive register or are you polling? If polling,
are you absolutely sure you are polling often enough (with 10MHz osc you
should have lots of time between bytes)? Are you checking the overrun
(OERR) and framing error (FERR) status bits (and clearing them afterwards)?
5) Are you using a small and known data stream to test the receive, or is
it "live" MIDI data. Try using the serial transmit pin (and the rest of
the output circuit from the GIF file) to send yourself known data (this
will not find baud rate problems, but will trouble-shoot receive hardware
I hope this helps. I will try to help if you have more questions.
On Sunday, May 17, 1998 12:19 PM, Catch-It
[SMTP:FILETREK.DEMON.CO.UK] wrote: Catch-It
> Can anybody help me? (no smart comments please :-)
> I am trying to get MIDI data into my 16C77. It kind of works, but seems
> get some wrong values through (I have examined the same stream on the PC
> it is being transmitted correctly)
> PIC is running at 10 Mhz (oscillator using 22pf capacitors). SPBRG is set
> 4 (which should give me the 31250 bps right?)
> The circuit I am using for input is basically a standard circuit (see the
> input section of http://www.borg.com/~jglatt/tech/midi.gif ), but I am
More... (looser matching)
- Last day of these posts
- In 1998
, 1999 only
- New search...