hserin and 16f876


+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2008
    Posts
    5

    Smile hserin and 16f876

    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:
    [email protected], 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.

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    It's probably getting out of sync with the data.
    And there's no way to re-sync it.

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

  3. #3
    Join Date
    Feb 2008
    Posts
    5

    Default hserin and 16f876 to midi

    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

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    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>
    DT

  5. #5
    Join Date
    Feb 2008
    Posts
    5

    Default

    Yes I've been using an opto-isolator, but it was a 6n137. Does it make any difference with the 138 ?

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    Quote Originally Posted by novino View Post
    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>
    DT

  7. #7
    Join Date
    Feb 2008
    Posts
    5

    Thumbs up it works at last

    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 ?

Similar Threads

  1. Simple Hserin test
    By macinug in forum Serial
    Replies: 1
    Last Post: - 14th January 2009, 20:42
  2. Hserin
    By Christopher4187 in forum General
    Replies: 3
    Last Post: - 20th March 2006, 23:09

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts