Introduction

Signals, including audio (speech, acoustics, music), image (video, multimedia, medical scans) and remote sensing data, are phenomena that vary with time, space, or other parameters. Systems can be regarded as devices that manipulate signals. The disciplines of signal and image processing are concerned with the analysis and synthesis of signals and their interaction with systems. In communications, the objective is to transfer information (signals) from one or many sources to one or many destinations, which requires the design of transmission schemes (e.g., modulation and coding), receivers, and filters.

The Systems, Signals, and Communications area of interest covers the fundamentals of analog and digital signals and systems, the mathematical tools for the analysis of determinate and random signals, and applications to digital signal processing, digital image processing, and digital/analog communications.

Section Overvieliw

This lab uses the FRDM KL46-z in a simple circuit that acts like a piano(or a simple musical instrument ). Using a variable resistor as input, an attached speaker will produce at least an octave of distinct musical notes. Later in the lab we will use a python GUI to make songs and play them on the FRDM KL46-z microcontroller .

Objectives

  • Learn to use a schematic to correctly build a circuit.
  • Download the ECE111 code.
  • Program the FRDM KL46-z microcontroller.

Materials

  • KL-46z.
  • USB to Mini USB Cable.
  • Speaker.
  • ECE111 Tekbots Tool Kit

Task 1: Understanding What is a Signal

What's a Signal?

A signal is a function that contains information about the behavior  of the system or  some phenomenon in the system. Signals may occur naturally and they also could be synthsized. The term is used for referring to a wide variety of information. Examples include:

  • Acoustic waves which convey speech.
  • Electromagnetic waves which could be used to transmit images.

Analog Signals vs Digital Signals

We live in an analog world, meaning that everything around us has infinite possibilities. An example would be the colors you can use to paint an object. Another example is the number of tones us humans can hear.

Some other aspects of life can not be looked at the same way, for example the colors in a computer program can not be infinite. Those types of values are finite and are called digital values.

Since signals are used to convey information, depending on the type of information we could use Analog or Digital.

To read more about this topic use this refernce: Analog VS Digital on Sparkfun.

Task 2: Understanding How Speakers Work

How Do Speakers Work?

In order to translate an electrical signal into an audible sound, speakers contain an electromagnet: a metal coil which creates a magnetic field when an electric current flows through it. This coil behaves much like a permanent magnet, with one particularly handy property: reversing the direction of the current in the coil flips the polarity of the magnet.

Inside a speaker, an electromagnet is placed in front of a permanent magnet. The permanent magnet is fixed firmly into position and the electromagnet is free to move. As pulses of electricity pass through the coil of the electromagnet, the direction of its magnetic field is rapidly changed. This means that it is in turn attracted to and repelled from the permanent magnet, vibrating back and forth.

To read more about this topic use this refernce: How Loud Speakers Work.

Task 3: Programing the KL-46z or kl-46z From Scratch.

In this task we look at how to use Mbed.com to program your FDRM KL-46z.

Add KL-46z to the compiler.

  • After creating an account on mbed go to KL-46z on mbed.com or KL-43 depending on your kit. 
  • Click on the tap "Add to your mbed compiler".

Now you should be on the compiler page, and your correct hardware is added.

  • Explore the different demos in the compiler.

Creating a program.

  1. Create a new program and name it Program-1.
  2. For the template pick Empty Program.
  3. It should look similar to the following figure.

Import mbed.h to the program.

  1. Click on the Import tab in the compiler.
  2. Search for 'mbed'.
  3. Import the 'mbed' library to your compiler.
  4. Your work space should now look like this.

Adding main.cpp to the program.

  1. Click on New File in the 'New' drop down menu.....
  2. Make sure you are in the Program-1 Folder.
  3. Make a file named main.cpp.
  4. You should have the next window.

Writing your program.

  1. Open your main.cpp file.
  2. The first line you need is #include "mbed.h"
  3. The include line tells the compiler that we are going to be using the mbed library files. The mbed library contains the classes, structures and groups that we will uses to program the micro controller.
  4. Before you go further, check the Classes, Structs, and Groups the mbed library provides for you by double clicking on it to see the documentation.
  5. For this program we will be using the DigitalOut class.
  6. Click on mbed library then go to DigitalOut class inside Classes folder.
  7. Look at the DigitalOut Class Reference , understand what is the use of this class you can also read more in your class text book.

Using DigitalOut

  • DigitalOut allows you to create a digital output object, to learn more about Classes and Objects in C++ read  C++ Classes and Objects.
  • For this program you will create and use the digital output to flash one of the LEDs on the KL-46z board.
  • Use the following page to find all available resources on the board FRDM-KL46z Documentation or KL-43z
  • Note where the LED location is on the previous link and the next image.

