Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Altera_Forum
Honored Contributor I
879 Views

How to record sound into SDRAM DE2-115 Cyclone IVE

Hello,  

 

I have an assignment where is need to design a nios 2 hardware system to run a desired software application on the DE2-115 board. 

The requirements are as follows;  

- Instructions on how to use the program are displayed on the LCD 

- An audio signal is applied to the line in/mic in of the de2 board 

- The program will record this signal into memory under the control of one push button  

- The program will output (playback) this signal through the line out under the control of a second push button  

- I need one interrupt source.  

 

 

I've designed the hardware using Qsys system integration tool; I've added the nios 2 processor, JTAG, SDRAM controller, audio core, audio/video config core, on-chip memory, LCD controller and the PIO's for the push buttons and interrupt. I've instantiated in quartus. I am debugging the software using Altera monitor program.  

 

I need to write the software in assembly language or C (I chose assembly because my lecturer taught us assembly mostly) I've gotten as far as writing the instructions on the LCD. I've added a polling routine for the first pushbutton, loading the value from the input and repeating the process if the key has not been pressed.  

 

I've tried simply extracting audio data from the FIFOs and outputting to the speaker but when I download the system, plug my phone into the line in and speakers to the line out the sound just plays without me running the software. Forgive me if I am being naive but I don't understand how I can run the software when the hardware alone is outputting sound.  

 

I am clueless as how I am going to actually record the sound in memory. How do you allocate memory for the audio onto the SDRAM chip? Please help! I am losing sleep over staring at datasheets and documents and I am getting no where with this assignment. There are no assembly language software guides for recording sound and playing back, they've all been done either using VHDL alone or Nios IDE/HAL.  

 

 

.text 

.global _start 

_start: 

 

 

 

movia r2,0x00009000 # audio_codec address  

movia r4,0x00003000 # push_button 1 address (record) 

movia r5,0x00004000 # push_button 2 address (playback)  

movia r8,0x00002040 # LCD address 

movia r9,0x08000000 # DRAM address  

 

 

 

 

 

 

main:  

 

# LCD related---------------------------------------------------------# interface the LCD with the commands  

movi r3,0x38 # interface length 8-bits, 2 line, font - offset 1 for command  

stbio r3,0(r8) # store on LCD (register 8 contains lcd address) 

 

movi r3, 0x0F # set blinking cursor  

stbio r3,0(r8) 

 

movi r3,0x10 # Shift mode enabled  

stbio r3,0(r8) 

 

movi r3,0x01 # clear and set cursor to 00 

stbio r3,0(r8) 

 

 

 

movia r10,end_string-start_string # load length of string  

movia r11,start_string # load start string  

 

# Writing data to LCD  

 

 

write_lcd:  

ldb r3,0(r11) # load byte from r11 (start string) onto r3  

stbio r3,1(r8) # store data on LCD - offset 1 for data  

 

mul r12,r12,r1 # r1 temporary assembler - add r1 to accumulated addition r12  

addi r7,r7,1 # increment start address 

subi r6,r6,1 # decrement counter  

bne r6,zero,write_lcd # branch if not equal - if equal...  

 

movi r3,0xC0 # ...new line  

stbio r3,0(r8) # store command on lcd  

# Push button Key_1----------------------------------------------------------------------------------------------------------------------  

 

 

wait_key1: # wait for push button  

ldwio r6,0(r4) # load input from pushbuttons into r6 

bne r6,r0,wait_key1 # wait for button release  

 

Audio related ----------------------------------------------------------------------------------------------------------------  

ldwio r3,4(r2) # Read fifospace register -- load 32-bit word from input peripheral into register 3  

# Offset 4 is the fifo space  

 

andi r3,r3,0xff # Extract samples in Input Right Channel FIFO [ADC] 

beq r3,r0,main # If no samples in FIFO, go back to start  

# Reasoning: andi 0000 0000 1111 1111 with r3 register (entire FIFO space) 

# RALC (15:8) and RARC (7:0) indicate the number of words of incoming audio  

# data in the left and right channel FIFOs, respectively. 

# If '0' the program checks again, we have samples 

 

ldwio r3,8(r2) # Read left fifo - offset 8 is the left data  

stw r3,8(r2) # Echo to left channel - left speaker  

 

ldwio r3,12(r2) # Read right fifo - offset 12 is the right data  

stw r3,12(r2) # Echo to right channel - right speaker  

 

loop: br loop # infinite loop 

 

 

 

.data 

start_string: 

.ascii "KEY1 to REC" 

end_string:  

 

 

 

Just some pointers or guidance or anything!!! I am struggling so badly 

Many many many thank you's
0 Kudos
0 Replies
Reply