41
Student Name: Kevin Dobson Project Supervisor: Dr

Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

Embed Size (px)

Citation preview

Page 1: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

Student Name: Kevin Dobson

Project Supervisor: Dr Lance Fung

Page 2: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

Project Overview

“To create a device which may interpret and

modify a MIDI signal as defined my the user”

Page 3: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

Project Objectives

• Select and Configure device hardware– Select Microcontroller for accurate operation

and optimum performance

• Create Software– Both embedded code and application software

Page 4: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung
Page 5: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

MIDI Background Information

• The Musical Instrument Digital Interface (MIDI) is a standard allowing musical synthesizers and other electronic devices, of different makes and models, to communicate and control each other via a unidirectional link.

• For Example: A computer, or musical keyboard may control the notes played on a separate synthesizer.

Page 6: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

MIDI History

• During the 70s the analogue synthesizer evolved from the electric organ and became popular by the end of the decade

• During this time, analogue ‘control voltages’ were used for interconnectivity. Crude and Monophonic.

• In 1982 UMI (Universal Musical Interface) was proposed

• By 1983 it had been renamed to MIDI (Musical Instrument Digital Interface)

• Major contributors to the development of the standard were Roland (Japan) and Sequential Circuits (USA)

source: http://www.mtsu.edu/~dsmitche/rim419/midi/HTMLs/MIDHIS~1.HTM

Page 7: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

The MIDI Specification

• Hardware Specification– Asynchronous Serial Interface – Current Loop (current on = logic 0)

• Optical isolation & no common ground

– 31.25 Kbps (320us per byte)

Page 8: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

The MIDI Specification

• Midi Messages (in general)– Each message can contain from 1 to 3 bytes– The first byte is always a status byte which

specifies the TYPE (and channel) of the message. This byte always has the MSB set (i.e from 0x80 - 0xFF)

– The following data bytes (if needed) contain information specific to the message type defined by the status byte

Page 9: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

The MIDI Specification

Some Status Bytes:

0x80 - 0x8F : Note Off

0x90 - 0x9F : Note On

0xA0 - 0xAF : Aftertouch

0xB0 - 0xBF : Program Change

- where the lower nibble is the channel number

Page 10: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

The MIDI Specification

Example:The Note On status byte is followed by two data bytes which specify the note number and velocity (defined in the specification)

The following byte stream will play note C6 (0x3C) at a velocity (volume) of 100 (0x64).

0x92, 0x3C, 0x64

Now, onto the convoluted contraption...

Page 11: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

Enter...

Page 12: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

Concept & Preliminary Design

Q. So... What does this thing do anyhow?

A. Anything!

Page 13: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

Concept & Preliminary Design

Q. So... What does this thing do anyhow?

A. Anything!

Keyboard Programmable

MIDI Device

MIDI OUT

PC

MIDI OUT MIDI IN MIDI IN

Page 14: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

Concept & Preliminary Design

Why would you want it?

• Compatibility Issues

• Abstract event triggering

• Real-time interactive automation

• Performance Aid

Page 15: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

Concept & Preliminary Design

• Major Considerations– Ease of use– Diversity of use

• State Machine Approach– Text / Macros– Tabular– Graphical

Page 16: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

Concept & Preliminary Design

No Action

No Action No Action

Key 1

Key 2

Key 3

START

Other Key

Other Key

Key 4

Key 5 Key 6

Action 1 -------------- Action 2

Reset Key

Action 3 Action 4 -------------- Action 5

Page 17: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

• Device Programming Method– Download

• Separate Serial/Parallel PC interface

• Sysex Data Stream (through MIDI)

– Code Generation• Configuration data interpreted by Embedded Code

• Generation of instruction words of code

Concept & Preliminary Design

Page 18: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

Project Components

• Hardware– Microcontroller Consideration– MIDI Interface Circuitry

• Software– User Application Software– Embedded ‘Firmware’

Page 19: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung
Page 20: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

Hardware Consideration

• Microcontroller Required:– Nonvolatile Memory– Sufficient Speed & Ram– Asynchronous serial input and output

• 31.25Kbps

• 1 start bit, 1 stop bit, 8 bit data byte

