PDA

View Full Version : Timing issues with trying to do MIDI output with FullDuplexSerial



__red__
10-21-2011, 12:55 PM
When running the following program:



'************************************************* *************
'* miditest *
'************************************************* *************
CON
_clkmode = xtal1 + pll16x
_clkfreq = 80_000_000
MIDI_OUT_PIN = 20 'MIDI out pin
MIDI_IN_PIN = 21

OPEN_DRAIN = true 'if using the standard MIDI output circuitry TX must be open drain
INVERT_TX = false 'change if required

BASE_OCT = 0 'can go down to -2 or up

OBJ 'include 2 ViewPort objects:
ser : "FullDuplexSerial"
VAR
long onems
PUB main | n, mode

mode := 0
if INVERT_TX
mode |= 2
if OPEN_DRAIN
mode |= 4
ser.start(MIDI_IN_PIN, MIDI_OUT_PIN, 31250, mode)
waitcnt(cnt + clkfreq * 3)
onems := clkfreq / 1000
repeat
repeat n from 0 to 60
send_note(n, 500)
waitcnt(cnt + clkfreq * 10)

PRI send_note(pitch, duration)
'send NoteOn message
ser.tx($90)
ser.tx((BASE_OCT + 2) * 12 + pitch)
ser.tx($40)
'wait for a while
waitcnt(cnt + duration * onems)
'send NoteOff message
ser.tx($80)
ser.tx((BASE_OCT + 2) * 12 + pitch)
ser.tx($40)


My Logic analyzer shows that each serial character appears to take 5 seconds to send.

I've run my other code on the same board so i don't think it's a crystal issue.

Anyone have any insight as to my simple mistake?

Thanks,



Red

__red__
10-21-2011, 12:58 PM
It took my posting for all to see my idiocracy to see the issue:

80_000_000 with 16x.

I'd delete the thread but there is no delete function that I can see.

I now return you to your previous programming...

kuroneko
10-21-2011, 01:02 PM
Setting _clkfreq to 80M is fine (equivalent to _xinfreq = 5M). You simply start your serial device with the wrong parameters. Baud rate is last, mode second to last.

__red__
10-21-2011, 02:36 PM
I spoke too soon it seems, I don't seem to be able to decode it. I'll work on it some later this evening after work. Thanks for the feedback thus far.

Red