Figure 2.1 KL-46z Pinout.

Figure 2.2 KL-43z Pinout.

 

Using LEDs

    • Now in your main.cpp write the following code.

#include"mbed.h"

DigitalOut My_led(PTD5); //Create a Digital output in the Location PTD5 which is for the green LED int

main(){ // the start of Main function

while(1){ //Endless loop

My_led = 0; // set digital output named My_led to a value

wait(1);//wait before doing this again

}

}

  1. Compile the code. This will result in downloading a .bin file
  2. Copy the .bin file into the KL-46z or KL-43z.
  3. Press the Reset button on the KL-46z or KL-43z to start running your code.
  4. Look at the green LED. Verify it is on.
  5. Now find out how you can change it to make the red LED light on along with the green led.
  6. Now make another change to have both LEDs blink.

Task 4: Using PWM for tones.

How Does Sound Work?

Sound is simply a movment of air. When you hear something, small parts of your ear are moving because  of the movments in the air. When you speak, your voice causes the air to move.

In the ECE world things are similar. When a speaker receives signal (electricity), it causes parts of the speaker to move back and forth which causes air to move.

Use this page to understand how sound frequncy and the speaker movments relate Sound Frequency and Speakers..

How PWM Works

PWM means Pulse Width Modulation, which is a type of digital signal. It's used in a wide number of applications, in this lab we will use it to generate sound.

    Properties of PWM:
  • Frequncy: The rate at which a PWM signal occurs in one secound.

  • Duty Cycle: How long is the PWM high.

 

Task 5: Using KL46Z to Play Tones.

Build the Circuit

In the previous lab, a potentiometer was created out of conductive paper. In this lab, another potentiometer will be made out of conductive paper, but this time attached to a Popsicle stick so that it will be more robust. This potentiometer will be used as a voltage divider to send an analog voltage to the KL-46z. The microcontroller will then interpret the analog voltage as a specific pitch and play the pitch using a small speaker as shown in figure below.

Figure 2.3 Schematic for the PWM tones circuit.

The figure above is a schematic for the piano circuit that is being built. A schematic is a diagram which shows every component and connection in a circuit. The schematic in the figure above shows how to correctly connect the potentiometer, speaker, capacitor, and microcontroller.

Finish building the circuit according to the schematic. In the end, you will have built a PWM Music Circuit.

 

Program the FDRM KL-46z microcontroller

The code for each lab for ECE 111 is located on the Mbed page for the class. Follow these instructions to download the code.

  1. Navigate to the ECE 111 page on the Mbed website and open the Lab3-Basic code.
  2. Compile the code after picking the correct device KL43 or KL46 z, this will result in downloading a .bin file
  3. Copy the .bin file into the Mbed device.
  4. Press the Reset button to start runing your code.
  5. If you are having issues with the paper clips, feel free to use the a real potentiometer.

 

Check off: show your TA a working circuit.

 

Study Questions

Type answers to the study questions below. Please keep answers clear and concise. Turn in the questions at the beginning of lab next week, on Canvas. You will be required to type all study questions for the future labs as well.

  1. What are some of the applications of signals and systems in everyday life? (Think of anything that has a transmitter and receiver.) Name at least two.
  2. What is the operating frequency for wifi signal?
  3. What is the highest frequency humans can hear?

Challenge

FRDM-KL46z Beat factory

In this section, Python software interfaces with the C++ firmware on the FRDM-KL46z microcontroller to create an embedded system. A GUI built with Python is used to compose a song that the microcontroller will play through its speaker

    1. Navigate to the ECE 111 page on the Mbed website and open the Lab3_GUI code.
    2. Compile the code, this will result in downloading a .bin file
    3. Copy the .bin file into the KL-46z.
    4. Press the Reset button to start runing your code.
    5. Use this Python GUI-Lab3 code , you must install python to be able to run this use this ECE111 Python Installation."Ask TA for more help if needed"
    6. You might need this driver, use this link.

Option 1: Improve the Python GUI used in this lab. There are suggested items at the beginning of the Python file but other improvements are acceptable as well. Come up with a creative idea. The amount of extra credit awarded for this challenge is dependent on the difficulty of the improvement and the effort put in; a harder improvement will earn more points than a simple improvement.

Option 2: There is a similar project on the Mbed website. Use this project as inspiration to add more circuitry or improve the programming of the FRDM-KL46Z.