Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Project 6: A/D LDR Light Level Switch Design Analogue Light Detector (Project 6 requires Full CoreChart & ezCircuit Designer licences) Learning Outcome This workshop gives the user a hands-on experience on how to design, build, document and program an electronic light detector and an introduction to Analogue to Digital A/D conversion. An example of A/D is the conversion of voltage levels to digital values for use by the microcontrollers. Equipment for workshop Computer PC running Windows 2000 SP4 or higher with USB connections Software Microsoft .NET Framework V2 ( Required to run ezCircuit Designer ) ezCircuit Designer CoreChart V2.4.26 Hardware eLab16m Controller Board with battery holder and 3x AA batteries eLabtronics USBP Programmer with USB Cable Analogue Light Detector Parts and Tools LCD Light Dependant Resistor (LDR) sensor module Relay module Small flat head screwdriver Soldering Iron and solder for building the kit 1 Project 6: A/D LDR Light Level Switch Analogue Light Detector An analogue light detector measures the light level of the surrounding. For example, an automatic window shutter extends or retracts depending on the light level in the room. Step 1: Select eLab16m_LCD Template The analogue light detector is built from the eLab16m_LCD template. a. Start up ezCircuit Designer. b. Enter the “File” drop down menu and click “Open”. c. Enter the “ezCircuit” folder then enter the “Examples” folder. d. Select and open “eLab16m_LCD.ezproj” which should look like figure 1.1. figure 1.1 Step 2: Create Documents a. In the main menu bar, click on “Documentation” then “Create Document”, finally select “Specification”. b. Fill in “Introduction”, “Functional Requirement” and “Requirement Specification Rationale” as follows: Introduction: The aim of this project is to build an analogue light detector. Functional Requirement: The electronic light detector uses a LDR to sense the light intensity and convert the analogue value to 8 bit digital value to be displayed on an LCD. At a pre-set level of light intensity, the relay trips and switches circuits on and off. Requirement Specification Rationale: Learn to build and program a light detector with the eLab16m, LDR, LCD. Investigate the use of analogue to digital conversion. NOTE: It is important to save the program regularly. 2 Project 6: A/D LDR Light Level Switch Step 3: Add LDR circuit to design In this project an Analogue to Digital A/D converter is used to convert the LDR sensor analogue signals to digital values. However, all available Analogue pins in PORTA have been allocated. It is important to note in this special case that two circuits are connected to one Analogue pin on the PIC chip. This is possible because the LCD pins can be enabled and disabled so that the LCD signal is not affected by the Analogue signal from the LDR sensor. a. Rename pin 2 (A3) to “D4_LightSensor”. b. Rename Pin 16 (A7) to “Relay”. Figure 3.1 c. Enter the “File” drop down menu and click “Save as…”. d. Re-name the ezCircuit Designer project as “Light_Detector”. e. Click on “Send to CoreChart” under the “Options” drop down menu or click the CoreChart icon as shown in figure 3.2. figure 3.2 3 Project 6: A/D LDR Light Level Switch Step 4: Hardware Connection Figure 4.1 shows the hardware connections for the Light Detector. The LDR Circuit Diagram is available from ezCircuit Designer. a. Right click on the LDR box connected to the PIC chip. b. Click on “View Circuit Diagram”. NOTE: It is an Active High Circuit. c. Connect the LDR white wire to “A3” terminal on the eLab16m. d. Connect the LDR black wire, soldered with a 33K resistor, to “-” (ground). e. Connect the red wire of the LDR to the “+”. f. Connect the black wire of the Relay to “-” (ground). g. Connect the red wire of the Relay to “A7” terminal. h. Connect the LCD to the 10 pin socket. Normally open Normally closed Common figure 4.1 4 Project 6: A/D LDR Light Level Switch Step 5: Test Hardware with CoreChart test program This test program will test the OUTPUT circuits of the project. These are the LCD and the Relay circuits. The CoreChart test program should look like figure 5.1. a. Save the CoreChart test program as “LightDetector”. figure 5.1 b. Plug in the USBP programmer cable to the computer. c. Connect the programmer to the eLab16m and turn on the power. d. Send the CoreChart test program to the chip. e. When the program is successfully downloaded to the chip, unplug the USBP programmer from the eLab16m and plug in the LCD display. f. Only switch on the power on the eLab16m AFTER the LCD has been plugged in. g. Press the and release the Reset switch on the eLab16m to start the test program. The word “HELLO” is displayed on the LCD. The relay turns on for two seconds and turns off for two seconds. 5 Project 6: A/D LDR Light Level Switch Step 6: Add Subroutines Add subroutines “MESSAGE”, “CHECK_SENSOR”, “TRIP_RELAY”, “SHOW_RESULT”, “LCD2ndLINE”, “SPLIT_DEC” and “NUM_2_ASCII”. a. Under “Edit” drop menu click on “Subroutines…”. b. Type the subroutine names in the text entry box on the upper right corner. c. Click “Add Subroutine”. figure 6.1 6 Project 6: A/D LDR Light Level Switch Step 7: Import Analogue subroutine a. Under CoreChart “Options” drop down menu select “Import subroutine…”. b. Next find the subroutine called “GetAnalogue”. c. Tick the “GetAnalogue” tick box and the “Manual Control of Name Change” tick box at the bottom. d. Then click on “Import Selected”. NOTE: Click “NO” in the “Confirm Subroutine Name Change” dialog boxes as shown below. Figure 7.1 7 Project 6: A/D LDR Light Level Switch Step 8: Add variables Add variables “ONE”, “TEN”, “HUNDRETH” and “TEMP”. a. To add a variable click on the “Edit” drop down menu and then click “Variables” to display the “User Variable List” screen. b. Type the variable name in the text box and click “Add Variable”. Figure 8.1 8 Project 6: A/D LDR Light Level Switch Step 9: Build Main LDR Program a. Edit the test program to build a Main LDR program that looks like figure 9.1. figure 9.1 9 Project 6: A/D LDR Light Level Switch Step 10: Enter subroutine details a. To add icons to a subroutine double click on the subroutine icon in the Main Program. b. To return to Main Program double click on “Return from Subroutine” icon. The “MESSAGE” subroutine displays the message “LDR” on the LCD screen. The “CHECK_SENSOR” subroutine reads the analogue value from “LDR” circuit and stores the converted digital value in “RESULT”. Subroutine MESSAGE Subroutine CHECK_SENSOR figure 10.1 10 Project 6: A/D LDR Light Level Switch The “SHOW_RESULT” subroutine displays the digital value of the “LDR” on the LCD. The “LCD2ndLine” subroutine moves the cursor to 2nd line of the LCD. The “NUM_2_ASCII” subroutine converts decimal numbers into ASCII form for display on the LCD. The LCD processes the ASCII code values and displays the character. Subroutine SHOW_RESULT Subroutine LCD2ndLine Subroutine NUM_2_ASCII figure 10.2 11 Project 6: A/D LDR Light Level Switch The subroutine “TRIP_RELAY” checks for the results of the converted analogue value from the LDR and activates the Relay to trip at a set value. In this case the upper set value is 160 and the lower set value is 145. Subroutine TRIP_RELAY figure 10.3 12 Project 6: A/D LDR Light Level Switch Finally the subroutine “SPLIT_DEC” splits the value into three individual digits to be displayed on LCD. Subroutine SPLIT_DEC Figure 10.4 c. Save program and send to chip. d. Press the eLab16m Reset push button switch once to start the program. e. The LCD displays the light intensity from the sensor as a level number from 0 to 255. 13 Project 6: A/D LDR Light Level Switch Extension Exercises Temperature Control Modify the Light Detector program to a Temperature Control program using a Thermistor. Replace the LDR with a Thermistor from the pack. Measure the room temperature with the Thermistor program Set different temperature levels to trip the Relay. Check what happens at the threshold. Display Temperature in Celsius Write a program to display the real temperature value in Celsius on the LCD. Hint: Use a conversion table subroutine as shown below. The value of “W” directs the subroutine to return the value stored in the table. For example, when “W = 5” then a “W = 26” value (Icon 8) will be returned. The value 5 is added to the Program Counter Low (PCL) which is the PIC chip instruction counter. The next chip instruction will be 5 instructions further than the next instruction which is Icon 8. END OF Project 6: A/D LDR Light Level Switch 14 Project 6: A/D LDR Light Level Switch