Sie sind auf Seite 1von 6

1|Page

Hardware Software Co-design


Naman Govil

Introduction:
Hardware/software partitioning is dividing an application's computations into two parts. First, a part that executes as sequential instructions on a microprocessor (the "software") and second that runs as parallel circuits on some IC fabric like an ASIC or FPGA (the "hardware"), such as to achieve design goals set for metrics like performance, power, size, and cost.

Aim of the Project:


The aim is to implement a system based on Hardware/Software Co-Design on a Digilent Nexys 2 board and a Microcontroller using Xilinx IDE tool. Alphabets and/or numbers are entered through keyboard (push buttons on the FPGA) and are in-turn displayed on the LCD display (on the Microcontroller), at the same time audio corresponding to the key being pressed will be played on a speaker. The system is implemented in both hardware and software. VHDL is used as hardware description language and C as software.

System Architecture:

Fig1: Block Diagram

Govil UG2k11

2|Page

Components Required:
1. 2. 3. 4. 5. Nexys 2 Spartan 3E FPGA Board Boot-Loader Kit Atmega16 + LCD 8 Speaker Connectors 74LS244 IC or any variant (Level Shifter: 3.3V to 5V)

Construction:
A. FPGA The FPGA has to be configured to take the input from the user through its input switches (or push button switches). Hence the first step is to configure some switches as the input to the FPGA. Next, we need to make sure that each switch corresponds to a different input. Hence we will give a code (4 bit) to uniquely identify each input. Since, this is a prototype we will define just 4 inputs. And hence code them as: A => 0001 B => 0010 C => 0011 D => 0100 That is, as soon as a switch is pressed, we will identify it using the 4 bit code unique for it. The next thing to be done from the FPGA is to send these 4 bits to the microcontroller. Communication: The communication can be either Synchronous or Asynchronous. If you prefer Asynchronous mode, then parallel transmission will be the fastest mode to choose. If you prefer Synchronous mode, I would recommend setting up of SPI between the FPGA (master) and microcontroller (slave). Here I will be using Asynchronous Parallel Transmission. For transmission we will make use of Peripheral Connectors (PMod Connectors) on the Spartan 3E board. The figure bellow explains this in detail.

Govil UG2k11

3|Page

Fig 2: PMod Connectors We can configure the PMods as both Input and Output. Here they will be set as output.

B. Microcontroller This unit has mainly two tasks. First, displaying the character on the LCD. Second, playing the sound corresponding to the character on the speaker. Task 1: Display Since we are using parallel communication, each of those transmission lines are connected to corresponding input pins on microcontroller. Now there can be two ways to ensure data is read correctly; 1. The pins are continuously polled to check if there is any activity. Once, there is, the value is read and then stored in a variable. 2. We set up an interrupt. This interrupt is sent from the FPGA when transmission lines are going to send the bits. Once, the interrupt is received, the value is read and then stored in the variable.

Govil UG2k11

4|Page

The 2nd method is more efficient than the 1st one. Hence we will run with it. Hence the value is read by using the PIN<port no> variable and stored in some variable of our choice. Task 2: Sound We have to play a sound on the 8 speaker. For this we will use the internal flash of the microcontroller. We will store a sample sound (say a beep) in the memory. And we will play it according to the input. That is, A means playing the beep once. B means playing it twice, and so-on. The microcontroller we are using here is the Atmega16 which has just 16K Bytes of internal flash. Hence we cannot store many different sounds in this much memory. To achieve this we need to use an external flash and interface it with the microcontroller. To play PCM audio on the AVR microcontroller, we will make use of AVR's high speed PWM (fast PWM Mode). It almost sounds fine and can be used for simple projects that require sound effects. Step1: Create a .wav file. If you don't have any use the following link and convert text to speech. Save it as .wav file.
http://www2.research.att.com/~ttsweb/tts/demo.php

Step2: Convert the created wav file into 8 bit unsigned 8000
samples per second wav file using the software switch from NCH. It can be found here:
http://www.nch.com.au/switch/index.html

Step3: Convert the 8 bit wav file to a sample c file using the
software below.
http://darkfader.net/ngpc/files/wav2c.zip

Step4: Copy the created samples onto the header file


pcm_sample and save it. In essence, what we are doing here is taking a sound sample, and then sampling it to create finite (8000) samples each of 8 bits. These samples are stored in the flash using the PROG_MEM command (due to use of avr/pgmspace library). These samples will act as the duty cycle for the PWM that will be generated. We set the initial duty cycle (value in the OCR1A register) as 0. Thereafter, samples will be continuously read from the flash and will be written to the OCR1A. Finally the speaker will be attached to the output of the PWM (OC1A) and we will be able to hear the sounds. To use the internal flash, we make use of the following functions: 1. const long pcm_length=6800; const unsigned char pcm_samples[] PROGMEM ={ enter samples here }; This function is used to make the header file pcm_sample which will be used later.
Govil UG2k11

5|Page

2. pgm_read_byte(&pcm_samples[sample++]); This function is used to read byte after byte from the header file.

Connections:
For the FPGA: 1. The 4 slide switches SW0, SW1, SW2 and SW3 will be used as input.

2. Next for output from the FPGA, we will use PMod JA. The connections are: Interrupt (O) is connected to JA1 "L15" Transmission Line "Z0" connected to JA2 "K12" Transmission Line "Z1" connected to JA3 "L17" Transmission Line "Z2" connected to JA4 "M15" Transmission Line "Z3" connected to JA7 "K13" Note1: We cannot use JA5, JA6 since they are predefined to be used as GND, VCC. Note2: Since the Spartan 3E works at 3.3V Logic and the Atmega16 at 5V Logic, we need to connect a Logic Shifter IC like 74LS245 to level up the transmission lines before connecting them to the PORT of the microcontroller. For the Microcontroller: 1. First connect the interrupt to PD2 (since we are using INT0, can be anything depending on your choice). Then connect the transmission lines to pins 0-3 of any port. Here, Port B is used. 2. Connect the speaker through a Low-Pass filter (resistor (1k) + capacitor (470uf) connected to GND) to PD5 (OC1A-PWM output).

Working:
It can be observed that as soon as we press a switch on the FPGA, we can see the corresponding letter on the LCD and hear the number of beats on the speaker.

Govil UG2k11

6|Page

Conclusion:
This was a simple experiment to showcase the concept of Hardware-Software codesign. Though this project on its own does not really exploit the full potential of this concept but it is a good start for beginners who can learn from it and use this in projects of their own.

Pin Diagrams:

74LS244

Govil UG2k11