Shop OBEX P1 Docs P2 Docs Learn Events
SERIN/OUT Baud Modes Clarification — Parallax Forums

SERIN/OUT Baud Modes Clarification

YendorYendor Posts: 288
edited 2008-07-24 12:39 in General Discussion
Can someone help me clarify what·does the "OPEN"·refer to·for the baud modes in SERIN/OUT?

I had thought it was·"Open Collector" but doesn't seem to be, looking at the·asm code.

Here's the difference's in assembly of a subroutine·I'm using·- taking a quick look, it seems to·inverse the data !RA, but I thought that's what the "N" (inverted) was used for...

BAUD = "OTnnnn"
 293  0092  0425        CLRB MyOut                  
   294  0093  0C7E        MOV __PARAM4,#126             
        0094  002B
   295  0095  02EB        DJNZ __PARAM4,@$              
        0096  0010 0A95
   296  0098  0708        MOVB IND.1,__PARAM1.0         
        0099  0420 0608 0520
   297  009C  0200        MOV !RA,IND                   
        009D  0005
   298  009E  0503        STC                           
   299  009F  0328        RR __PARAM1                   
   300  00A0  02E9        DJNZ __PARAM2,@$-13           
        00A1  0010 0A93
   301  00A3  0018        BANK $00                      
  

··
BAUD = "Tnnnn"
   293  0092  0018        BANK $00                      
   294  0093  0425        CLRB MyOut                  
   295  0094  0C7E        MOV __PARAM4,#126             
        0095  002B
   296  0096  02EB        DJNZ __PARAM4,@$              
        0097  0010 0A96
   297  0099  0000        NOP                           
   298  009A  0000        NOP                           
   299  009B  0708        MOVB MyOut,__PARAM1.0       
        009C  0425 0608 0525
   300  009F  0503        STC                           
   301  00A0  0328        RR __PARAM1                   
   302  00A1  02E9        DJNZ __PARAM2,@$-13           
        00A2  0010 0

Thanks!

Rodney·

