Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

How to create Hardware/software system to achieve design goals

By Naman Govil August 30, 2013

Hardware/software partitioning is the problem of dividing an application’s computations into a part that executes as sequential instructions on a microprocessor (the “software”) and a part 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.

Introduction:

The aim of the project is to implement a system based on Hardware/Software Co-Design on a Spartan 3E FPGA 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. Though this project can be implemented by use of either FPGA or microcontroller only, but that is not the aim here. We want to introduce this concept so that it can be applied later in problems where partitioning can actually make a difference in the performance.

System Architecture:

 

Overview of FPGA based Hardware Software Co-Design

Fig. 1: Overview of FPGA based Hardware Software Co-Design

Components Required:

            1.      Nexys 2 Spartan 3E FPGA Board

            2.      Microcontroller – Atmega16 + LCD

            3.     8Ohm Speaker

            4.      Connectors

            5.      74LS245 IC

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.

 

Circuit Diagram of Nexys2 Pmod Connector

Fig. 2: Circuit Diagram of Nexys2 Pmod Connector

·         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 triggered 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.

·         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. This is not the focus here so we will not go there.

  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.

        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.

Table Listing PMod Connectors

Fig. 3: Table listing PMod Connectors

       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.

Conclusion: 

This was a simple experiment to showcase the concept of Hardware-Software co-design. 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:

Image of 4-slide Switch on FPGA Board

Fig. 4: Image of 4-slide switch on FPGA board

74LS245

Project Source Code

###


// Program to use External (Hardware) Interrupts of AVR Microcontroller (ATmega16)
#include "lcd.h"
#include
#include
#include
#include "pcm_sample.h"
#include
#include
#define SAMPLE_RATE 8000;
 
volatile uint16_t sample;
int sample_count;
 
 
 
/* initialise the PWM */
void pwm_init(void)
{
    lcd_init();
/* use OC1A pin as output */
    DDRD = _BV(PD5);
 
    /* 
    * clear OC1A on compare match 
    * set OC1A at BOTTOM, non-inverting mode
    * Fast PWM, 8bit
    */
    TCCR1A = _BV(COM1A1) | _BV(WGM10);
    
    /* 
    * Fast PWM, 8bit
    * Prescaler: clk/1 = 8MHz
    * PWM frequency = 8MHz / (255 + 1) = 31.25kHz
    */
    TCCR1B = _BV(WGM12) | _BV(CS10);
    
    /* set initial duty cycle to zero */
    OCR1A = 0;
    
    /* Setup Timer0 */
   int a;
   a = PINB;    //since pins are connected at PB0,PB1,PB2,PB3 the codes will form integers as 1,2,3,4 
   //lcd_print(a,10);
   if(a==1)
   {
_delay_ms(100);
OCR1A = pgm_read_byte(&pcm_samples[sample++]);  //reading the serial flash completely once
if(sample>pcm_length)sample=0;  //after reading making the counter=0
lcd_send_string("A");
   }
if(a==2)
{
 
lcd_send_string("B");
_delay_ms(100);
OCR1A = pgm_read_byte(&pcm_samples[sample++]);
if(sample>pcm_length)sample=0;
_delay_ms(200);
OCR1A = pgm_read_byte(&pcm_samples[sample++]);
if(sample>pcm_length)sample=0;
 
 
}
if(a==3)
{
lcd_send_string("C");
_delay_ms(100);
OCR1A = pgm_read_byte(&pcm_samples[sample++]);
if(sample>pcm_length)sample=0;
_delay_ms(200);
OCR1A = pgm_read_byte(&pcm_samples[sample++]);
if(sample>pcm_length)sample=0;
_delay_ms(300);
OCR1A = pgm_read_byte(&pcm_samples[sample++]);
if(sample>pcm_length)sample=0;
 
}
if(a==4)
{
 
lcd_send_string("D");
_delay_ms(100);
OCR1A = pgm_read_byte(&pcm_samples[sample++]);
if(sample>pcm_length)sample=0;
_delay_ms(200);
OCR1A = pgm_read_byte(&pcm_samples[sample++]);
if(sample>pcm_length)sample=0;
_delay_ms(300);
OCR1A = pgm_read_byte(&pcm_samples[sample++]);
if(sample>pcm_length)sample=0;
_delay_ms(400);
OCR1A = pgm_read_byte(&pcm_samples[sample++]);
if(sample>pcm_length)sample=0;
}
   
}
 
ISR (INT0_vect)
{
pwm_init();
}
 
 
int main(void)
{
lcd_init();
cli();
GICR =(1< //Set Bit6 of GICR to unmask INT0 interrupt.
MCUCR =(3<
sei();
while(1)
{
}
}
 


Filed Under: Electronic Projects
Tagged With: hardware, software
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: 5G Technology
This Tech Toolbox covers the basics of 5G technology plus a story about how engineers designed and built a prototype DSL router mostly from old cellphone parts. Download this first 5G/wired/wireless communications Tech Toolbox to learn more!

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • System for measuring the amount of Joules delivered from a capacitor discharge.
  • Two sections broadband impedance matching
  • The GaN revolution must now happen?
  • How to find the resonance frequency and impedance of a planar spiral coil in HFSS?
  • PhD for Electronics Designers

RSS Electro-Tech-Online.com Discussions

  • The Analog Gods Hate Me
  • Impact of Tariffs on PCB Fab
  • More fun with ws2812 this time XC8 and CLC
  • I Wanna build a robot
  • Wierd makita battery

Featured – LoRa/LoRaWan Series

  • What is the LoRaWAN network and how does it work?
  • Understanding LoRa architecture: nodes, gateways, and servers
  • Revolutionizing RF: LoRa applications and advantages
  • How to build a LoRa gateway using Raspberry Pi
  • How LoRa enables long-range communication
  • How communication works between two LoRa end-node devices

Recent Articles

  • The top five AI startups to watch in 2025
  • STMicroelectronics unveils SoC based on secure MCU
  • Nexperia’s 48 V ESD diodes support higher data rates with ultra-low capacitance design
  • Taoglas releases Patriot antenna with 18 integrated elements covering 600 to 6000 MHz
  • Amphenol RF introduces SMPM to SMPM assemblies on RG-178 cable

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe