TVZ Mechatronics Team


Zagreb University of Applied Sciences, Professional Study in Mechatronics

You are viewing an older revision! See the latest version

Analogni ulazi i izlazi

All exercises in this topic will be carried out using an mbed application board, but you can also use the breadboard and other external components. The application board has 3 inputs prepared for use with an AnalogIn class. Two potenciometers (Pot1 and Pot2) are connected to pins p19 and p20, respectively, and 3.5 mm audio jack is connected to pin p17.

Since mbed NXP LPC1768 has only one analog output on pin p18 for use with an AnalogOut class, mbed application board uses that output via another 3.5 mm audio jack.

You will examine the use of potenciometers as analog inputs in Exercise 1, analog outputs in Exercise 2 and analog communication between two mbeds in Exercise 3.

Exercise 1: Using potenciometers as analog inputs

Write a program that will read the inputs of potentiometers Pot1 and Pot2, calculate the average reading of two potentiometers, and based on the average reading value, turn on or off the four onboard mbed LEDs. Use the following table as rules for LEDs control:

Average reading xLED1LED2LED3LED4
x <= 0.20000
0.2 < x <= 0.41000
0.4 < x <= 0.61100
0.6 < x <= 0.81110
0.8 < x <= 11111

Write your own solution of the program, test it and then compare to the solution given below.

Import programMAB_Potenciometers

Using potenciometers as analog inputs.

Exercise 2: Generating waveforms using analog output

Write a program that generates a simple sawtooth waveform.

One possible solution is given in the program below.

Import programMAB_Waveforms_A

A simple sawtooth waveform generator using analog output.

The oscillogram is shown in the following figure:

/media/uploads/tbjazic/mab_waveforms_a_01.png

Modify the above program to generate smoother sawtooth waveform, with the period kept the same (10 ms). Let the smoothness of the waveform be defined by the potentiometer Pot1, with a value of 0 meaning the above case (not smoothed), and a value of 1 meaning nice smooth waveform.

The solution is given in the program below.

Import programMAB_Waveforms_B

A sawtooth waveform generator using analog output, with smoothness setting over potentiometer.

The oscillogram for Pot1 set to a value of 1 (maximum number of points) is shown in the following figure:

/media/uploads/tbjazic/mab_waveforms_b_01.png

Write a new program that will generate the sinewave waveform with mean value of 1.65 V, peak-to-peak amplitude that can be adjusted over potentiometer Pot1 in the range between 0 and 3.3 V, and frequency that can be adjusted over potentiometer Pot2 in the range between 10 and 20 Hz.

The solution is given in the below program.

Import programMAB_Waveforms_C

A simple sinewave generator with adjustable amplitude and frequency over potentiometers.

A sample oscillogram is shown in the figure below:

/media/uploads/tbjazic/mab_waveforms_c_01.png

Exercise 3: Analog communication between two mbeds

Note

Please ensure you have properly configured Windows serial communication with mbed. Check Windows serial configuration and Serial Communication with a PC.

You will need two mbed application boards (or just two mbeds) for this exercise. Connect the analog output (p18) of the first board to the analog input (p17) of the second board. You can use the 3.5 mm stereo line cable, or directly connect the wires (p18 to p17 and GND to GND).

Write the program for the first mbed that sends the analog value to the second mbed. One possible solution including a terminal is given below.

Import programMAB_AnalogCommunication1

A simple program that sends a value over analog output.

Write the program for the second mbed that receives the analog value sent by the first mbed. A possible including the terminal is given below.

Import programMAB_AnalogCommunication2

A simple program that receives a value over analog input and displays it on a terminal.

Run the programs and both terminals and observe the results. What are the differences if using stereo line cable or plane wires? Does the surrounding noise affect the data transfer?

Čestitke!

Završili ste sve vježbe iz teme Analogni ulazi i izlazi.

Povratak na naslovnu stranicu TVZ Mechatronics Team-a.


All wikipages