Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 30 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
30
Dung lượng
6,83 MB
Nội dung
LAB PROCEDURE Sensors Fundamentals Page 1 of 30 Sensors Fundamentals RL78 Family Description: The Sensor Fundamentals lab provides an introduction to some of the ADI sensors and to the evaluation boards for these sensors compatible with Renesas MCU platforms. During the hands on part of the lab the attendees are guided through a series of steps required to create a new project for the Renesas RL78 MCU, establish communication through SPI and I2C with different ADI digital sensors, read data from an ADI analog sensor through the A/D converter found on the Renesas MCU. Lab Sections 1 Board Setup 2 2 Software Setup 3 3 Sensors Application 8 3.1 Temperature Sensor Application 8 3.2 Accelerometer Application 17 3.3 Accelerometer Game 21 3.4 Gyroscope Application 22 3.5 Accelerometer and Gyroscope Game 25 3.6 Microphone Application 27 Lab Objectives 1. Establish communication through SPI and I2C with different ADI digital sensors. 2. Read data from an ADI analog sensor through the A/D converter found on the Renesas MCU. 3. Use the sensors output data in a real application. Skill Level 1. Basic knowledge of C programming language. 2. Basic knowledge of SPI and I2C communication protocols. Time to Complete Lab 90 Minutes Lab Materials Please verify you have the following materials at your lab station. · IAR Embedded Workbench for Renesas RL78 v.1.20 · ADISensorsLab.zip Please verify you have the following hardware: · RL78/G14 RDK · USB Cable · PmodGYRO2 LAB PROCEDURE Sensors Fundamentals Page 2 of 30 1 Board Setup Overview This section contains a description of the steps required to setup the hardware. Procedural Steps Step 1.1 Connect the PmodGYRO2 to the PMOD1 connector of the RL78/G14 board (Figure 1). Pin 1 of PmodGYRO2 has to be connected to Pin 1 of boards connector (place the Pmod on the side of the connector closest to the LCD). Figure 1. Board setup Step 1.2 Ensure the switch SW5 is set to DEBUG (ON, OFF, ON, ON Figure 2). Figure 2. SW5 position for Debug Mode Step 1.3 Connect the RL78/G14 board using the provided cable to a USB port of your lab station. LAB PROCEDURE Sensors Fundamentals Page 3 of 30 2 Software Setup Overview This section contains a description of the steps required to setup the software project for the IAR IDE. Procedural Steps Step 2.1 Run the IAR Embedded Workbench for Renesas RL78 integrated development environment. Step 2.2 Choose to create a new project (Project Create New Project). Step 2.3 Select the RL78 tool chain, the Empty project template and click OK (Figure 3). Figure 3. Create New Project window Step 2.4 Select a location and a name for the project (DevCon2012 for example) and click Save (Fig. 4). Figure 4. Save As window LAB PROCEDURE Sensors Fundamentals Page 4 of 30 Step 2.5 Open the projects options window (Project Options). Step 2.6 From the Target tab of the General Options category select the RL78 G14 RL78 R5F104PJ device (Figure 5). Figure 5. arget options window Step 2.6 From the Stack/Heap tab of the General Options category set the Stack Size to 256 bytes (Figure 6). Figure 6. Stack/Heap window LAB PROCEDURE Sensors Fundamentals Page 5 of 30 Step 2.7 From the Setup tab of the Debugger category select the TK driver and click OK (Figure 7). Figure 7. Debugger options window Step 2.8 Extract the files from the lab .zip archive and copy them into the projects folder (Figure 8). Figure 8. tract te fies into te projects foder LAB PROCEDURE Sensors Fundamentals Page 6 of 30 Step 2.9 The new source files have to be included into the project. Open the Add Files window (Project Add Files), select all the copied files and click open (Figure 9). Figure 9. Include the files into the project LAB PROCEDURE Sensors Fundamentals Page 7 of 30 At this moment, all the files are included into the project (Figure 10). Figure 10. The files are included into the project The source file that will be modified during the following steps is the Main.c. Add the code lines only between Start user code and End user code comments. Do not modify any other file included into the project. LAB PROCEDURE Sensors Fundamentals Page 8 of 30 3 Sensors Application Overview This section contains descriptions of the steps required to create the applications for the ADI sensors. 3.1 Temperature Sensor Application The ADT7410 is a high accuracy digital temperature sensor (Figure 11). It contains a band gap temperature reference and a 13 bit ADC to monitor and digitize the temperature to a 0.0625°C resolution. The ADC resolution, by default, is set to 13 bits (0.0625°C) but it can be changed to 16 bits (0.0078°C). Figure 11. Functional Block Diagram for ADT7410 Control of the ADT7410 is carried out via the I2C-compatible serial interface. The ADT7410 is connected to this bus as a slave and is under the control of a master device. On the RL78/G14 board, an ADT7410 sensor is installed (Figure 12). Figure 12. ADT7410 installed on the RL78/G14 is marked TEMP SENSOR LAB PROCEDURE Sensors Fundamentals Page 9 of 30 Step 3.1.1 Initialize the I2C communication peripheral to communicate with the device. To verify that the device is present read the ADT7410 ID register. Copy following code between Start user code and End user code comments. /* Variables declaration. */ unsigned char adt7410Id = 0; /* Clear the screen and display the name of the sensor. */ ST7579_Clear(); ADI_Component("ADT7410"); /* Initialize the I2C communication peripheral at 400 kHz. */ I2C_Init(400000); /* Read and display the value of the ADT7410 ID register. */ adt7410Id = ADT7410_GetRegisterValue(ADT7410_REG_ID); ST7579_String(1, 0, "ID:", 0); ST7579_HexNumber(1, 27, adt7410Id, 0); /* Infinite loop. */ while(1) { } Make the project by pressing F7 key or selecting Project Make (Figure 13). Figure 13. Make the project LAB PROCEDURE Sensors Fundamentals Page 10 of 30 After the project is built, download the project on the board by pressing CTRL + D or pressing the Download and Debug button (Figure 14). Figure 14. Download and debug the project A window will appear asking to save the workspace (Figure 15). Select a name for the workspace (DevCon2012 for example) and click Save. Figure 15. Save Workspace As window Other two windows will appear asking to set Emulator Hardware configuration (Figure 16 and Figure 17). Keep the default settings and click OK. . LAB PROCEDURE Sensors Fundamentals Page 1 of 30 Sensors Fundamentals RL78 Family Description: The Sensor Fundamentals lab provides an introduction to some of the ADI sensors and to. PROCEDURE Sensors Fundamentals Page 8 of 30 3 Sensors Application Overview This section contains descriptions of the steps required to create the applications for the ADI sensors. . accelerometer in measure mode. */ ADXL345_SetPowerMode(1); LAB PROCEDURE Sensors Fundamentals Page 19 of 30 /* Infinite loop. */ while(1) { /* Read and display the output data of