MIDI frame generator with EasyHDL

Discussion on both general simulation and Proteus VSM microcontroller simulation.
Post Reply
chimimic
Expert User
Posts: 508
Joined: Tue 2006-04-11 13:31
Location: France
Contact:

MIDI frame generator with EasyHDL

Post by chimimic »

Hi,

I want generate MIDI data (SYSEX) with logic EasyHDL generator, but I'm not sure how to do, as it is the first time I use this langage. I tried to start with the samples provided in samples dir of Proteus (serial data and QPSK), and I read help related to this langage. But I didn't found how make my "EasyHDL code" to work.

For my first attempt, I tried to output following sysex data :
0xF0,0x7F,0x00,0x06,0x06,0xF7
(6 bytes, starting with $F0 and ended by $F7)

Code: Select all

// MIDI Sysex generator

// Define data to be output
DATA 0xF0,0x7F,0x00
DATA 0x06,0x06,0xF7
DATA REPEAT

// Define the baud rate
FLOAT BAUD=31250
FLOAT BITTIME=1.0/BAUD

// Declare working variables
INT DataOut
INT i,j,d
TIME td

// Top level
OUT = 1
SLEEP FOR 10m

LOOP:
READ DataOut,td
GOSUB OUTDATA
SLEEP FOR td
GOTO LOOP

// Output data
OUTDATA:

FOR i=1 TO LEN(d)
  d = DataOut[i]
  GOSUB OUTCHAR
NEXT I

RETURN

// Bit Bang a single character
// 1 Start bit, 1 Stop bit and no
// parity are assumed.
OUTCHAR:

// Start bit
OUT = 0
SLEEP FOR BITTIME

// Data bits
FOR j=0 TO 7
 OUT = d & (1 << j)
 SLEEP FOR BITTIME
NEXT j

// Stop bit
OUT = 1
SLEEP FOR BITTIME

RETURN

I think I have understood how work exemple provided in serial data sample, that make usage of strings data ("hello world"). But I can't find how to "translate" this sample to my case, that only make usage of bytes.

Please, does someone can help me to make this to work ?
Any help will be really appreciated.

(I know that some part of the code is not valid, just written to show what I tried)

Kindest regards,
Remy
Ettore
Labcenter Staff
Posts: 2932
Joined: Fri 2006-03-03 11:56
Location: Milan
Contact:

Re: MIDI frame generator with EasyHDL

Post by Ettore »

Look at the attached file. Hope it helps.
Attachments
Easy_HDL_test.zip
(4.48 KiB) Downloaded 96 times
Kind regards,
Ettore Arena - Labcenter Electronics.
chimimic
Expert User
Posts: 508
Joined: Tue 2006-04-11 13:31
Location: France
Contact:

Re: MIDI frame generator with EasyHDL

Post by chimimic »

Thank you very much Ettore, your help is appreciated.
I now understand how it works about DATA / READ / OUT, and I have good thing to start and develop this code :D
Remy
chimimic
Expert User
Posts: 508
Joined: Tue 2006-04-11 13:31
Location: France
Contact:

Re: MIDI frame generator with EasyHDL

Post by chimimic »

Hi Ettore,

all work as wanted, in continuous mode.

To generate an isolated (unique) message (six bytes long in my case), I removed the line DATA REPEAT, to indicate that I don't want circular reading of DATA content.

New code is following :

Code: Select all

// Define data to be output
DATA 0xF0,0x7F,0x00
DATA 0x06,0x06,0xF7
//DATA REPEAT   // "data repeat" removed
After removed this line, a unique sequence is sent as expected, but an error message "OUT OF DATA" is generated just after, and simulation stop (in digital graph or in real time). I used your own code, unchanged - except for DATA REPEAT line.

VSM Help file talk about the REPEAT keyword, but I don't see anything about a not continuous usage.
Please, can you tell me if I have to change something at other place in the EasyHDL code, for example delete the LOOP / GOTOLOOP statement or similar change ?

Thanks again for your help,
Remy

Edit :
following code seems to work, but I think it's not the best solution. I have added the "i" variable to limit the DATA to be read only for 6 bytes.

Code: Select all

// MIDI Sysex generator

// Define data to be output
DATA 0xF0,0x7F,0x00,0x06,0x06,0xF7

// Define the baud rate
FLOAT BAUD=31250
FLOAT BITTIME=1.0/BAUD

// Declare working variables
INT DataOut
INT i,j,d

// Top level
OUT = 1
SLEEP FOR 4106u

LOOP:
  i = i + 1
  if i > 6 THEN GOSUB THEEND
  READ DataOut
  GOSUB OUTDATA
GOTO LOOP

THEEND:

END

// Output data
OUTDATA:
  d = DataOut
  GOSUB OUTCHAR
RETURN

// Bit Bang a single character
// 1 Start bit, 1 Stop bit and no
// parity are assumed.
OUTCHAR:
  // Start bit
  OUT = 0
  SLEEP FOR BITTIME
  // Data bits
  FOR j=0 TO 7
    OUT = d & (1 << j)
    SLEEP FOR BITTIME
  NEXT j
  // Stop bit
  OUT = 1
  SLEEP FOR BITTIME
RETURN
Ettore
Labcenter Staff
Posts: 2932
Joined: Fri 2006-03-03 11:56
Location: Milan
Contact:

Re: MIDI frame generator with EasyHDL

Post by Ettore »

Given that in your code you used a REPEAT then I thought you were looking at a repeated sequence.
For non repeated sequence you need additional code that prevents the reading of more elements than those specified in the DATA keyword or you will get an OUT OF DATA error (like any other BASIC dialect). So, any solution that limits the number of DATA reading is correct, including the your. An alternative solution - a little more efficient - is by using an 'end-of-table element'. This technique is illustrated in the sample attached.
Attachments
Easy_HDL_test_1.zip
(3.96 KiB) Downloaded 152 times
Kind regards,
Ettore Arena - Labcenter Electronics.
chimimic
Expert User
Posts: 508
Joined: Tue 2006-04-11 13:31
Location: France
Contact:

Re: MIDI frame generator with EasyHDL

Post by chimimic »

Thanks a lot, Ettore.
New sample is enough clear for me, excellent !

Best regards,
Remy
Post Reply