[ieee 2012 tecnolog as aplicadas a la ense anza de la electr nica (technologies applied to...

6
Utilizing a PIC18F8722 microcontroller to automate a laboratory experiment Alejandro Ayala Alfonso, Silvestre Rodríguez Pérez, Oswaldo González Hernández, Beatriz Rodríguez Mendoza, Manuel Rodríguez Valido and Efrén García Hernández Dpto. de Física Fundamental y Exp., Electrónica y Sistemas Universidad de La Laguna La Laguna, Tenerife, Spain [email protected], [email protected], [email protected], [email protected], [email protected] AbstractThis paper presents the design and implementation of a laboratory project for first-year Bachelor of Science undergraduates that is intended to consolidate concepts in the field of Physics. The laboratory experiment implements a plane whose inclination can be manually modified by the user (student or instructor), and contains a processing device based on a PIC 18F8722 microcontroller, which oversees the acquisition and processing of data supplied by different sensors located along the plane. This makes it possible for the kinetic parameters (speed and acceleration) associated with the descent of a ball rolling down the plane to be automatically and accurately measured. Moreover, the system has a radio communication module that allows it to send information to the students’ laptops if these are equipped with another radio module. Therefore, the experiment can be performed in the laboratory by students who directly control all the process or by the teacher while the students observe the results on their own laptops. This practical experiment was implemented as part of a senior-year project by Electronics Engineering majors. The designers (students) of this project were able to see how their knowledge of Electronics can help them to implement complex applications that can be very useful to teaching activities. Microcontrollers, analog-to-digital and digital-to-analog converters, radio beams, communications protocols I. INTRODUCTION Microcontrollers [1] are found in a wide variety of common devices these days, both in the home (washers, microwaves, etc.) and elsewhere (automobiles, industry), where they are used in an endless number of applications. It is important, therefore, for electronics students to be able to conduct experiments based on these devices that allow them to apply their knowledge to the development of projects that consolidate their training. In keeping with the above, then, the purpose of this paper is to design and implement a laboratory experiment that allows students to study the movement of a ball on an inclined plane. The system, whose general block diagram is shown in Fig. 1, is controlled by means of a PIC18F8722 microcontroller [1, 2], which allows for the acquisition of highly precise data on the distance traveled by the ball as a function of time through the use of infrared sensors that detect the motion of the ball as it travels along the inclined plane. The resulting data are shown on the screen of a computer that is connected to the acquisition system through an RS232 port. This graphical interface greatly simplifies the user’s control of the system. Specifically, the user can, with a simple mouse click, see and, if necessary, adjust the inclined plane’s angle of elevation, release the ball while simultaneously starting the timing sequence or see plots of the distance, speed or acceleration versus time on the computer screen. The system’s performance is enhanced by means of a so- called “student module” that, when connected to the computer’s USB port, lets him see the same data that is being displayed on the instructor’s PC, relayed by GFSK modulation [3]. Figure 1. System block diagram Receiver P I C 1 8 F 8 7 2 2 Elevation angle potentiometer Infrared sensors Adjustment and measurement of elevation angle Ball release Transmitter RS232 USB 978-1-4673-2486-1/12/$31.00 ©2012 IEEE 243

Upload: efren-garcia

Post on 31-Mar-2017

214 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: [IEEE 2012 Tecnolog as Aplicadas a la Ense anza de la Electr nica (Technologies Applied to Electronics Teaching) (TAEE) - Vigo, Spain (2012.06.13-2012.06.15)] 2012 Technologies Applied

Utilizing a PIC18F8722 microcontroller to automate a laboratory experiment

Alejandro Ayala Alfonso, Silvestre Rodríguez Pérez, Oswaldo González Hernández, Beatriz Rodríguez Mendoza, Manuel Rodríguez Valido and Efrén García Hernández Dpto. de Física Fundamental y Exp., Electrónica y Sistemas

Universidad de La Laguna La Laguna, Tenerife, Spain

[email protected], [email protected], [email protected], [email protected], [email protected]

Abstract— This paper presents the design and implementation of a laboratory project for first-year Bachelor of Science undergraduates that is intended to consolidate concepts in the field of Physics. The laboratory experiment implements a plane whose inclination can be manually modified by the user (student or instructor), and contains a processing device based on a PIC 18F8722 microcontroller, which oversees the acquisition and processing of data supplied by different sensors located along the plane. This makes it possible for the kinetic parameters (speed and acceleration) associated with the descent of a ball rolling down the plane to be automatically and accurately measured. Moreover, the system has a radio communication module that allows it to send information to the students’ laptops if these are equipped with another radio module. Therefore, the experiment can be performed in the laboratory by students who directly control all the process or by the teacher while the students observe the results on their own laptops. This practical experiment was implemented as part of a senior-year project by Electronics Engineering majors. The designers (students) of this project were able to see how their knowledge of Electronics can help them to implement complex applications that can be very useful to teaching activities.

Microcontrollers, analog-to-digital and digital-to-analog converters, radio beams, communications protocols

I. INTRODUCTION

Microcontrollers [1] are found in a wide variety of common devices these days, both in the home (washers, microwaves, etc.) and elsewhere (automobiles, industry), where they are used in an endless number of applications. It is important, therefore, for electronics students to be able to conduct experiments based on these devices that allow them to apply their knowledge to the development of projects that consolidate their training. In keeping with the above, then, the purpose of this paper is to design and implement a laboratory experiment that allows students to study the movement of a ball on an inclined plane.

The system, whose general block diagram is shown in Fig. 1, is controlled by means of a PIC18F8722 microcontroller [1, 2], which allows for the acquisition of highly precise data on the distance traveled by the ball as a function of time through

the use of infrared sensors that detect the motion of the ball as it travels along the inclined plane.

The resulting data are shown on the screen of a computer that is connected to the acquisition system through an RS232 port. This graphical interface greatly simplifies the user’s control of the system. Specifically, the user can, with a simple mouse click, see and, if necessary, adjust the inclined plane’s angle of elevation, release the ball while simultaneously starting the timing sequence or see plots of the distance, speed or acceleration versus time on the computer screen.

The system’s performance is enhanced by means of a so-called “student module” that, when connected to the computer’s USB port, lets him see the same data that is being displayed on the instructor’s PC, relayed by GFSK modulation [3].

Figure 1. System block diagram

Receiver

P I C 1 8 F 8 7 2 2

Elevation angle potentiometer

Infrared sensors

Adjustment and measurement of elevation angle

Ball release

Transmitter

RS232

USB

978-1-4673-2486-1/12/$31.00 ©2012 IEEE 243

Page 2: [IEEE 2012 Tecnolog as Aplicadas a la Ense anza de la Electr nica (Technologies Applied to Electronics Teaching) (TAEE) - Vigo, Spain (2012.06.13-2012.06.15)] 2012 Technologies Applied

II. CHARACTERISTICS OF THE INCLINED PLANE

Before the various electronics blocks are designed, an inclined plane must first be constructed and equipped with the different sensors that are required to detect the ball as it moves and to measure its angle of elevation.

The ramp was built with the assistance of the University of La Laguna’s carpentry workshop. Its dimensions are as shown in Figure 2. Its length is determined by the need to have ten measuring points spaced 10 centimeters apart. Its width must be sufficient to easily accommodate both the track on which the ball will move as well as the electronic circuitry located at each of the aforementioned measuring points. The ramp is made of wood, which makes for a lightweight design that is easily transportable.

Figure 2. Inclined plane and it´s dimensions

A consideration taken into account during construction was that the wires used and the transmitter and receiver boards that comprise the motion sensors be hidden from view, thus making for a more aesthetic design.

III. DETERMINING THE ANGLE OF ELEVATION

The system is designed to provide the user with a graphical interface from which to see and control all of the variables, including the angle of elevation (α), which is measured using a linear potentiometer operating as a voltage divider that generates a voltage that is directly proportional to this angle. This potentiometer rotates on its axis as the plane moves up or down, resulting in a voltage change at its center terminal. Fig. 3 shows the location of the potentiometer in the system.

Figure 3. Potentiometer to measure the angle of elevation

Once the analog signal from the potentiometer is received, the voltage is relayed to the internal analog-to-digital converter (ADC) [4] on the PIC18F8722 (configured to provide 8-bit precision), where it is digitized so that, by means of the corresponding calibration, the value of α can be obtained.

When the plane is in a horizontal position, however α = 0º, the potentiometer is at about the midpoint in its range of travel, meaning that at 0º, the ADC would still be receiving a voltage input, which would result in losing some of the resolution made available by the 256 levels. To address this problem, the following modifications were made:

• The signal from the potentiometer is not sent directly to the microcontroller’s internal ADC; instead, its voltage is subtracted from the output of a DAC0808 digital-to-analog converter (DAC) [4], which is controlled by the microcontroller itself (Fig. 4). Thus, when α=0º, there will be 0 volts at the output of the subtractor (connected to the input of the ADC on the PIC18F8722 via U21), and therefore a digital zero. This zero adjustment can be repeated as often as desired through the graphical interface.

• The reference voltage Vref+ is sent through a voltage divider to the PIC, such that when α=0º, the value shown by the ADC will be 0 when α=0º and 256 when α is at its maximum value (Table I).

Equation (1) shows the relationship between α and the digital value (DV) provided by the ADC, which the microcontroller needs to determine its value.

VD*212.0=α (1)

TABLE I.

Angle Subtractor

output voltage

Digital value

α=0º 0 0

α=54º Vref+ 255

IV. BALL RELEASE

The experiment starts when the ball is released from an initial starting point, which triggers the start of the timing sequence that measures how long it takes for the ball to travel along each of the segments into which the plane is divided.

This is done by means of an electromagnet, which was taken from a relay and placed at the top of the inclined plane (Fig. 5). If a current is passed through the electromagnet, it magnetizes, holding the ball in place. Since its core is made of wrought iron, interrupting the current releases the ball and starts the timing sequence.

Since the balls can be of different diameters, a metal piece was designed that allows the ball to be moved longitudinally and centered along the start line while being held place by the electromagnet (Fig. 5). The microcontroller uses the output of a transistor operating in the saturation and cut-off regions to control the magnetization of the electromagnet.

244

Page 3: [IEEE 2012 Tecnolog as Aplicadas a la Ense anza de la Electr nica (Technologies Applied to Electronics Teaching) (TAEE) - Vigo, Spain (2012.06.13-2012.06.15)] 2012 Technologies Applied

V. MEASUREMENTS

In this laboratory experiment, a metal ball with a selectable mass is released from rest and allowed to roll down a plane inclined at an angle α. The time the ball takes to cover 10-centimeter segments is then measured over a span of 1 meter.

Figure 5. Mechanism for holding and releasing the ball

The passage of the ball through each segment is detected by means of an infrared (IR) diode located at each measuring point and whose emission beam is directed at a photodiode. The passing of the ball interrupts this beam, generating a signal that is used by the PIC to measure the time. Fig. 6 shows the arrangement of diodes and photodiodes along the inclined plane. The latter, connected all in series, output a voltage V0 when light shines on them (terminal U4 in Fig. 7). This voltage is compared with the output of the R11 voltage divider, such that the latter is always lower than the former. Every time a ball passes in front of a photodiode and interrupts the beam of light, the voltage drops below that supplied by the divider. This translates into a change in the logic level output by the LM339 and detected by the PIC 18F8722. In other words, as the ball rolls down the inclined plane, a train of ten pulses is generated that will be used by the microcontroller to determine the time required for the ball to travel the length of each 10-centimeter segment.

Figure 6. Arrangement of diodes and photodiodes along the inclined plane

One drawback of the design, however, is that the photodiodes are sensitive to ambient light, which translates into a higher voltage. This means that when the ball interrupts the light beam, the voltage change is not sufficient to cause a change in the output voltage of the LM339 comparator.

To solve this problem, potentiometer R11 in Fig. 7 was replaced by the circuit in Fig. 8, which relies on a second DAC (DAC0808). Thus, before each experiment, the system increases the reference voltage until the voltage of the photodiodes is reached (the PIC will detect this by the change in the level of the comparator output), at which time its value is lowered to be just a few millivolts below V0, thus ensuring that the decrease in voltage caused by the ball passing in front of each measuring point will alter the comparator output.

VI. USER INTERFACE

Two interfaces, called the instructor’s and student’s interface, were developed using Nokia Qt Creator to allow users to better manipulate the system. The first is shown in Fig. 9, and consists of a series of user-clickable buttons. These will be described in the order in which they are used during an experiment.

R195,6k

U25

RH1

1

+12

U26

RH2

1

-12

U18

uA741

+3

-2

V+

7V

-4

OUT6

OS11

OS25

U27

RH3

1

R14

1k

R15

1k

R161k

U28

RH41

U29

RH61

R17

1k

-12

U30

RH71

U31

RH51

U19

ENT. POTENCIOMETRO

1

+12

U21

SEÑAL AL CAD PIC

1

C11

0.1uF

R20

5,6k

+12

-12

U22

DAC 0808

11

GND2

-12V3

LF3514

A15

A26

A37

A48

COND16

R-GND15

+12V14

5V13

A812

A711

A610

A59

R185,6k

U23

LF351/301/TI

+3

-2

V+

7V

-4

OUT6

VCC

U24

RH0

1

Figure 4. Wiring diagram for zeroing the elevation angle

SIGNAL TO ADC

POTENTIOMETER

245

Page 4: [IEEE 2012 Tecnolog as Aplicadas a la Ense anza de la Electr nica (Technologies Applied to Electronics Teaching) (TAEE) - Vigo, Spain (2012.06.13-2012.06.15)] 2012 Technologies Applied

R215,6k

U32

RJ1

1

U33

RJ2

1

+12

U35

RJ3

1

U36

RJ41

U37

RJ61

+12

-12

U38

RJ71

U39

RJ51

C12

0.1uF

R22

5,6k

U40

DAC 0808

11

GND2

-12V3

LF3514

A15

A26

A37

A48

COND16

R-GND15

+12V14

5V13

A812

A711

A610

A59

R23

5,6k

U41

LF351/301/TI

+3

-2

V+7

V-4

OUT6

VCC

U42

RJ0

1

-12

U6

PATA 4 COMPARADOR 339

1

Figure 8. Circuit to compensate for ambient light interference.

First, once the program for the interface is executed, the COM port that the PC will use to communicate with the PIC using the RS232 standard [3] is selected with the mouse. This is done by expanding the drop-down menu and choosing from among the ports shown (in this case COM3 has been selected).

Next, communications are established between the PIC18F8722 microcontroller and the PC by clicking on the “ON” button. These steps need only be performed once.

At the start, we need to verify that the elevation angle α is 0º when the plane is laid flat. Clicking on “SHOW ANGLE” will display the value of α in the ELEVATION box at the top, located alongside the protractor. If this value differs from 0º, we must click on the CALIBRATE button, located at the bottom left of the screen, which will adjust the value of α to 0º.

The instructor has the option to display the elevation angle or to have the students calculate this parameter, instead of simply letting them read it off the screen.

Once this adjustment is made, the inclined plane is raised to the desired value of α. Once the plane is secured at this angle,

the “ACTIVATE” button is clicked. This will activate the electromagnet shown in Fig. 5, which will hold the ball in place. The ball/electromagnet assembly is then positioned so as to place the ball at the starting point. This step is only necessary if the diameter of the ball selected is modified.

Figure 9. Instructor´s interface.

The “START” button is then clicked. This interrupts the current to the electromagnet, releasing the ball and starting the timing sequence.

As the ball descends past each of the ten measuring points located along the plane, the table at the far left of the screen will start to display the times, expressed in milliseconds, associated with each of these points.

The buttons along the bottom of the screen (DISTANCE/TIME, SPEED/TIME, and ACCELERATION/TIME) allow the user to display the associated graphs in the central box on the screen. Fig. 10 shows an example of these graphs.

The menu can also be used to enable the transmission of data in real time to multiple users. This is done by clicking on the “ACTIVATE RADIO” button (at which time the button label will change to “DEACTIVATE RADIO”).

U1ALM324

+3

-2

V+

4V

-11

OUT1

U2A

LM339

+5

-4

V+

3V

-12

OUT2

U3B

LM324

+5

-6

V+

4V

-11

OUT7

U4

TENSIÓN FOTODIODOS

1

R1

470k

R2

1k

R3

1k

C2

47n

R4

1k

VCC

VCCVCC

C3

10uF

VCC

R61k R7

820

U5

PULSOS PIC

1

C41uF

R112KSET = 0.5

VCC

Figure 7. Wiring diagram of the timing circuit.

LM339

PULSES

VOLTAGE FROM PHOTODIODES

246

Page 5: [IEEE 2012 Tecnolog as Aplicadas a la Ense anza de la Electr nica (Technologies Applied to Electronics Teaching) (TAEE) - Vigo, Spain (2012.06.13-2012.06.15)] 2012 Technologies Applied

Figure 10. Graphs of the changes in distance, speed and acceleration versus time (ms).

By activating the radio, the PIC uses a semi-duplex GFSK transmitter/receiver to relay the data via a USART to each student’s computer. This system has a 1000-meter range and operates on the 431-478 MHz band. The carrier frequency, transmission power, modulation speed and frequency deviation are all configurable and compatible with both TTL and RS232 levels.

Each student has a receiver whose output is connected to an RS232 to USB adaptor that is plugged into the student’s PC. This same PC which will also have installed on it the student module, which is similar to the one shown in Fig. 9 but without some of the features, such as being able to release the ball or adjust the zero point of α. The student will, however, be able to select from among the three data displays available (Fig. 11).

Figure 11. Student PC set-up

VII. EXPERIMENTAL RESULTS

The system we have implemented yields measurements involving four variables: time (t), elevation angle (α), mass of the ball (M) and the distance traveled by the ball (d). Thus, the user can determine the time required for a ball of mass M to travel a distance of 100 cm (measured in 10-cm intervals) when the inclined plane is at an elevation of α degrees. The resulting experimental data can be used to obtain graphs for d(t), v(t) and a(t).

The system, thus, exhibits great versatility in terms of the various experiments available and of the complementary graphical displays it offers and which make it possible for students to obtain a better understanding of the physics of inclined planes.

Three experimental runs were conducted with balls weighing 63.93 g, 40.27 g and 32.76 g. The goal of the runs was to obtain the speed and acceleration for each mass for different values of α and to display the results.

By way of example, Fig. 12 shows the change in the speed of the ball as a function of time for different masses and elevation angles. Fig. 13 shows a similar graph for acceleration versus mass for different values of α.

This last result is particularly interesting in that it shows how acceleration increases with α, despite the theoretical independence of acceleration and mass. Instructors can have students discuss this phenomenon to try to develop possible explanations, such as slippage of the ball.

(a) Distance, m

(b) Speed, m/s

(c) Acceleration, m/s2

247

Page 6: [IEEE 2012 Tecnolog as Aplicadas a la Ense anza de la Electr nica (Technologies Applied to Electronics Teaching) (TAEE) - Vigo, Spain (2012.06.13-2012.06.15)] 2012 Technologies Applied

Figure 12. Change in speed with time for different M and α

0

1

2

3

4

5

6

7

0 10 20 30 40 50 60 70

Mass (g)

Acc

eler

atio

m (

m/s

2)

α = 7º

α = 14º

α = 24º

α = 36º

α = 47º

Figure 13. Change in a with M for different α

VIII. CONCLUSIONS

We have constructed a system of an educational nature that students can use to demonstrate how a knowledge of electronics can be implemented to design an experimental setup that is of practical use in a physics laboratory. The students can:

Design and implement an electronic circuit.

Work with various laboratory instruments.

Learn to program a PIC microcontroller.

Design a user interface.

Transfer data using radio transmissions and RS232 and USB ports.

REFERENCES [1] J. Mª Angulo y otros, “Microcontroladores PIC”, Editorial Paraninfo,

Madrid, 1997.

[2] PIC16F877 data sheet, http://www.microchip.com

[3] Roy Blake, “Sistemas Electrónicos de Comunicaciones”, Thomson Editorial Learning, Madrid, 2004.

[4] N. R. Malik, “Circuitos Electrónicos”, Editorial Prentice Hall, S.A., Madrid, 1996.

248

Powered by TCPDF (www.tcpdf.org)