Midi input, using hserin?


Closed Thread
Results 1 to 17 of 17
  1. #1
    Join Date
    Apr 2006
    Posts
    92

    Default Midi input, using hserin?

    Hi,

    I'm trying to receive midi input using the pic18f452.

    I guess I would use HSERIN. Are there any examples? Has anyone here done this?

    Thanks for any info.

    Tony

  2. #2
    Kees Reedijk's Avatar
    Kees Reedijk Guest


    Did you find this post helpful? Yes | No

    Default MIDI in

    Here's an example using serin2, you have to use a 20MHz crystal:
    It reads in MIDI data and sends it out to a serial port, worked fine for me.

    @ device pic16F628A, pwrt_on, mclr_on, protect_off, wdt_on, HS_OSC

    INCLUDE "modedefs.bas"

    DEFINE OSC 20

    CMCON = 7 ' PortA = digital I/O

    PORTA = %00000001
    TRISA = %00000000
    PORTB = %00000000
    TRISB = %00000000

    test1 VAR BYTE
    test2 VAR BYTE
    mdata VAR BYTE

    loop:
    SerIn2 PORTA.0,12,[test1,test2,mdata]
    SerOut PORTB.7,N9600,[" midi : ",#test1," ",#test2," ",#mdata,10,13]
    GoTo loop

    end
    Last edited by Kees Reedijk; - 13th July 2006 at 22:48.

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    do a google search and you'll find, at least the right baudrate

    Search with MIDI in the forum search tool and you'll find some info

    Same for HSERIN

    It can definately be done using a PIC and PBP, some homework have to be done first.

    If your PIC have a USART, there's no reason to use SERIN or else software solution.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Apr 2006
    Posts
    92


    Did you find this post helpful? Yes | No

    Default

    Hi,

    Thanks. Why not use HSERIN? Isn't that more appropriate?

    Yes, the google search will only yield midi output examples, nothing on midi input for picbasic pro (unless I'm overlooking something).

    Thanks again for the help, I appreciate it very much.

    Tony

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Sorry if it wasn't really clear, Sure HSERIn is appropriate where SERIN it's not really to reach the baudrate you want @4MHZ.

    The internal USART also offer you the Interrupts where the software SERIN,DEBUG don't

    Usefull when your software have to do something else than wait... Even the Timeout of SERINx may be used but with the MIDI baudrate i can't say you'll never miss any character.

    HSERIN within a ISR is the way to go.

    The Kees Reedijk example is something to play 'round.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    Join Date
    Apr 2006
    Posts
    92


    Did you find this post helpful? Yes | No

    Default

    Hi,

    Thanks. Yes, I'm going to need 20 Mhz osc. for midi.

    Any examples on how to set up hserin code?

    Thanks again, I appreciate.

    Tony

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    use the calc i did few month/years ago.. FREEBIES
    http://www.picbasic.co.uk/forum/atta...6&d=1118138371

    click on the button at the right twice and you're in business.

    Now using the USART and this calc, you may discover that it will be possible to acheive a nice error % even with a 4MHZ clock.

    HTH
    Last edited by mister_e; - 14th July 2006 at 17:35.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  8. #8
    Join Date
    Apr 2006
    Posts
    92


    Did you find this post helpful? Yes | No

    Default

    Hi,

    That's cool. Thank you.

    I'm wondering if anyone could refer me to examples of HSERIN code.

    I'm sending midi out like this:

    hserout [$90, note, Velocity] 'send midi note & velocity out on channel 1

    And with another pic18f452 I would just like to receive those transmitted variables; "note" and "Velocity".

    Any ideas how I can proceed?

    Thanks again,

    Tony
    Last edited by TonyA; - 14th July 2006 at 19:18.

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


    Did you find this post helpful? Yes | No

    Default

    I think everyone's avoiding the original question because it just seems too obvious.

    If you're sending it with

    hserout [$90, note, Velocity]

    then you'd receive it with

    hserin [wait($90), note, Velocity]
    <br>
    DT

  10. #10
    Join Date
    Apr 2006
    Posts
    92


    Did you find this post helpful? Yes | No

    Default

    Yes, that's what I needed. Thanks.

    What is the "wait", a variable?

    When I try to compile it in micro code studio I get an error for

    HSerIn [wait($90), note, Velocity]

    it says "expected ']'.

    Thanks,
    Tony
    Last edited by TonyA; - 14th July 2006 at 20:46.

  11. #11
    Join Date
    Apr 2006
    Posts
    92


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by TonyA
    Yes, that's what I needed. Thanks.

    What is the "wait", a variable?

    When I try to compile it in micro code studio I get an error for

    HSerIn [wait($90), note, Velocity]

    it says "expected ']'.

    Thanks,
    Tony
    Hi Sorry, that works. I had to fix my code.

  12. #12
    Join Date
    Jul 2006
    Location
    USA
    Posts
    26


    Did you find this post helpful? Yes | No

    Default

    I'm sure the hserin will work, but I like to read the port directly. Here is a
    program that I wrote 3 years ago for a 909 kick drum copy that I built. It worked
    great. It only responded to one MIDI channel and one note, but I think you will
    be able to see what's happening and figure out how to implement your design.
    Attached Files Attached Files

  13. #13
    Join Date
    Apr 2006
    Posts
    92


    Did you find this post helpful? Yes | No

    Default

    That's cool, thank you. I'll let you know how it works out. Thanks again.

    Tony

  14. #14
    Join Date
    Feb 2006
    Posts
    3


    Did you find this post helpful? Yes | No

    Default Hserin

    Did you ever got this to work?

  15. #15
    Join Date
    Apr 2006
    Posts
    92


    Did you find this post helpful? Yes | No

    Default

    Yeah, this should work. I don't think I ever built the circuit though. I was thinking about making a midi receiver but I never did.

    Let us know if you try it.

  16. #16
    Join Date
    Feb 2006
    Posts
    3


    Did you find this post helpful? Yes | No

    Default ok

    Well, I'm working on a MIDID receiver based on HSERIN but not sure of a few things.

    1. MIDI seems to be active low so when no data= +5V. Data = 0V

    So I'm not sure if USART (16F88) if compatible or do I have to invert polarity.

    2. MIDI seems to come from the legacy of Motorola based arquitectured (Big endian) Pics are Little endian ( I think this is true) so ata has to be inverted.


    So any info would help!

  17. #17
    Join Date
    Apr 2006
    Posts
    92


    Did you find this post helpful? Yes | No

    Default

    Someone else would probably be able to help you more with this.

    I believe you don't have to invert the data. (I know that you don't have to invert the data when sending midi out from a pic, so I'm assuming you don't have to invert the data when receiving as well.)

    (There are some old diagrams on the web that show the need for using a 7404 hex inverter chip to properly send midi data out of the pic. It was later found that the PIC does not need this extra inverter chip to send midi out. Because it can send non-inverted serial data. I've never inverted the signal when making midi controllers (sending midi)).

Similar Threads

  1. Sony LanC Program
    By l_gaminde in forum Code Examples
    Replies: 2
    Last Post: - 25th September 2009, 18:51
  2. How to HSERIN and MIDI code?
    By francolok in forum Serial
    Replies: 1
    Last Post: - 18th December 2008, 16:59
  3. Midi, Interrupts and Pic better than SX28?
    By Lajko in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 27th September 2008, 00:26
  4. Timing input pulses and re-outputting them
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th February 2007, 01:50
  5. Using LEDs as light sensors
    By skimask in forum Code Examples
    Replies: 3
    Last Post: - 30th December 2006, 22:19

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

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