1 / 37

General MIDI Explorer Instructor and UGA Presentation, and Demo Professor Sandip Kundu Fall 2014

ECE 353 Lab D. General MIDI Explorer Instructor and UGA Presentation, and Demo Professor Sandip Kundu Fall 2014. Lab D General MIDI Explorer with Record/Playback. Getting Started. Where Are We?. Lab A Cache Simulator in C C programming, data structures

landis
Download Presentation

General MIDI Explorer Instructor and UGA Presentation, and Demo Professor Sandip Kundu Fall 2014

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ECE 353 Lab D General MIDI Explorer Instructor and UGA Presentation, and Demo Professor Sandip Kundu Fall 2014

  2. Lab DGeneral MIDI Explorer with Record/Playback Getting Started

  3. Where Are We? Lab A Cache Simulator in C • C programming, data structures • Cache architecture and analysis Lab B MIDI Receiver • Hardware design • Proper Verilog Coding • Functional Simulation, GoLogic, MIDI-Ox Lab C Pipelined Machine • C programming, data structures • Pipeline architecture and analysis Lab D General MIDI Explorer with Record/Playback • Microcontroller programming • C and Assembly (optional for 10% extra credit)

  4. Perspective • As an engineer you often have multiple choices for implementation • What you do will depend on performance and cost requirements • Use a CPLD, FPGA, ASIC/microprocessor, or microcontroller • Write it in Verilog (CPLD, FPGA, ASIC) => Lab B • Write it in C or ASM => Lab D

  5. When to use: PLDs, FPGAs, ASICs, Structured ASICs • Programmable logic devices (PLDs) provide low/medium density logic. • Field-programmable gate arrays (FPGAs) provide more logic and multi-level logic. Advanced peripheral support. • Application-specific integrated circuits (ASICs) are manufactured for a single purpose. Typically built with standard cells implementing gates. Higher performance vs. FPGAs. • Structured ASICs are in between FPGAs and ASIC in density & performance. Typically wire together cells that are pre-built and exist in island configurations.

  6. Tx Discrete PHY Rx Tx Rx Differences between microcontrollers, microprocessors and FPGA systems for running software • FPGA systems often contain CPUs in softcore (synthesized) or hardcore (part of die) format but can also contain logic blocks for other hardware, e.g., state machines, etc • 45-65 nm FPGAs (Virtex 5-7) can achieve high performance. • Microcontrollers are more limited in functionality and often do not include support for virtual memory and caches • Up to 50MHz • Microprocessors are higher performance capable and have typically virtual memory support • From 50MHz to GHz Soft core Hard core with built-in Transceivers

  7. Lab D Objectives • Exposure to microcontroller programming vs. design of hardware • Compiled Language (C) • Data Structure in Memory • Talking to UART, Timer • Assembly Language (ASM) - optional • Talking to A/D converter, Timer, UART • Continuation of MIDI theme • Serial communication • Notes and instruments • Complete system with MIDI – FUN! with input, output, storage

  8. Lab D Requirements • Part 1: C Program • Send & Receive MIDI Messages • Play and Recording Modes • Store and Replay MIDI Messages • Part 2: ASM Program (optional for extra credit) • Vary speed of messages via hex switch • Instrument / Note / Velocity via photo cells • Change channels between Percussion & Instrument

  9. AVR Components Used • In Part 1 (C Program) • Data EEPROM (Storage) • USART (Communication) • Timer1 (Counter) • In Part 2 (ASM Program) • Timer1 (Counter) • USART (Communication) • ADC (Analog to Digital Converter) • Will manipulate these components using AVR assembly.

  10. ATmega32 AVR • 16MHz CMOS 8-bit microcontroller with AVR RISC instruction set • 32 general purpose registers • 32KB of Flash • 2Kb internal SRAM • 1KB E2PROM – 100,000 erase cycles • 8 and 16 bit counters • USART • 8-bit ADC • JTAG • ….

  11. Board Demonstration

  12. Wired Board

  13. Part 1 – C Program • Develop, program AVR through JTAG, for: • Getting MIDI messages through the Midi OX from the PC serially • Similar to Lab B but using AVR Studio and AVR gcc compiler – to receive

  14. Part 1 – C Program contd. • Once received in AVR, store in E2PROM if switch set to Record • Compress/decompress before/after storing - you can use any algorithm you find suitable • Record timing also so that you can replay exactly the same way • If switch set to Playback, play back • Incoming signal optically isolated from PC

  15. Compression • Why compress? • Store more data in same persistent memory • Persistent data limited in # of erase cycles • Save on bandwidth when communicating in some apps • Lossless compression (LZ, Huffman, RLE): • Decompress and get the same data, bit - for - bit • Lossy compression (JPEG,…): • Decompress and get something *similar*. • Any amount of compression is possible. • Tradeoff between quality and compression. • Domain specific • You may understand the pattern, e.g., in the case of MIDI messages there is a repetition that could be exploited.

  16. Example: Run Length Encoding (RLE) • Very simple lossless encoding of repeating patterns • Example: Imagine a stream of bits with many 0s and 1s • Source: 000000000111111110001111111 • RLE Version: 9Zeros8Ones3Zeros7Ones • Can be transformed into a sequence of 1s and 0s but we often limit the encoding of the maximum sequence value to avoid too much overhead for very random sequences. • Say we limit to maximum 16 repetition of 1s or 0s: represent with 4 bits • 1001(0)1000(1)0011(0)0111(1) for the above sequence • Best we get is minimum 5 bits needed for a sequence of length 16, or a compression ratio of 16/5 • 111111111111111 => 1111(1) • Worst we get an overhead of how much? • To avoid, change algorithm to have a first bit encode WHEN RLE is used • RLE can be applied at various granularities

  17. Example of lossy compression - JPEG compression Very high quality: compression = 2.33 Photoshop Image Very low quality: compression = 115 Produced by MATLAB with Quality = 0

  18. For Part 1 you need to figure out how to • Initialize the USART • Set baud rate for midi • Enable the receiver and transmitter • Initialize to 8 data bits, 1 stop, and 1 stop bit • Create functions for receive, transmit, and flush USART • Create functions to read and write E2PROM • Work with timers and interrupts • Use 16-bit counter and generate interrupts for overflows; need to setup ISR (interrupt service routine) • Main function • Use LEDs to debug, try something simple first • All information is in AVR datasheet; sample codes

  19. Part 2 – AVR ASM Program • Develop, program AVR through JTAG • Use the three optical sensors that are connected to three ADC inputs on AVR to generate instrument, note, and velocity MIDI bytes • Use the internal AVR counter to synchronize when sending back MIDI messages to PC • Sets 1 bit into register, your code will be polling • Speed-dial hex switch on board • Use GPIO connected switch • To program channel select (percussion, instrument) • Note that you will see 2 byte message for program channel selection and the typical 3 bytes for the message that contains note and velocity

  20. Build Process • Board Assembly • C & Assembly Programming • AVR Studio (IDE) • Olimex JTAG Programmer • Testing • MIDI-OX • GoLogic Logic Analyzer • Oscilloscope

  21. Board Assembly • Reuse parts of Lab B • MIDI input (Opto-isolator) • Plan for both programs if you decide to do both C and ASM versions • Layout should be compatible with both • Use resistors as indicated in schematic • Otherwise photo-senors may not work correctly

  22. AVR Studio • Atmel IDE • Tool chains for building C and assembly code • Programmer • Debug • Easier to use than Quartus!

  23. AVR Studio Demonstration • Open up a new instance of AVR Studio 4 • When the welcome screen pops up, click New Project

  24. AVR Studio Demonstration • Select AVR GCC for the project type • Type in project title and choose project directory if necessary • Click next and choose the debugging platform used to program the MCU as well as the MCU that you are using • Now go to Project --> Configurations and choose the MCUs clock frequency.

  25. AVR Studio Demonstration • Start Coding! • When finished, 1.build your project and then 2.connect to the MCU.

  26. AVR Studio Demonstration • Once you connect to your MCU, erase the device and then load up the .hex file created in your project directory on to the Flash Memory.

  27. AVR Studio Demonstration • Click on program to load your .hex file on to the board. • Now open up MIDI OX and set it up like you did in Lab B. • Start sending notes to your board!

  28. Testing • Familiar tools • MIDI-OX • GoLogic Logic Analyzer • Analyzer individual MIDI frames • Oscilloscope • Demonstrate frequency of sent MIDI messages

  29. General Advice • Consult the Atmega32 datasheet • Pin layouts • Code examples in C and assembly • All the info you need to manipulate the microcontroller for this project is here! • Use the AVR studio debugger • Check the value of pins and registers • Single step through code to find source of problems • Use internet resources • avrfreaks.net is a good resource for examples

  30. DEMO

  31. Backup

  32. 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.

  33. 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: …

  34. Stack Pointer You must initialize the stack pointer if you wish to return from jumps… Set stack pointer ldi        Temp, 0x65        out        SPL, Temp

  35. 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) } …

  36. 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

  37. 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

More Related