Comments

  • JonnyMacJonnyMac Posts: 9,216
    edited 2008-07-21 20:54
    I've added comments to an OTxxxx SEROUT statement that might be helpful.

    354  00AC  0C58        MOV __PARAM1,#"X"              ;  SEROUT RA.0, OT9600, "X"
            00AD  0028
       355  00AE  0C0A        MOV __PARAM2,#10               ;  start + 8 bits + stop
            00AF  0029
       356  00B0  0CFA        MOV FSR,#__TRISA               ;  point to "shadow" tris port
            00B1  0024
       357  00B2  005F        MODE $0F
       358  00B3  0400        CLRB IND.0
       359  00B4  0200        MOV !RA,IND                    ; make TX an output for start bit
            00B5  0005
       360  00B6  0405        CLRB RA.0                      ; this creates the start
       361  00B7  0C02        MOV __PARAM3,#2                ; bit delay
            00B8  002A
       362  00B9  0C9D        MOV __PARAM4,#157
            00BA  002B
       363  00BB  02EB        DJNZ __PARAM4,@$
            00BC  0010 0ABB
       364  00BE  02EA        DJNZ __PARAM3,@$-3
            00BF  0010 0ABB
       365  00C1  0000        NOP
       366  00C2  0000        NOP
       367  00C3  0000        NOP
       368  00C4  0708        MOVB IND.0,__PARAM1.0          ; grab the bit to send
            00C5  0400 0608 0500
       369  00C8  0200        MOV !RA,IND                    ; write it to tris bit (1 = float, 0 = low)
            00C9  0005
       370  00CA  0503        STC                            ; pad stop bit
       371  00CB  0328        RR __PARAM1                    ; rotate for next bit to send
       372  00CC  02E9        DJNZ __PARAM2,@$-21
            00CD  0010 0AB7
       373  00CF  0018        BANK $00
    


    !RA is the TRIS port (IO direction) for RA -- not the inverted data of RA. The reason the code grabs the "shadow" tris port is that the SX28 does not allow direct reads of tris, and the code has to ensure that the IO state of the other pins is not affected by the SEROUT. In the end, the stop bit (1) will cause the IO pin to float.

    Post Edited (JonnyMac) : 7/21/2008 9:02:57 PM GMT
  • YendorYendor Posts: 288
    edited 2008-07-23 17:14
    Thanks so much for the feedback, Jon.·

    It made me realize I need to not (!)·assume with assembler!

    I've been using the simulator to see what's happening, but I'm still not sure on·how does the SX 'know' that the output port is open collector?

    Is it because the output port is·initialized as an input, and then it 'outputs' with·mov !RA, IND command, instead of using TRIS_A = %0000 where the program starts?

    Where all of this is leading is using open collector for MIDI out on the UART VP.
    I just can't get my head around this yet!· I figure if I can see what Bean is doing with SX/B, I can do the same with the UART VP.

    the UART VP·has the following code for the output configuration:
    rx_pin EQ ra.2
    tx_pin EQ ra.3
    ;...
    mov  ra, #%1011  ;initialze port RA
    mov  !ra,#%0100  ;Set RA's inputs and outputs
    

    So, for TRIS, if 1 = input, 0 = output
    Port·2 is initialized as an output, and then set as an input
    Port 3 is initialized as an input, and then set as an output

    I'm not sure why·he's doing this...can anyone add any enlightenment for me?··(of course those are the only two lines that Gunther doesn't touch upon).

    I have midiout working using SEROUT, and declaring the Tx pin as a var
    MidiOut VAR RA.1 ' midi serial output
    

    So, that would lead me to think I that I need to have my UART VP Tx·output defined as inputs, for Open Collector.

    Am I making this too complicated?

    Many thanks for any feedback!

    Rodney, the MIDIot
  • JonnyMacJonnyMac Posts: 9,216
    edited 2008-07-23 17:40
    Unless you override the compiler with an OUTPUT directive in the PIN definition, all ports are initialized as inputs and that state is saved in the shadow registers. The shadow registers get updated by any command that affects them.

    Why an open collector output for MIDI? MIDI uses a current loop with optical couplers, so by its construction there is electrical isolation; driving the outputs both directions will not harm a properly-constructed MIDI system.

    [noparse][[/noparse]Edit] In the event you really need open-collector output I've attached a framework that should get you going.
    [noparse][[/noparse]Edit] Fixed DELAY_MS subroutine; uses ISR timing now.

    Post Edited (JonnyMac) : 7/23/2008 7:54:50 PM GMT
  • YendorYendor Posts: 288
    edited 2008-07-23 18:42
    Thanks Jon,

    I apologize for being in this rut, but as far as open collector, isn't that what "O" is for in the baud mode?
    All of the Basic Stamp MIDI code has this as well.

    I guess I'm thinking too much again, but wouldn't a·current loop require it to be open collector on TX, as the Rx is optically isolated?

    I also found several references, here's one noting this:
    http://www.harmony-central.com/MIDI/midi-cable.txt

    MIDI IN :
    · 1- n.c.
    ··4- anode of optocoupler
    ··2- n.c. <<<--- !!!! Different for MIDI OUT
    ··5- cathode of optocoupler
    ··3- n.c.
    MIDI OUT/THRU:
    · 1- n.c.
    ··4- +5v thru resistor
    ··2- local ground
    ··5- TTL open collector output
    ··3- n.c.
    Basically, through my experiments, if I specify my TXOut as "output", it freaks out my synth.· If I leave as input, and do SEROUT "OT", it works!

    It also freaks out when I use the "PIN OUTPUT" reference, but· "PIN INPUT" works fine. (e.g. using PIN INPUT, and using·SEROUT on the input pin)

    Hence, I'm thinking there's something similar going on w/ the·UART VP, and can't get my head around the OC thing.

    All of my 'commerical' midi devices work great on this synth.· I'll post my findings when I get there, but sounds like you're already successful with this, which leads me to think I'm heading down a wrong path...·which isn't so bad, as long·as I'm having fun and have great interaction w/ the forum members!

    Your (and anyone else's)·input is much appreciated!

    Thanks!

    Rodney
  • JonnyMacJonnyMac Posts: 9,216
    edited 2008-07-23 19:34
    Forgive me, I haven't experimented with MIDI output for a long time and having just gone back to look at old experiments find that they are indeed using "Open" baud mode.

    Yes, the "O" is for Open, it's the next letter that counts. For MIDI using high-level SEROUT you need to specify a baud parameter of OT31250; the T indicates True mode where the idle state of the line is 1 (which is usually pulled up in Open mode), this is akin to Open-Collector (though it's actually called Open-Source in the SX due to the construction of the IO pin).

    It might be helpful if you posted your entire program -- sometimes working with fragments can put the rest of us at a serious disadvantage.

    [noparse][[/noparse]Edit] Since I chided you about posting a program, I've attached a simple MIDI program that uses high-level code (not test, I don't have a MIDI instrument).

    Post Edited (JonnyMac) : 7/23/2008 7:53:56 PM GMT
  • YendorYendor Posts: 288
    edited 2008-07-23 19:54
    Thanks Jon,

    Another point to this is that I'm not using the two inverters/buffers on the MIDI spec for the TxOut (the latter one is a 75LS05, which is open collector), as I'm assuming that the SX can be used w/o them... I'm reducing parts, but I need to experiment a bit more, as that could be part of my problem...

    I think I know where to go from here - I will definately provide feedback...
  • JonnyMacJonnyMac Posts: 9,216
    edited 2008-07-23 20:30
    You don't need the inverters. You'll typically see those in circuits on the downstream side of the opto -- this allows the MIDI THRU output to sink enough current for a zero bit, and takes the load of the serial input to the local host. Now, if you're going to create a device that uses MIDI in and not buffer the data through the processor then you should use the inverters. I get the idea, though, that your SX is the MIDI master which means you can connect to the MIDI line directly. Keep in mind that when the MIDI output pin is active (low) it will be sinking about 20 mA (well within SX limits).
  • YendorYendor Posts: 288
    edited 2008-07-24 04:40
    I'm hoping I won't need them, too!

    Can you help me understand what you mean by?
    Now, if you're going to create a device that uses MIDI in and not buffer the data through the processor then you should use the inverters.
    Isn't this referring to·two different types of buffers?· I consider the inverters a buffer to protect the processor data lines - (e.g. for appropriately sinking/sourcing the current, or enabling OC on a uart/processor pin that doesn't have it), whereas buffering the data through the processor is temporarily storing the data, until it can be appropriately·used (as in the Rx UART VP).·
    ·Keep in mind that when the MIDI output pin is active (low) it will be sinking about 20 mA (well within SX limits).
    ····· Wouldn't a 5mA current loop be 5mA no matter what?·· Looking at the schematic from Midi out to Midi in, you have 5v supply, a 220 ohm resister, a diode voltage drop (opto coupler·- assume 0.7v), and two more 220 ohm resistors.··· This would be 4.3V/660 ohms = 6.5mA, unless I'm missing something...

    My project will eventually use both Midi TX and RX - something like an simple arpeggiator initially.

    I'm·focusing on the Midi TX part (using the VP).· The Rx you have already·done for us (many thanks for that!)

    Sorry for stretching this thread out beyond its initial context, and again appreciate the·help!

    Rodney
    ·
  • JonnyMacJonnyMac Posts: 9,216
    edited 2008-07-24 06:28
    What I meant by buffering is receiving a byte in and then retransmitting it -- a software buffer, so to speak. You might want to do this to interleave you messages in stream coming in if that's required (I think this process is called store-and-forward).

    My mistake on the MIDI loop current; sorry, it is much less than 20 mA (I calculate 7.9 mA).

    To be candid, I think this thread has become somewhat long-winded because you present everything in fragments, not allowing the rest of us to see the whole picture -- that makes things tough....
  • YendorYendor Posts: 288
    edited 2008-07-24 12:39
    I too, cringe at my thread - I wish I could break it out... In my cluttered mind, I had a direction I was trying to head, and had a few right angle turns in there, but will learn next time. I was trying to see if there was a logical explaination w/o pushing too much code, as I just wanted some help on the "Open Collector" concept, rather than an entire working program right now.

    Thanks!
Sign In or Register to comment.