160 likes | 513 Views
Lab 3 General MIDI Explorer with Record/Playback. Getting Started updated 11/08 by Felipe Vilas-Boas and W. Burleson. Where are we?. Lab 0 MIDI Receiver Verilog/Quartus, Breadboarding, GoLogic, MIDI-Ox Lab 1 Cache Simulator in C C programming, data structures
E N D
Lab 3General MIDI Explorer with Record/Playback Getting Started updated 11/08 by Felipe Vilas-Boas and W. Burleson
Where are we? • Lab 0 MIDI Receiver • Verilog/Quartus, Breadboarding, GoLogic, MIDI-Ox • Lab 1 Cache Simulator in C • C programming, data structures • Cache architecture and analysis • Lab 2 Pipelined Machine • C programming, data structures • Pipeline architecture and analysis • Lab 3 General MIDI Explorer with Record/Playback • Microcontroller programming • C • Assembly
Objectives • Exposure to microcontroller programming • Assembly Language (ASM) • Talking to A/D converter • Talking to Timer • Talking to UART • Compiled Language (C) • Data Structure in Memory • Talking to UART • Continuation of MIDI theme • Serial communication • Notes and instruments • FUN! A complete system with input, output, storage
Requirements • C Program • Send & Receive MIDI Messages • Play and Recording Modes • Store and Replay MIDI Messages • ASM Program • Vary speed of messages via hex switch • Instrument / Note / Velocity via photo cells • Change channels between Percussion & Instrument
Relevant AVR Components • C Program • Data EEPROM (Storage) • USART (Communication) • ASM Program • Timer1 (Counter) • USART (Communication) • ADC (Analog to Digital Converter) • Will manipulate these components using AVR assembly.
AVR Assembly • Commands similar to MIPS • ldi, breq, andi, lsr, rsr, etc. • ‘in’/’out’ used when working with I/O ports • Can ‘rjmp’ using tags (no offsets to worry about) • There are some differences though… • sbic, neg, cbi, etc.
Setup Example (AVR) Setup Example .include "m32def.inc“ (Include system file) .def Temp=R16 (Define R16 register) .org 0x0000 (Where to begin)rjmp RESET (Jump to RESET) RESET: …
Stack Pointer • You must initialize the stack pointer if you wish to return from jumps… • Set stack pointer ldi Temp, 0x65 out SPL, Temp
Setup Example (C) Setup Example #include <avr/io.h> (Include system file) int main() { int data; DDRA = 0xFF; (PORTA output) DDRB = 0x00; (PORTB input) PORTA = 0x55; (Output 0x55 or 0b01010101) data = PINB; (Store input values) } …
Timer1 • Timer1 is the 16-bit counter on the AVR • Will count overflows of Timer1 in order to gauge transmission time. • Good to set counter prescalar to 1024 • Choose 1024 prescalar for Timer1 ldi Temp, 0x05 out TCCR1B, Temp
USART • Must initialize with desired baud rate and frame format • Must be initialized in both C and ASM • MIDI Baud rate : 31.25 kbps • Want start/stop bits and 8 data bits • Read data sheet
ADC • General AVR ADC reading process: • Enable ADC • Specify pin to read • Call for conversion • Check completion bit • Copy data to intermediate register
MIDI Message Format • STATUS / NOTE / VELOCITY • For Note on : 0x90 / 0x?? / 0x?? • For Note off : 0x80 / 0x?? / 0x?? • For Inst. Change : 0xC0 / 0x?? • For Note on Perc. Chan : 0x99 / 0x?? / 0x?? • Max data value for MIDI NOTE / VEL should be 0x7F • ADC can output up to 0xFF
What Now? • Every time Timer1 overflows, a flag will be triggered. Use this to time transmission. • Package MIDI messages correctly • Three Byte Clusters (Status/Note/Velocity) • MIDI On and Off Messages
Hints • Datasheet is extremely helpful • Both C and ASM • Timer in ASM can be tricky • Send Dummy Messages to test timing • C program slightly simpler • Start with C to understand the AVR • ASM can be broken into two pieces