University of Puerto Rico at Mayagüez Department of Mechanical Engineering INME 4235 – MECHANICAL ENGINEERING LAB I TASK 9: Introduction to Microprocessor-Based Measurements Objective: The purpose of this task is to familiarize you with the BX-24 Developer’s Board and review electric circuit theory. With the opportunity to see a full measurement system, including the sensor, transduction, signal conditioning, and output stages of measurement. Reading assignment for this task: BasicX Quick Tour Handout on Useful Basic X Commands and Calls Class 9 or Task 9 Adendum Materials: To carry out this task the following are provided in the laboratory: 1. Thermistor. 2. Wheatstone bridge circuit 3. Osciloscopio. Procedure: Reading Assingment for this task: For this task, you will not turn in the usual report. Rather, you will hand in specific results for each of various activities that will get you started on microprocessor-based measurements. In Tasks 9 and 10, you will have 1 The task includes four main objectives in support of its purpose: 1. Explain all steps in a simple BasicX program. 2. Display numbers in a 7-segment LED array through BasicX commands. 3. Write a program to measure the time in between two consecutive presses of a button. 4. Calculate the output of an 8-bit D/A converter for the eight combinations of digital inputs. 2 Task 9a: BX-24 Developer’s Board and BasicX Commands You will use a computer to communicate with the BX-24 Developer’s Board. Turn the computer on and start the BasicX Environment. Power the BX-24 Developer’s Board and connect the serial cable between the board and the PC. Set working directories and verify proper communication settings. Open and monitor port COM1. Compile and run program Task9a.bxp, which we will use to verify port communication and note the structure and function of various useful BasicX Commands. Please see the Class 9, section 1, and answer the questions about the program on your task report. PART 9A Sub Main() Dim Dim Dim Dim Dim Dim Dim Counter1 As Integer Counter2 As Integer Firstnumber As Single Secondnumber As Single Answer1 As Single Answer2 As Single Answer3 As Single Firstnumber = 3.0 Secondnumber = 4.0 For Counter1 = 1 To 3 If (Counter1 = 1) Then Answer1 = Firstnumber + Secondnumber Debug.Print Debug.Print "Three plus four is: "; CStr(CInt(Answer1)) ElseIf (Counter1 = 2) Then Answer2 = Firstnumber * Secondnumber Debug.Print "Three times four is: "; CStr(CInt(Answer2)) ElseIf (Counter1 = 3) Then Answer3 = (Firstnumber*100.0)/Secondnumber Debug.Print "Three divided by four is: "; CStr(CInt(Answer3)); " hundredths" Debug.Print End If Next Counter2 = 1 Do While Counter2 <=4 Debug.Print "Mechanical Engineers know electronics." Counter2 = Counter2+1 Call Delay(3.0) Loop End Sub 3 Task 9b: Numeric Displays For this second experiment, you will have BasicX count the numbers 0 to 9 and show the numbers in a seven-segment LED display. Please see the Task 8-Addendum, section 2. Create a program containing individual subprocedures for each number. Make the appropriate connections from the BX-24 system to the PC and from the BX-24 system to the breadboard. Using a Do-Loop command, have the program count from 0-9 and start over indefinitely. To be able to see the numbers, put in a Delay command in between number subprocedure calls. Show your results to your instructor and copy the program on a floppy disk. Then, hand your program in with your report. first Sub Main() Debug.Print "comienzo " Dim Switch As Byte Do Switch = GetPin(11) Debug.Print "el estado del boton es"; CStr(CInt(Switch)) If (Switch = 1) Then Call Nine Call Borrar Call Eight Call Borrar Call Seven Call Borrar Call Six Call Borrar Call Five Call Borrar Call Four Call Borrar Call Three Call Borrar Call Two Call Borrar Call One Call Borrar Call Cero Call Borrar Delay(5.0) End If Loop End Sub Sub One() Call PutPin(20,0) Call PutPin(18,0) Delay(0.5) 4 Call Borrar() Delay(0.5) End Sub Sub Two() Call PutPin(5,0) Call PutPin(20,0) Call PutPin(19,0) Call PutPin(7,0) Call PutPin(16,0) Delay(0.5) Call Borrar() Delay(0.5) End Sub Sub Three() Call PutPin(5,0) Call PutPin(20,0) Call PutPin(19,0) Call PutPin(18,0) Call PutPin(16,0) Delay(0.5) Call Borrar() Delay(0.5) End Sub Sub Four() Call PutPin(6,0) Call PutPin(19,0) Call PutPin(20,0) Call PutPin(18,0) Delay(0.5) Call Borrar() Delay(0.5) End Sub Sub Five() Call PutPin(5,0) Call PutPin(6,0) Call PutPin(19,0) Call PutPin(18,0) Call PutPin(16,0) Delay(0.5) Call Borrar() Delay(0.5) End Sub Sub Six() Call PutPin(5,0) Call PutPin(6,0) Call PutPin(7,0) Call PutPin(16,0) Call PutPin(18,0) Call PutPin(19,0) Delay(0.5) Call Borrar() Delay(0.5) End Sub Sub Seven() Call PutPin(5,0) Call PutPin(20,0) Call PutPin(18,0) Delay(0.5) Call Borrar() 5 Delay(0.5) End Sub Sub Eight() Call PutPin(5,0) Call PutPin(6,0) Call PutPin(7,0) Call PutPin(19,0) Call PutPin(18,0) Call PutPin(16,0) Call PutPin(20,0) Delay(0.5) Call Borrar() Delay(0.5) End Sub Sub Nine() Call PutPin(5,0) Call PutPin(6,0) Call PutPin(19,0) Call PutPin(18,0) Call PutPin(16,0) Call PutPin(20,0) Delay(0.5) Call Borrar() Delay(0.5) End Sub Sub Cero() Call PutPin(5,0) Call PutPin(6,0) Call PutPin(7,0) Call PutPin(18,0) Call PutPin(16,0) Call PutPin(20,0) Delay(0.5) Call Borrar() Delay(0.5) End Sub Sub Borrar() Call PutPin(5,1) Call PutPin(6,1) Call PutPin(7,1) Call PutPin(19,1) Call PutPin(18,1) Call PutPin(16,1) Call PutPin(20,1) End Sub a pin 5 b pin 20 c 18 d 16 e pin 7 f pin 6 g 19 6 Task 9c: Buttons and Timing Task 9c asks you to count the time elapsed in between two consecutive pushes of a button. Since the pushbuttons on the BasicX program require debouncing, the smallest time difference that you will detect is 0.1 seconds. However, for any two consecutive presses of a button greater than 0.1 seconds apart, you will be able to measure the time elapsed in between presses with a fair amount of accuracy (in the order of milliseconds). Connect the output of an on-board pushbutton to pin 12 of the BX-24 board. Then, run the program Task9c.bxp, which will read the state of the pin. When the button is pressed, the program requests the time on the BasicX real time clock. When the button is pressed a second time, the program requests the time again. It then uses a variable to calculate the difference in between these two times. Note that, to get millisecond accuracy, the program separates the integer part from the decimal part. It then multiplies the decimal part by 1000 and reports both the seconds and milliseconds to the screen. Explain how this program works, by stating in your own words what each statement does inside the larger Do-Loop, starting with the Do command and ending with the Loop command. Sub Main() Dim Dim Dim Dim Dim Dim Dim Dim T1 As Single T2 As Single DT As Single DT_Int As Single DT_Decimal As Single DT_Dec_in_ms As Single PinState As Byte Cycle As Boolean Debug.Print "Starting" PinState = 0 Do PinState = GetPin(11) Delay(0.2) If (PinState = 1) Then T1 = Timer PinState = 0 Cycle = True 7 Do While Cycle = True PinState = GetPin(11) Delay(0.2) If (PinState = 1) Then T2 = Timer DT = T2-T1 DT_Int = Fix(DT) DT_Decimal = DT-DT_Int DT_Dec_in_ms = DT_Decimal*1000.0 Debug.Print "The time elapsed is "; CStr(CInt(DT_Int));" seconds" Debug.Print "and "; CStr(CInt(DT_Dec_in_ms)); " milliseconds" call freqout(4,1010,0,1.0) PinState = 0 Cycle = False End If Loop End If Loop End Sub 8 Task 9d: Determining Digital-to-Analog Converter Output An eight-bit D/A Converter is shown in the Class 9, section d. This eight-bit converter is made up of 3 voltage sources and seven resistances arranged in a network. The voltage sources will be output pins of the BX-24 system, which we can set to 0 or 5 Volts. (Zero volts means disconnecting the source, 5 Volts means supplying 5 Volts to the network at the location of the source.) Two of the resistances have the same value R and five of the resistances have values 2R. The output voltage is measured across one of the 2R resistances toward the right side of the network, as indicated in the figure. If you recall that voltage potentials increase across a voltage source (from – to + leads) and voltage potentials drop across resistances, then you may already suspect that the output voltage will be different at the output node if sources and/or resistors are removed from the circuit. This is exactly what occurs when we turn off any of the three BX-24 output pins (that, in turn, are sources on the D/A converter’s circuit). Task 8d is for you to analyze the eight circuits that result when the three BX-24 output pins used as sources on the D/A converter are either turned on or off. Fill in a table like the one in the Class 9, part d, and hand it in as part of your report. Pin 1 Pin 2 Pin 3 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 9 Vout HOMEWORK 1: Write a BasicX program program that writes “HELLO[#group number][student #]”. HOMEWORK 2: Read the following BasicX program. Then, describe what the program does. Include the control structures, the calculations, and subprogram calls in your explanation. Do not generalize, be specific to this program! You will receive credit on the understanding that you demonstrate. The student who wrote the program made a mistake. What is it? Sub Main() Dim Dim Dim Dim Dim Dim N As Single Dl As Single Aux2 As Single Auxl As Single D As Integer I As Integer Debug.Print N=48357.4 Debug.Print I = 1 Do While I <= 6 If (I <> 1) Then Auxl = N/10.0 Aux2 = Fix(Auxl) Dl = (Auxl-Aux2)*10.0 ElseIf (I = 1) Then Aux2 = Fix(N) Dl =(N-Aux2)*10.0 End If D = CInt(Dl) Debug.Print CStr(D) If (D = 1) Then Debug.Print Call Delay(l.O) Call One() ElseIf (D = 2) Then Debug.Print Call Delay(2.0) Call Two() ElseIf (D = 3) Then Debug.Print Call Delay(1.0) Call Three() ElseIf (D = 4) then Debug.Print Call Delay(2.0) Call Four() ElseIf (D = 5) Then Debug.Print Call Delay(1.0) 10 Call Five() ElseIf (D = 6) Then Debug.Print Call Delay(2.0) Call Six() ElseIf (D = 7) Then Debug.Print Call Delay(1.0) Call Seven() ElseIf (D = 8) Then Debug.Print Call Delay(2.0) Call Eight() ElseIf (D = 9) Then Debug.Print Call Delay(1.0) Call Nine() ElseIf (D = 0) Then Debug.Print Call Zero() End If N=Aux2 I=I+1 Loop End Sub Sub One() Call PutPin(5,0) Call PutPin(6,0) Call PutPin(7,0) Call PutPin(8,0) Call PutPin{15,0) Call PutPin(16,0) Call PutPin(17,l) End Sub Sub Two() Call PutPin(5,0) Call PutPin(6,l) Call PutPin(7,l) Call PutPin(8,l) Call PutPin(15,0) Call PutPin(16,1) Call PutPin(17,0) End Sub Sub Three( ) Call PutPin(5,0) Call PutPin{6,0) Call PutPin(7,0) Call PutPin(8,0) Call PutPin(15,0) Call PutPin(16,0) Call PutPin(17,0) End Sub Sub Four() Call PutPin(5,0) Call PutPin(6,0) Call PutPin(7,l) Call PutPin(8,0) Call PutPin(15,0) Call PutPin(16,0) Call PutPin(17,l) End Sub 11 Sub Five() Call PutPin(5,l) Call PutPin(6,0) Call PutPin(7,l) Call PutPin(8,l) Call PutPin(15,0) Call PutPin{16,0) Call PutPin(17,0) End Sub Sub Six() Call PutPin(5,0) Call PutPin(6,l) Call PutPin(7,l) Call PutPin(8,0) Call PutPin(15,0) Call PutPin(16,0) Call PutPin(17,0) End Sub Sub Seven() Call PutPin(5,0) Call PutPin(6,l) Call PutPin(7,0) Call PutPin(8,0) Call PutPin(15,l) Call PutPin(16,0) Call PutPin(17,0) End Sub Sub Eight() Call PutPin(5,l) Call PutPin(6,l) Call PutPin(7,l) Call PutPin(8,l) Call PutPin(15,0) Call PutPin(16,1) Call PutPin(17,0) End Sub Sub Nine() Call PutPin(5,0) Call PutPin(6,0) Call PutPin (7,0) Call PutPin(8,0) Call PutPin (15,0) Call PutPin(16,1) Call PutPin(17,0) End Sub Sub Zero() Call PutPin(5,0) Call PutPin(6,0) Call PutPin(7,l) Call PutPin(8,0) Call PutPin(15,0) Call PutPin(16, 0) Call PutPin(17,0) End Sub 12 13