========================================
UP/DOWN SWEEP 18b - for the MICrODEC
Text based flow chart
last edited by: mcanulty - Sept.28.2010
========================================
variables:
bit direction flag
int left in
left LSB in
left MSB in
int left out
left LSB out
left MSB out
int right in
right LSB in
right MSB in
int right out
right LSB out
right MSB out
18b read pointer
read pntr LSB
read pntr MSB
read pntr HIGH
18b write pointer
read pntr LSB
read pntr MSB
read pntr HIGH
18b read offset vector
offset LSB
offset MSB
offset HIGH
18b buffer size
buff size LSB
buff size MSB
buff size HIGH
int ADC value
ADC val LSB
ADC val MSB
START UP/DOWNSWEEP INTERRUPT ROUTINE
==== AUDIO XFER =================================================================
- out Left MSB
- wait for SPI flag
- in left MSB
- out left LSB
- request data from SRAM at read pointer (left/even)
- increment read address (now points at right/odd)
mask off unused bits
set we bit
- receive data from read pointer request
place in left channel out regs
- wait for SPI flag
- in left LSB
- out right MSB
- write left channel to SRAM at write pointer (left/even)
set address lines to write pointer
pull CE and WE low
switch data lines direction to out
load data lines
pull we high
switch data lines direction to in
- wait for SPI flag
- in right MSB
- out right LSB
- request data from SRAM at read pointer (right/odd)
- increment write address (now points at right/odd)
mask off unused bits
- receive data from read pointer request
place in right channel out regs
- wait for SPI flag
- in right LSB
- write right channel to SRAM at write pointer (right/odd)
set address lines to write pointer
pull CE and WE low
switch data lines direction to out
load data lines
pull we high
switch data lines direction to in
- increment write address pointer (now points at left/even)
- set read address equal to write address (in order to later subtract the offset)
write pointer LSB data -> read pointer LSB register
write pointer MSB data -> read pointer MSB register
write pointer HIGH data -> read pointer HIGH register
- BRANCH TEST - Are we in forward mode?
if yes, go to FORWARD MODE OFFSET UPDATE
if no, go to REVERSE MODE OFFSET UPDATE
===================================================================================
==== FORWARD MODE OFFSET UPDATE ==================================================
- decrease offset vector by 2 (read pointer plays forwards at 2x)
- BRANCH TEST - Have we reached the beginning of the buffer, ie, offset equals 0?
if yes, set offset to 4 and switch mode to reverse
if no, proceed to CALCULATE READ ADDRESS
===================================================================================
==== REVERSE MODE OFFSET UPDATE ==================================================
- increase offset vector by 4 (read pointer plays backwards at 1x)
- BRANCH TEST - Have we reached the bottom of the buffer, ie, offset >= buff size?
if yes, reduce offset by 2 (replay last sample), switch mode to forward
if no, proceed to CALCULATE READ ADDRESS
===================================================================================
==== CALCULATE READ ADDRESS =======================================================
- set read address pointer to write address pointer (already done)
- subtract offset from read address pointer
- mask off unused bits in read pointer HIGH
- set WE bit in read pointer HIGH
- proceed to UPDATE BUFFER SIZE
===================================================================================
==== UPDATE BUFFER SIZE ===========================================================
- place ADC Value in Buffer Size
ADC val LSB -> Buffer Size LSB
ADC val MSB -> Buffer Size MSB
0 -> Buffer Size HIGH
- left shift Buffer Size two times (multiply by four)
===================================================================================
END UP/DOWNSWEEP INTERRUPT ROUTINE