joe blubaugh diana mui david sutherland matthew swallow

14
Joe Blubaugh Diana Mui David Sutherland Matthew Swallow

Upload: alfred-bailey

Post on 31-Dec-2015

219 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Joe Blubaugh Diana Mui David Sutherland Matthew Swallow

Joe BlubaughDiana MuiDavid SutherlandMatthew Swallow

Page 2: Joe Blubaugh Diana Mui David Sutherland Matthew Swallow

• Two seperate devices to be programmed

• DSP (dsPIC33)• DFT algorithm performed on audio

input• Peak detection and frequency

analysis• SPI communication with micro

• Micro (PIC24)• SPI communication with DSP• SPI communication with USB

controller• UART communication with LCD• Menu/push buttons• Motor control

Page 3: Joe Blubaugh Diana Mui David Sutherland Matthew Swallow

Discrete Fourier Transfor

m

Peak Detectio

n

Frequency information

PIC24

dsPIC33

Audio InString

FrequenciesSPI

• Where the magic happens…

Page 4: Joe Blubaugh Diana Mui David Sutherland Matthew Swallow

Tuning

mode?

Full ADC sample

set taken?FFT

Peak detect(precise)

Build SPI transmission

packet

Transmit packet over SPI

Take more samples

Message received

from micro?

Start

Note detect(not as precise)

Determine request

Yes No

NoYes

Transmission error

Mode change

Tuning mode

MIDI mode

Page 5: Joe Blubaugh Diana Mui David Sutherland Matthew Swallow

• Interrupt driven code• ADC triggered on 2800 Hz timer

interrupt when sampling• SPI

• Polling loop code• FFT on ADC

complete• Frequency

analysis (note, peak detection)

Page 6: Joe Blubaugh Diana Mui David Sutherland Matthew Swallow

• Why the hybrid interrupt/polling approach?

• ADC sampling rate is timing critical, must be interrupt triggered

• FFT, frequency calculations must happen after samples taken

• Calculations should be completed in order and as fast as possible, should not be interrupted.

• Hence, polling loop is best option for these steps

Page 7: Joe Blubaugh Diana Mui David Sutherland Matthew Swallow

Frequency

DecodeSPI1

PWM Motor

Control

User Interface

MIDI Assembl

y

USB Control

PWM

UART

SPI2

Motors

LCD

Vinculum USB Controller

PIC24

Page 8: Joe Blubaugh Diana Mui David Sutherland Matthew Swallow

• Interrupt driven code• SPI packet reception from DSP

• Saves data to circular buffer to be processed later

• Menu/UI• Pushbuttons are externally debounced and

attached to EXTINT pins• LCD commands added to a circular buffer

and serviced by low-priority ISR triggered by 50Hz timer interrupt

• USB communication via SPI• Only active during “MIDI transcription” mode• Bytes assembled from MIDI polling loop

routine• ISR entered on first SPI2 write• Highest priority interrupt

Page 9: Joe Blubaugh Diana Mui David Sutherland Matthew Swallow

• More interrupt driven code…• Motor control algorithm

• 20 Hz timer interrupt• Timer initialized for 20Hz to set PWM

period• Interrupt will be enabled and utilized

to perform motor control calculations• Take frequency information from circular

buffer• Determine rotation direction which

increases frequency• Decrease motor speed as frequency

becomes close to desired one by varying PWM duty cycle

Page 10: Joe Blubaugh Diana Mui David Sutherland Matthew Swallow

Determine new motor

speed

Determine motor directions

Start

Yes No

Determine new motor direction

Is this the sixth motor?Write

PWMDTY register

No

Yes

Has this positive motor direction been

determined?

Exit ISR

20Hz timer ISR

Page 11: Joe Blubaugh Diana Mui David Sutherland Matthew Swallow

• Interrupts can be prioritized so that certain ISRs take precedence over previously operating ones

LCD timer interrupt (50Hz)

USB SPI transmission

DSP communication SPIMotor control timer interrupt

(20Hz)External push button interrupts

(EXTINT)

Page 12: Joe Blubaugh Diana Mui David Sutherland Matthew Swallow

• Polling loop code• MIDI transcription

• Save off pointers to header section for later modification

• Write corresponding note data to buffer when note changes

• Either when mode has stopped, or 128 bytes have been acquired, initiate USB SPI interrupt by writing SPI2TXBUF

• Modify the header sections with number of bytes written to each “track”

Page 13: Joe Blubaugh Diana Mui David Sutherland Matthew Swallow

• Why is the code mainly interrupt-based?• Prioritization

• Certain processes need precedence• USB over… well, anything• Pushbuttons/UI service before LCD

UART transmission• Some routines are big…

• Organization• ISRs help to organize code into

manageable chunks that happen at discrete periods of time

• In contrast to…• A giant, unruly polling loop where higher

priority tasks have to wait for lower ones to complete

Page 14: Joe Blubaugh Diana Mui David Sutherland Matthew Swallow

• Questions?