joe blubaugh diana mui david sutherland matthew swallow
TRANSCRIPT
Joe BlubaughDiana MuiDavid SutherlandMatthew 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
Discrete Fourier Transfor
m
Peak Detectio
n
Frequency information
PIC24
dsPIC33
Audio InString
FrequenciesSPI
• Where the magic happens…
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
• 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)
• 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
Frequency
DecodeSPI1
PWM Motor
Control
User Interface
MIDI Assembl
y
USB Control
PWM
UART
SPI2
Motors
LCD
Vinculum USB Controller
PIC24
• 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
• 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
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
• 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)
• 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”
• 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
• Questions?