PDA

View Full Version : hserin and 16f876



novino
- 14th October 2009, 17:59
Hello,
I've been trying to figure out how to build a midi shield with a 16f876. I'd like to use midi messages to control servos and lights, and control sounds from the pic, via the midi protocol. I just found the hardware section on Tom Igoe's page, and it works fine for the midiout, but receiving midi looks more tricky. I've been interfacing successfully with pure data via a midi to usb interface. Pure data receives the bytes perfectly with either hserout and serout2 methods. But when I try to receive midi bytes from pure data and to send them again from the pic, it looks like the datas are not correct.

here is the code:
16f876@20mhz, using mecanique bootloader. Oscillator looks ok

define loader_used 1
define osc 20
define HSER_RCSTA 90h
define HSER_TXSTA 24H
define HSER_BAUD 31250

adcon1=7
include "modedefs.bas"
trisb=0
control var byte
pitch var byte
streng var byte

main:
hserin [control,pitch,streng]
hserout [$90,pitch,streng]

'serin2 portc.0,12,[control,pitch,streng] the other method
'serout2 portc.0,12,[$90,pitch,streng]

goto main


With both methods, the pic seems to loose datas, or clock pace. I just don't understand what's going wrong.
If anyone has any idea, I would be very interested in understanding why sending midi is so easy as receiving it looks so difficult !
Thank you for any reply.

Darrel Taylor
- 14th October 2009, 18:36
It's probably getting out of sync with the data.
And there's no way to re-sync it.

Try it like this ...
hserin [wait($90), pitch, streng]

novino
- 15th October 2009, 08:26
Thank you Darrel,
Actually, I've been trying to wait for a $90 byte too, but in this case, it seems that the pic doesn't see the start byte at all (or only from time to time)
Do you see any other way to code a more reliable "midi receive" routine ? Has it something to do with buffering the incoming datas ?
Thanks again for your help
Nicolas

Darrel Taylor
- 15th October 2009, 20:37
You mentioned before that you saw Tom Igoe's MIDI page.
Are you using the Opto-Isolator on the input? Is it a 6N138?

Or is it converting the current loop to voltage another way?
<br>

novino
- 16th October 2009, 11:37
Yes I've been using an opto-isolator, but it was a 6n137. Does it make any difference with the 138 ?

Darrel Taylor
- 17th October 2009, 01:11
Yes I've been using an opto-isolator, but it was a 6n137. Does it make any difference with the 138 ?
It may.

The 137 has a higher input current requirement than the 138.
And I think MIDI uses a 5mA current loop for it's signal, which is right at the absolute minimum specified for the 137.

It may not be creating a good signal on the other side.
Can't say for sure though.
<br>

novino
- 20th October 2009, 12:13
Ok, thanks to you I found the problem ! The 6n138 and 137 don't have the same wiring . I got it working with by correcting the connection of the opto isolator
(basically, it's pin 5 to ground, 6 to Rx , 1,5kO res between 6and 7, and 7,8 to +5Vcc, the other pins are the same as 138)

I still have speed issues. The datas are received, but at a very slow pace(about a good midi pack by second). Do you see any way to improve the speed, to get a more "real-time" application ?