ECE 477 Digital Systems Senior Design Project Rev 8/09 s12
Total Page:16
File Type:pdf, Size:1020Kb
ECE 477 Digital Systems Senior Design Project Rev 8/09
Homework 9: Software Design Considerations
Team Code Name: WaWA (We Are Wireless Audio) Group No. 5 Team Member Completing This Homework: Drew Schuster E-mail Address of Team Member: dtschust @ purdue.edu
Evaluation:
SCORE DESCRIPTION Excellent – among the best papers submitted for this assignment. Very few 10 corrections needed for version submitted in Final Report. Very good – all requirements aptly met. Minor additions/corrections needed for 9 version submitted in Final Report. Good – all requirements considered and addressed. Several noteworthy 8 additions/corrections needed for version submitted in Final Report. Average – all requirements basically met, but some revisions in content should 7 be made for the version submitted in the Final Report. Marginal – all requirements met at a nominal level. Significant revisions in 6 content should be made for the version submitted in the Final Report. Below the passing threshold – major revisions required to meet report * requirements at a nominal level. Revise and resubmit. * Resubmissions are due within one week of the date of return, and will be awarded a score of “6” provided all report requirements have been met at a nominal level.
Comments: ECE 477 Digital Systems Senior Design Project Rev 8/09
1.0 Introduction
We are Wireless Audio (WaWA) is a wireless speaker system that utilizes wireless protocols to transmit audio from a base station to a receiving station. It contains a microcontroller-driven base station on which the user will be able to adjust the volume manually, mute the volume, and power on and off the device. The user will also be able to use short speech commands to perform the functions of volume up, volume down, and mute. The user will be able to interface his or her portable music device with the base station. The receiving station will play the audio on either external speakers that the user provides, or internal speakers built into the receiving station.
The software running the microcontroller on both the host and receiving stations must be able to perform the aforementioned tasks reliably and rapidly. The major priority for the software is to make the audio quality as good as possible, and to not let any user interactions negatively affect the quality of the audio. This priority helps to define the manner in which the software is designed.
2.0 Software Design Considerations
2.1 I2S Audio Interface
One of the most critical external interfaces for WaWA is the I2S Audio interface. This protocol allows the LPC2377 microcontroller [1] to interact with the PCM3010 audio codec [2].
This interface is used on both the base and receiving station. On the base station it is used to receive audio, and on the receiving station it is used to output audio that is received from the base station.
-2- ECE 477 Digital Systems Senior Design Project Rev 8/09
The I2S interface uses the I2SRX_SDA and I2STX_SDA ports on the microcontroller, for receiving and transmitting data respectively. In order to initialize the I2S interface, PCONP bit 27 has to be set to a value of 1 to provide power to the I2S pins. Additionally, the transmission and receive rates need to be set. This is achieved by setting the I2S_TXRATE and the I2S_RXRATE variables to 0x13.
2.2 UART0 – XBee Wireless Interface
UART0 will be used by the microcontroller to communicate with the XBee wireless modules [3]. This will also be used on both the base and receiving stations. On the base station the XBee module will be transmitting audio data, and on the receiving station the XBee module will be receiving audio data.
Initialization of the UART0 interface is relatively simple, as the UART0 receives power by default on reset of the microcontroller. The transmit and receive pins can be accessed via the
U0RBR and U0THR pins respectively. Appropriate PINSEL0 values must be set in order to select which pins will be used for UART0 interfacing. A value of 0b1010 is sufficient in achieving this goal. Additionally, to set up the UART interface to be 8-bit, no parity, and one stop bit, the U0CLR pin must be set to 0x83. The desired baud rate for the UART0 communications is 115200 baud, because that is the maximum baud rate supported by the XBee modules. To set the baud rate to 115200 baud, U0DLL must be set to 3 and U0FDR must be set to 0x67.
2.3 UART3 – μOLED Display interfacing
UART3 will be used exclusively on the base station as a means to communicate with the
μOLED display [4]. The screen will be used to display volume information to the user.
Whenever a volume change occurs, the screen will be updated to reflect this information.
-3- ECE 477 Digital Systems Senior Design Project Rev 8/09
UART3 initialization is almost identical to UART0 initialization. The transmit and receive pins are U3RBR and U3THR respectively. As in UART0, the pin selection registers must be set appropriately (by setting PINSEL9 bits 27-24 to 0b1111), U3CLR is set to 0x83 to represent 8-bit, no parity, one stop bit communication, and U3DLL is set to 3 and U3FDR is set to 0x67 to select a baud rate of 115200 baud. The baud rate is kept consistent with the UART0 baud rate for ease of troubleshooting and debugging.
2.4 SPI – Potentiometer interfacing
SPI will be used on the base station only in order to interact with the AD5174 potentiometer [5]. When the user requests a volume change, the microcontroller will send a message to the potentiometer, which will adjust the audio signal coming in to the PCM3010 audio codec appropriately. This volume-adjusted signal will then propagate through the base station, to the receiving station, and finally be output to speakers.
As the SPI is initialized by default, no initializations or configurations are necessary. All
SPI interfacing can be managed by changing values in the SPI Status Register (SSEL) and the
SPI Data Register (S0SPDR). Writing to these registers will allow messages to be sent to the potentiometer. As the microcontroller does not require any acknowledgement from the potentiometer, the code will be written to ignore any message from the potentiometer to the microcontroller.
2.5 GPIO – Push Buttons and Voice Recognition Module
The GPIO interface will be used by the microcontroller to interact with standard push buttons along with the HM2007 Voice Recognition Module [6]. These external devices are used for volume control. When a change has been detected on any of the GPIO pins, the software will evaluate if a relevant command has been executed and adjust the volume accordingly. If the
-4- ECE 477 Digital Systems Senior Design Project Rev 8/09 volume does need to be adjusted, the μOLED display will be updated over UART to express that change to the user, and the microcontroller will send a message over SPI to the potentiometer to change the volume of the audio signal.
Initialization of the GPIO pins is rather simple. For each pin, a bit needs to be set in
FIODIR to determine the direction of the pin (0 is input, 1 is output). The value of this pin can then be used by accessing the FIOPIN registers.
2.6 Timer Module
The main integrated peripheral being utilized by the microcontroller is the timer module.
The timer module is used for two main functions. First, the μOLED display has a very specific initialization handshake that must be performed by the microcontroller before regular interactions can occur. This handshake requires waiting for exactly 1 second after reset before sending a startup message to the device. The timer module is used to wait for 1 second after the microcontroller has reset the display. After this initialization, the timer module is then used to poll user inputs from the push buttons and voice recognition module. Values of these pins are analyzed every 100 milliseconds, and the timing of that is controlled by the timer module.
The timer module is initialized to raise an interrupt every 1 millisecond. This provides the accuracy needed by the microcontroller but does not raise an interrupt so frequently that it hurts audio processing performance, which is the major priority of the entire WaWA system. In order to initialize the timer module, the T1MR0 register is set to 11999 to raise an interrupt every
1 millisecond. T1MCR is set to 3 and T1TCR is set to 1, turning on interrupts and enabling the timer. Finally, the interrupt is set to point to the required function so that the desired code runs in the software when the interrupt is triggered.
2.7 Code Organization
-5- ECE 477 Digital Systems Senior Design Project Rev 8/09
The code for this project is written in C using the μVision IDE [7] provided by the manufacturers of the MCB2370 [8] development kit. The code is designed to utilize both polling loops and interrupts, and can therefore be considered a hybrid design.
Timer interrupts drive the checking of user inputs in the base station, and UART receive interrupts are utilized in the receiving station to execute code when the XBee module receives audio data. When the base station timer interrupt functions have detected a change in user inputs, a flag is raised. The main loop of the base station code then checks this flag, and when the flag has been raised the volume is changed appropriately and the μOLED is updated.
This design suits the project well because it makes the transmission and processing of audio the priority. The user inputs will be checked periodically as needed, but the audio processing occurs as frequently as possible in the base station and immediately upon receipt of audio data in the receiving station.
2.8 Debugging Provision
To simplify debugging of the PCB circuit and the software, code has been written to temporarily implement ADC and DAC conversion instead of the more complicated I2S interface.
The ADC and DAC code can be used when troubleshooting the circuit to see whether potential problems exist in the I2S interface or elsewhere in the code or circuit.
2.9 Memory Map
Figure 2-1 LPC2377 Memory Map
-6- ECE 477 Digital Systems Senior Design Project Rev 8/09
3.0 Software Design Narrative
3.1 – Main
The main function oversees the entire operation of the codebase. On startup, the main function calls various initialization functions, initializing the display, the UART interface, the
I2S interface, the timers, and any other modules that require initialization. Once this is complete, the code goes into an endless loop. On the base station, this loop checks for volume change flags
-7- ECE 477 Digital Systems Senior Design Project Rev 8/09 and calls appropriate volume functions if necessary. On the receiving station, this while loops simply runs nops while waiting for an UART receive interrupt to occur.
Status: The code for the main functions in both the base station and receiving station is complete and functioning properly.
Hot Link: Main function (begins at line 146)
3.2 – Initialize Display
The display_init function is called by the main function exclusively on the base station.
This function performs the relatively complicated initial handshake with the μOLED display.
After resetting the display, the program waits for one second, and then sends the display a power up message. If the proper acknowledgement message is received, the function then sets the background color for the display.
Status: The code for the display_init function is complete and functioning properly.
Hot Link: display_init function (begins at line 55)
3.3 – UART Init
The init_serial function that initializes the UART modules is called by the main function.
The function itself sets the previously discussed (section 2.2 and 2.3) register values in order to initialize UART operation, and on the receiving station it registers an interrupt on UART0 receipts, allowing the receiving station to react immediately when audio data is received.
Status: The code for the init_serial function is complete and functioning properly.
Hot Link: init_serial function (begins at line 41)
3.4 – General Init
-8- ECE 477 Digital Systems Senior Design Project Rev 8/09
The general initialization functionality is currently housed within the main function itself, but will eventually become its own separate function. General init initializes the push button and voice module pins, as well as the timer module.
Status: The code for this functionality is complete and working properly, it just needs to be moved into its own function and called by the main function.
Hot Link: Main function (begins at line 146)
3.5 – Volume Change Handling
The checkVolumeChange function looks at the most recently received user inputs and detects if a volume change has been requested. It updates a volume variable that is then checked in the main loop. If that volume variable has changed, the main loop will call for a potentiometer change and a display update.
Status: The code for the checkVolumeChange function is complete and functioning properly.
Hot Link: checkVolumeChange function (begins at line 110)
3.6 – Change Potentiometer
The change potentiometer functionality will be used to send commands over SPI to the potentiometer. This will allow for an adjustment of the volume of the audio data being input into the microcontroller through the PCM3010 audio codec.
Status: The code for the change potentiometer functionality has not yet been written.
Hot Link: Not Yet Available
3.7 – Input Checking
Input checking is handled in the TO_IRQHandler2 function, which is called via timer interrupt every 1 millisecond. Every 100 milliseconds, the user input values are read and stored.
Those values are checked by the previously mentioned checkVolumeChange function.
-9- ECE 477 Digital Systems Senior Design Project Rev 8/09
Status: The code for the input checking is partially complete, as it does not currently check inputs from the voice recognition module. However, the code as written, which checks only the pushbutton inputs, is working properly.
Hot Link: TO_IRQHandler2 function (begins at line 34)
3.8 – Display Updating
The display updating code is used to display status changes to the user. In order to display text onto the μOLED display, an initial message must be sent to the display, followed by the text itself, followed by a termination character. An example of this can be seen in the main function. To simplify the process, a preprint function is called, followed by a standard printf message, followed by an individual sendchar function, which sends the termination character.
This prevents the programmer from having to write the initial message code repeatedly when trying to interact with the display.
Status: The code for display updating is complete and functioning properly.
Hot Link: preprint function (begins at line 98)
3.9 – I2S/UART0 Interfacing
The I2S/UART0 interfacing code is used to send and receive audio to and from the
PCM3010 audio codec. It is also used to send and receive audio data to and from the XBee wireless modules.
Status: The I2S interfacing code has not yet been written, but the XBee interfacing code is complete and functioning properly.
Hot Link: sendchar0 function (begins at line 103)
3.10 – XBee Receive / Audio Out
-10- ECE 477 Digital Systems Senior Design Project Rev 8/09
The current code temporarily uses the ADC and DAC to input and output audio because the I2S code isn’t yet complete. The XBee receive and audio out function is called by a UART0 receive interrupt. This functionality is only present in the receiving station.
Status: The code for the XBee Receive and Audio Out functionality is complete and functioning properly.
Hot Link: int_serial0 function (begins at line 30)
3.11 – XBee Send / Audio In
The XBee Send / Audio In code is currently housed in the main function, and only occurs in the base station. The code is housed in the main function because it is temporarily using ADC and DAC instead of the I2S interface. As often as possible, the microcontroller reads a value in over the ADC and transmits it over the XBee module to the receiving station. When the more complicated I2S code is written, it will be moved to a separate function that is called by the main function.
Status: The temporary ADC/DAC code is complete and functioning properly, but the final I2S interfacing code has not yet been written.
Hot Link: Main function (begins at line 188)
4.0 Summary
We are Wireless Audio is a wireless speaker system that utilizes wireless protocols to transmit audio from a base station to a receiving station. It contains a microcontroller-driven base station on which the user will be able to adjust the volume manually, mute the volume, and power on and off the device. The user will also be able to use short speech commands to perform the functions of volume up, volume down, and mute. The user will be able to interface his or her portable device with the base station. The receiving station will play the audio on
-11- ECE 477 Digital Systems Senior Design Project Rev 8/09 either external speakers that the user provides, or internal speakers built into the receiving station.
The software design for WaWA utilizes the UART, I2S, SPI, and GPIO interfaces of the
LPC2377 microcontroller. Using these interfaces, along with built-in timer functionalities, the software is able to perform all of the tasks required by the WaWA design.
-12- ECE 477 Digital Systems Senior Design Project Rev 8/09
List of References
[1] NXP. (2010). “LPC2377/2388 Product data sheet” [Online]. Available: http://www.nxp.com/documents/data_sheet/LPC2377_78.pdf
[2] Texas Instruments. (2002). “PCM3010” [Online]. Available: http://www.ti.com/lit/gpn/pcm3010
[3] Digi International, Inc. (2009). “XBee/XBee PRO RF Modules” [Online]. Available: http://www.digi.com/hottag.jsp?ht=/pdf/ds_xbeezbmodules.pdf
[4] Parallax, Inc. (2008). “uOLED-128-G1 Users Manual” [Online]. Available: http://www.jameco.com/Jameco/Products/ProdDS/2110035.pdf
[5] Analog Devices. (2010). “AD 5174 Single-Channel, 1024 Position, Digital Rheostat with SPI Interface and 50-TP Memory” [Online]. Available: http://www.analog.com/static/imported-files/data_sheets/AD5174.pdf
[6] HMC. “HM2007 Speech Recognition” [Online]. Available: http://www.imagesco.com/speech/HM2007.pdf
[7] Keil. (2011). “µVision IDE Overview” [Online]. Available: http://www.keil.com/uvision/
[8] Keil. (2011). “MCB2370 Evaluation Board” [Online]. Available: http://www.keil.com/mcb2300/mcb2370.asp
-13- ECE 477 Digital Systems Senior Design Project Rev 8/09
Appendix A: Flowchart for Main Program
Appendix A-1: Flowchart for Base Station
-14- ECE 477 Digital Systems Senior Design Project Rev 8/09
Appendix A-2: Flowchart for Receiving Station
-15- ECE 477 Digital Systems Senior Design Project Rev 8/09
Appendix B: Hierarchical Block Diagram of Code Organization
-16-