PDA

View Full Version : SERIN MIDI out of Synch?



jncortes
- 30th June 2007, 19:14
Hi Guys,

a typical 3 bytes of DATA in MIDI are 90h ,30h, 45h, for Command, Note, Velocity.
when I used the following statements to grab the standard 3 MIDI bytes from the USART:

HSERIN [var1]
HSERIN [var2]
HSERIN [var3]

I get inconsistent values, for each note played, and some times the expected value. AS if there was a baud synch problem.

Could it be that HSERIN does not work well with 31250 baud rate?

Thanks!

mister_e
- 30th June 2007, 19:24
HSERIN work well @ midi baudrate if you set it correctly and if you're using a good crystal value. Use my PicMulticalc to see what type of error % you may have with your current OSC speed.

If you're using the internal OSC... yes you will have problem.

Sure it will'nt solve the problem, but you can use a single line for HSERIN.

Maybe not a bad idea to include the HSER_CLROERR 1 Define at the top of your program

botsmaker
- 9th June 2009, 20:08
I have been able to control solid state relays with midi using a midi sequencer called Anvil Studio (free). I use a soundcard with a gameport/midi 15 pin connector (Siig soundwave 5.1 PCI). The serin2 commands works well. I couldn't get good results with Hserin. The byte order would change after receiving 2 bytes. This program works. The commands are sent as notes. The first byte turns on or off the note. The second byte is the note and the third byte, I don't use. Set Anvil studio to send on channel one, MPU-401. I'm building an artbot that turns on and off old hard drives. The hard drives make a nice sound during there start up sequence.

@ device pic16F877, pwrt_on, protect_off, wdt_on, HS_OSC

' program to turn on/off outputs using midi commands
' channel 1 midi, midi notes 60 to 83
' output is inverted for turn on solid state relays

INCLUDE "modedefs.bas"

DEFINE OSC 20


TRISA = %00000000

TRISB = %00000000

TRISC = %10000001

TRISD = %00000000

byte1 VAR BYTE
byte2 VAR BYTE
byte3 VAR BYTE

linkon VAR PORTC.0

alloff: 'turn off all ports
High PORTC.4

High PORTD.7
High PORTD.6
High PORTD.5
High PORTD.4
High PORTD.3
High PORTD.2
High PORTD.1
High PORTD.0

High PORTB.7
High PORTB.6
High PORTB.5
High PORTB.4
High PORTB.3
High PORTB.2
High PORTB.1
High PORTB.0

High PORTE.2
High PORTE.1
High PORTE.0

High PORTA.5
High PORTA.3
High PORTA.2
High PORTA.1
High PORTA.0



loop:
SerIn2 PORTC.7,12,[byte1,byte2,byte3]
Toggle PORTC.4


SerOut PORTC.5,N9600,[#byte1," ",#byte2," ",#byte3,10,13]

makemidi:

IF byte1 = 144 Then turnon
IF byte1 = 128 Then turnoff

turnoff:

IF byte2 = 60 Then High PORTD.7
IF byte2 = 61 Then High PORTD.6
IF byte2 = 62 Then High PORTD.5
IF byte2 = 63 Then High PORTD.4
IF byte2 = 64 Then High PORTD.3
IF byte2 = 65 Then High PORTD.2
IF byte2 = 66 Then High PORTD.1
IF byte2 = 67 Then High PORTD.0

IF byte2 = 68 Then High PORTB.7
IF byte2 = 69 Then High PORTB.6
IF byte2 = 70 Then High PORTB.5
IF byte2 = 71 Then High PORTB.4
IF byte2 = 72 Then High PORTB.3
IF byte2 = 73 Then High PORTB.2
IF byte2 = 74 Then High PORTB.1
IF byte2 = 75 Then High PORTB.0

IF byte2 = 76 Then High PORTE.2
IF byte2 = 77 Then High PORTE.1
IF byte2 = 78 Then High PORTE.0
IF byte2 = 79 Then High PORTA.5
IF byte2 = 80 Then High PORTA.3
IF byte2 = 81 Then High PORTA.2
IF byte2 = 82 Then High PORTA.1
IF byte2 = 83 Then High PORTA.0

GoTo loop

turnon:

IF byte2 = 60 Then Low PORTD.7
IF byte2 = 61 Then Low PORTD.6
IF byte2 = 62 Then Low PORTD.5
IF byte2 = 63 Then Low PORTD.4
IF byte2 = 64 Then Low PORTD.3
IF byte2 = 65 Then Low PORTD.2
IF byte2 = 66 Then Low PORTD.1
IF byte2 = 67 Then Low PORTD.0

IF byte2 = 68 Then Low PORTB.7
IF byte2 = 69 Then Low PORTB.6
IF byte2 = 70 Then Low PORTB.5
IF byte2 = 71 Then Low PORTB.4
IF byte2 = 72 Then Low PORTB.3
IF byte2 = 73 Then Low PORTB.2
IF byte2 = 74 Then Low PORTB.1
IF byte2 = 75 Then Low PORTB.0

IF byte2 = 76 Then Low PORTE.2
IF byte2 = 77 Then Low PORTE.1
IF byte2 = 78 Then Low PORTE.0
IF byte2 = 79 Then Low PORTA.5
IF byte2 = 80 Then Low PORTA.3
IF byte2 = 81 Then Low PORTA.2
IF byte2 = 82 Then Low PORTA.1
IF byte2 = 83 Then Low PORTA.0

GoTo loop

End