Shop OBEX P1 Docs P2 Docs Learn Events
SX/B serin command — Parallax Forums

SX/B serin command

jwillisjwillis Posts: 8
edited 2005-05-17 19:22 in General Discussion
I have designed a MIDI decoder board based on the SX-28 programed in SX/B.· The SX recieves a MIDI data stream at 31500 baud 8 data bits 1 stop bit using SERIN,·processes··each byte of the 3 byte message as they arrive,·and with some processing decodes the note on and off information and enables or disables a bit in an external 64 bit register to drive organ pipes.

The system works well as long as there is a slight pause between bytes (1 bit length)·to allow for processing. ·My keyboard encoders are based on the basic stamp 2-SX, and thus the 3·bytes of the midi message·are slightly separated using SEROUT. ·Midi·messages from a computer, however, come out as a continuous 3 byte·data stream without pause except for the stop bit of each byte.· The SX cannot seem to ·keep up using SERIN·and data is·lost causing chaos at the output drivers.

I cannot easily change the UART parameters in the computer to add another stop bit.· Can SERIN be used in this circumstance, or will it be necessary to go to an interrupt driven·UART subroutine?

Thanks

Jwillis

·

Comments

  • BeanBean Posts: 8,129
    edited 2005-05-15 04:01
    It depends on how much processing you are doing with each byte as the SX receives it.
    What clock speed are you running the SX at ?
    You can try a faster clock speed to see if that helps.
    If not, an interrupt receive routine would be best.
    I think Jon Williams is working on some midi stuff with the SX. Maybe he'll chime in.
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video Display Module" Available Now.

    www.sxvm.com

    "Great people talk about great things, average people talk about average things, small people talk about other people."
    ·
  • Guenther DaubachGuenther Daubach Posts: 1,321
    edited 2005-05-15 12:46
    When you are receiving MIDI data from a computer, make sure that it is not sending with running status. In this mode, one status byte is sent (e.g. Note On), followed by any number of pairs of bytes (e.g. Note + Velocity. Note + Velocity. etc.) as long as there is no need to change the status. When your SX/B program always expects three bytes per MIDI message, it will fail in this case.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Greetings from Germany,

    G
  • jwillisjwillis Posts: 8
    edited 2005-05-15 16:32
    Running status has been taken into account. That was initally a problem but the software was modified to work with running status. What is happening now seems to be the inability to process enough between serin commands to allow serin to catch the next byte in the midi message. The SX-28 is clocked at 50 mhz. I have not had much experience in SX/B programming esp with interrupts, and there is scant detailed information about SX/B syntax that is in an easily referenced and understandable format. Any sources for such information or canned interrupt driven UART subroutines that would be easy to utilize?
  • KenMKenM Posts: 657
    edited 2005-05-15 17:34
    www.sxlist.com "tons" of code examples in assembly, which you can insert into SXB
    jwillis said...
    ·Any sources for such information or canned interrupt driven UART subroutines that would be easy to utilize?
    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    トヨタは すばらし です!!
  • BeanBean Posts: 8,129
    edited 2005-05-15 22:21
    Can you post your code ? Maybe we could suggest some optimizations.
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video Display Module" Available Now.

    www.sxvm.com

    "Great people talk about great things, average people talk about average things, small people talk about other people."
    ·
  • Guenther DaubachGuenther Daubach Posts: 1,321
    edited 2005-05-15 22:51
    To be honest, so far, I never programmed a MIDI application for the SX using SX/B but I did a lot in Assembly.

    In my applications, I don't process anything "between" the bytes (except checking for new status bytes to handle running status), i.e. I first receive all bytes to complete a MIDI message into a buffer, and then do the necessary processing. The processing code always reads the three buffered message bytes, i.e. it does not "know" about running status.

    Instead, this is handled by the receive routine filling that buffer. IOW - when a byte is received with bit 7 set, this is assumed to be a new status byte to be copied into the first byte of the buffer (byte 0). Next, two more bytes are read and copied into the buffer (bytes 1 and 2). If the receive routine gets the first byte with bit 7 clear, it assumes running status, saves this in byte 1 of the buffer, and expects just one more byte to be saved in byte 2 of the buffer, leaving byte 0 (the status) unchanged.

    MIDI data comes in at 31,250 Baud, i.e. the bit period is 32 µs. With an SX clocked at 50 MHz, instruction cycles take 20 ns which means that you can execute "tons" of instructions between two ISR calls to handle the MIDI UART code, and I never had a problem with this.

    It is important though, that you don't call a routine for receiving a byte putting the mainline program on hold until the complete byte has been received. Instead, the UART receive code in the ISR should set an "RX_Avail" flag when it has received a new byte. After having processed the previously received byte, the mainline program should enter into a loop waiting until the ISR has set this flag, clear it, and then process the new byte while the ISR code takes care of receiving the next one.

    This way, you should have more than enough processing time in the mainline program.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Greetings from Germany,

    Günther
  • jwillisjwillis Posts: 8
    edited 2005-05-16 01:23
    Gunther:

    Is your UART subroutine based on periodic interrupts by the RTC to allow other processing to go on while waiting to sample the serial data stream?


    Jim
  • Guenther DaubachGuenther Daubach Posts: 1,321
    edited 2005-05-16 08:33
    Jim,

    yes, the UART code is executed in an interrupt service routine, periodically called on RTCC roll-overs. This is the "classical" UART Virtual Peripheral for the SX, available from various resources. When you download www.parallax.com/dl/src/prod/sx/ProgSXEdPre.zip which contains the source codes published in my book, you can find the UART code in TUT040.SRC.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Greetings from Germany,

    G
  • BeanBean Posts: 8,129
    edited 2005-05-16 10:52
    Jim,
    Jon has code posted in the "Projects" forum. Look for "MIDI Receiver with SX/B".
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video Display Module" Available Now.

    www.sxvm.com

    "It's not getting what you want, it's wanting what you've got."
    ·
  • jwillisjwillis Posts: 8
    edited 2005-05-17 04:46
    I have a copy of TUT40 and Jon's midi receiver program. I think that I will try an interrupt driven UART subroutine.
    I'll let all of you know how this comes out. When I have it working I will post the code. I also have a circuit board layout using express.pcb which I will also post when everything is working.

    Thanks

    Jim Willis
  • Guenther DaubachGuenther Daubach Posts: 1,321
    edited 2005-05-17 14:54
    Jim,

    BTW for 31,250 Baud (MIDI), the constants in TUT040.SRC should be defined as follows:

    baud_bit = 3
    start_delay = 13
    int_period = 200

    Good Luck!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Greetings from Germany,

    G
  • jwillisjwillis Posts: 8
    edited 2005-05-17 19:22
    Gunther


    Could you give me an example of the SX-B code to test the rx_flag and obtain the rx_byte?

    Thanks


    Jim Willis
Sign In or Register to comment.