Page 21: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

Hardware Consideration

• Microcontroller Chosen:– Microchip PIC16F876

• 8-bit RISC Structure (14 bit instruction word)

• Onboard Flash Memory (8K 14-bit words)

• 368 bytes of RAM

• USART Serial Communication

• 20MHz Maximum Operating Frequency– Allowing a 5MHz CPU clock

• 13 Interrupts

Page 22: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

Hardware Consideration

• Configuration:– 16Mhz Operating Frequency

• 4MHz CPU Clock

– UART @ 31.25 Kbps• 1 start/stop bits, 8 data bits, no interrupts enabled

– Flash Memory Runtime Write Enable

Page 23: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

Hardware Configuration

Page 24: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

Hardware Issues

• Supply voltage must be regulated to approximately 5V at varying current draw– In this case, a 5V regulator IC was used

• Opto-isolator and hex inverter must be capable of operation @ 31.25KHz

• With CPU Clock @ 4MHz, 1280 cycles are available between bytes

Page 25: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

Prototype

Page 26: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung
Page 27: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

Software Production

• Software Production Phases– Begin Windows Application Software (C++)

• Basic User Interface. I.e. Menus, MDI Child Windows, Toolbars

• Drawing/Dropping routines

– Create Embedded Firmware (PIC16 ASM)– Finish Windows Application Software

• Create Code Generation Routines• Tidy up File Saving/Loading

Page 28: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

Application Software

• Written wholly in ANSI C++

• Using MinGW (Minimalist GNU for Windows)– collection of headers, libraries and compilers

for Win32 Application creation– placed in the public domain & GNU licensed

• DJGPP’s RHIDE used as editor

Page 29: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

GUI Design

STATE EVENT (Transition)

TOOLS

Pointer Draw Line Delete Edit Select Start State

Actions within state

Triggers within event

Page 30: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

GUI Design

Page 31: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

GUI Design

Page 32: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

GUI Design

Page 33: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

Embedded Code

• Written wholly in PIC16 ASM• Using MPBLab IDE• DJGPP’s RHIDE used as editor

• Responsibilities– Receiving and organising MIDI bytes into messages– Calling Downloaded Code– Transmitting MIDI Output (from Output Buffer)– Allowing Downloading and Writing of State-Machine

Code to Flash Memory

Page 34: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

Full MIDI Message?

Add byte to Message Buffer

Embedded Code

Call Downloaded Code With MIDI Message

Byte Recieved?

Transmit Next Byte (If Output buffer isn’t Empty)

Call Downloaded Code Without MIDI Message

Y

Y

N

N

Page 35: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

Embedded Code Stats

• ROM– 493 Word Program (1st Page)– 2K Words Available for Download (2nd Page)

• RAM– Message Buffer - 4 bytes (1st Bank)– Output Buffer - 94 bytes (FIFO, 2nd Bank)

• Start Pointer, End Pointer & End Location

– 3rd Bank dedicated for Downloaded Code Ram

Page 36: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

User Code Generation

CodeGenerationAlgorithm

User’s State Diagram(s)

Machine Code

(Performed Within Windows Application Software)

Page 37: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

User Code Generation

• Each state diagram has a variable which defines the current state

• Every time the downloaded code is called it cycles through each of the state diagrams– For each diagram it jumps to the correct

location in memory for the current state• Each state location checks inputs to see if a change

in state is necessary

Page 38: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

User Code Generation

Action1

Action2

...

Set State to STATE1

Return to root code

STATE1A If Event1 goto STATE2A

...

Return to root code

STATE1B

If Event2 goto STATE5A

An Example for STATE 1. The root code will jump to STATE1B, but any other state will jump to STATE1A.

Page 39: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung

Resources Used

• MIDI Technical Fanatic’s Brainwashing Center

• MinGW, MPBLab & DJGPP Resources• The Forger’s Win32 API Tutorial• Microchip product documentation• MIDI Manufacturers Assoc. Homepage• Programming and Customising PICmicro

Microcontrollers– Myke Predko

Page 40: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung
Page 41: Student Name:Kevin Dobson Project Supervisor:Dr Lance Fung