Life@ITP

December 17, 2005

MIDI Lab

Filed under: Physical Computing

MIDI or Musical Instrument Digital Interface is a protocol developed for communication between digital synthesizers and other digital music devices.

For this lab I used a sythesizer which was connected to my microcontroller. The program takes a value from an analog sensor and uses it ro generate the pitch of a note played once every quarter of a second.

‘ the sensor is on pin RA0 The MIDI is on pin RC6
‘ Make sure to select Configuration, Oscillator, HS
‘ in EPICWIN when programming:
DEFINE OSC 20
DEFINE ADC_BIT 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 15

‘ set up serial UART registers:
define HSER_RCSTA 90h
define HSER_TXSTA 20h
define HSER_BAUD 31250

TRISA = %11111111
‘ set up ADCON1
ADCON1 = %10000010

‘ declare an array of 12 word variables:
pitch var byte (12)

‘ declare other variables:
note var byte
ADCVar var word

‘ the 12 elements of the array called pitch are the 12 notes of a scale:
pitch (0) = 60 ‘ middle C
pitch (1) = 61 ‘ C#
pitch (2) = 62 ‘ D
pitch (3) = 63 ‘ D#
pitch (4) = 64 ‘ E
pitch (5) = 65 ‘ F
pitch (6) = 66 ‘ F#
pitch (7) = 67 ‘ G
pitch (8) = 68 ‘ G#
pitch (9) = 69 ‘ A
pitch (10) = 70 ‘ A#
pitch (11) = 71 ‘ B

main:
‘My potentiometer gave a range from 0 to 1023
ADCin 0. ADCVar
‘ connect to a range from 0 to 11:
Note = ADCVAR / 100
‘ play note:
hserout [$90. pitch(note), $40]
pause 250
‘ noteoff:
hserout [$80, pitch(note), $00]
goto main

Week 6 Lab

Filed under: Physical Computing

I finally had a chance to work on my week 6 lab assignment. I couldn’t get my hands on a H-bridge so I did the next best thing…use a TIP120 which only allowed me to vary the speed of the motor by receiving pause intervals. After finals I was basically broke so I got the cheapest DC motor I could find at Radio Shack, a 1.5 - 3v DC hobby motor.

I got the DC motor to do what it’s supposed to do, which is to spin. The ER room was out of still camera’s so I didn’t have a chance to take any photos but below is the code I used to program my PIC chip.

‘define oscillator @ 4mhz
DEFINE OSC 4

‘ make ports D1 output

output PORTD.1

pause 500 ‘ start program with a half-second delay

main:

high PORTD.1

pause 1000 ‘ turns motor power on for 1 second

low PORTD.1

pause 1000 ‘ turns power off for 1 second

goto main






















Get free blog up and running in minutes with Blogsome | Theme designs available here