Home

Lab Exercise

image

Contents

1. TI ARM Lab 8 National Accelerometers Science Foundation Funded in part by a grant from the National Science Foundation DUE 1068182 Acknowledgements Developed by Craig Kief Brian Zufelt and Jacy Bitsoie at the Configurable Space Microsystems Innovations amp Applications Center COSMIAC Co Developers are Bassam Matar from Chandler Gilbert and Karl Henry from Drake State Funded by the National Science Foundation NSF Lab Summary This lab introduces the concepts of the I C and how it is implemented on the ARM processor Lab Goal The goal of this lab is to continue to build upon the skills learned from previous labs This lab helps the student to continue to gain new skills and insight on the C code syntax and how it is used in the TI implementation of the ARM processor Each of these labs will add upon the previous labs and it is the intention of the authors that students will build with each lab a better understanding of the ARM processor and basic C code syntax and hardware Even though these tutorials assume the student has not entered with a knowledge of C code it is the desire that by the time the student completes the entire series of tutorials that they will have a sufficient knowledge of C code so as to be able to accomplish useful projects on the ARM processor Learning Objectives The student should begin to become familiar with the concept of the accelerometer and ways to accomplish simple projects An accelerometer is
2. Configure GPIO pin for 12C Data line GPlIOPinConfigure GPIO_PB2_I2COSCL Configure GPIO Pin for I2C clock line GPIOPinTypel2C GPIO_PORTB_BASE GPIO PIN 2 GPIO PIN 3 Set Pin Type Enable Peripheral ports for output SysCtlPeripheralEnable SYSCTL_PERIPH_GPIOC PORTC GPIOPinTypeGPIOOutput GPIO_PORTC_BASE GPIO_PIN_6 GPIO_PIN_7 LED 1 LED 2 GPIOPinTypeGPIOOutput GPIO_PORTB_BASE GPIO PIN 5 LED 4 SysCtlPeripheralEnable SYSCTL_PERIPH_GPIOD PORT D GPIOPinTypeGPIOOutput GPIO_PORTD_BASE GPIO PIN 6 LED 3 setup the 12C GPIOPadConfigSet GPIO_PORTB_BASE GPIO PIN 2 GPIO STRENGTH 2MA GPIO PIN TYPE STD SDA MUST BE STD GPIOPadConfigSet GPIO_PORTB_BASE GPIO PIN 3 GPIO STRENGTH 2MA GPIO PIN TYPE OD SCL MUST BE OPEN DRAIN 12CMasterlnitExpCik 12C0 BASE SysCtiClockGet false sets the controller to 100kHz communication 11 lab activity Accel_int Function to initialize the Accelerometer while 1 Fill in this section to read data from the Accelerometer and move the LEDs according to the X axis LED value LED value Accel_read if LED value lt 1 Cycle through the LEDs on the Orbit board GPIOPinWrite GPIO PORTC BASE GPIO PIN 6 GPIO PIN 7 0x40 LED 1 on LED 2 Off GPIOPinWrite GPIO_PORTD_BASE GPIO PIN 6 0x00 LED 3 off Note different PORT GPIOPinWrite GPIO PORTB BASE GPIO PIN 5 0x00 LED 4 off LED value 1 reset value to maintain range else if LE
3. Setup the core to enable the PC hardware This is part of the SysCtl set of functions outline in the Driver users guide The Driver users guide provides an outline of all the available functions found in the Tiva API 2 Setup the GPIO port to use the I C controller This is part of the GPIO set of functions found within the Driver users guide 3 Finally Setup the PC controller with the settings for the bus you are plugging it into Like the UART PC has many settings and options This is part of the I2C set of functions found within the Driver users guide lab activity Attachment 1 main c file starting RRR A AAA AAA AAA AAA AAA AAA AAA AAA AA AA AAA AAA A AAA AAA Project Orbit Lab 8 ATE ACCEL Version 1 0 Date 2 20 2013 Author Brian Zufelt Craig Kief Company COSMIAC UNM Comments This source provides an introduction to the sensing capabilities for embedded systems The student will read accelerometer data and toggle the proper LED to provide tilt measurement eC cee ee eee ee ee Se ee ec eo oe eee kk Chip type ARM TM4C123GH6PM Program type Firmware Core Clock frequency 80 000000 MHz JERSE SOKO OOOO OSES OOOO OCIA ICI AISA A AAA define ACCEL_W 0x3A Addresses for the accelerometer define ACCEL _R 0x3B define ACCEL_ADDR 0x1D Define needed for pin_map h define PART_TM4C123GH6PM include lt stdbool h gt include lt stdint h gt include inc tm4c123gh6pm h include inc hw_
4. a device that will measure acceleration forces These forces may be static like the constant force of gravity pulling at your feet or they could be dynamic caused by moving or vibrating the accelerometer By measuring the amount of static acceleration due to gravity you can find out the angle the device is tilted at with respect to the earth By sensing the amount of dynamic acceleration you can analyze the way the device is moving An accelerometer can help the designer understand the system better Is it driving uphill Is it flying horizontally or is it dive bombing A designer can write code to answer all of these questions using the data provided by an accelerometer In the computing world IBM and Apple have recently started using accelerometers in their laptops to protect hard drives from damage If you accidentally drop the laptop the accelerometer detects the sudden free fall and switches the hard drive off so the heads don t crash on the platters In a similar fashion high G accelerometers are the industry standard way of detecting car crashes and deploying airbags at just the right time The ADXL345 used on the ORBIT board is a small thin ultralow power 3 axis accelerometer with high resolution 13 bit measurement at up to 16 g It s functional block diagram is shown in Figure 1 Digital output data is formatted as 16 bit twos complement and is accessible through either a SPI 3 or 4 wire or PC digital interface The ADXL345 is
5. 1 0 Date 2 20 2013 Author Brian Zufelt Craig Kief Company COSMIAC UNM Comments This source provides an introduction to the sensing capabilities for embedded systems The student will read accelerometer data and toggle the proper LED to provide tilt measurement eC cee ee eee ee ee Se ee ec eo oe eee kk Chip type ARM TM4C123GH6PM Program type Firmware Core Clock frequency 80 000000 MHz kkk kkoo AAA define ACCEL_W 0x3A Addresses for the accelerometer define ACCEL_R 0x3B define ACCEL_ADDR 0x1D Define needed for pin_map h define PART_TM4C123GH6PM include lt stdbool h gt include lt stdint h gt include inc tm4c123gh6pm h include inc hw_memmap h include inc hw_types h include driverlib gpio h include driverlib pin_map h include driverlib sysctl h include driverlib uart h include inc hw_i2c h include driverlib i2c h include inc hw_ints h include driverlib interrupt h include driverlib timer h void Accel_int Function prototype to initialize the Accelerometer signed int Accel_read Function prototype to read the Accelerometer void main void signed short int LED_value 1 SysCtIClockSet SYSCTL_SYSDIV_1 SYSCTL_USE_OSC SYSCTL_OSC_MAIN SYSCTL_XTAL_16MHZ setup clock SysCtlPeripheralEnable SYSCTL_PERIPH_I2CO Enable 12C hardware SysCtlPeripheralEnable SYSCTL_PERIPH_GPIOB Enable Pin hardware GPIOPinConfigure GPIO_PB3_I2COSDA
6. D_value 2 Cycle through the LEDs on the Orbit board GPIOPinWrite GPIO_PORTC_BASE GPIO_PIN_6 GPIO_PIN_7 0x80 LED 1 off LED 2 on GPIOPinWrite GPIO_PORTD_BASE GPIO_PIN_6 0x00 LED 3 off Note different PORT GPIOPinWrite GPIO_PORTB_BASE GPIO_PIN_5 0x00 LED 4 on else if LED_value 3 Cycle through the LEDs on the Orbit board GPIOPinWrite GPIO_PORTC_BASE GPIO_PIN_6 GPIO_PIN_7 0x00 LED 1 off LED 2 off GPIOPinWrite GPIO_PORTD_BASE GPIO_PIN_6 0x40 LED 3 on Note different PORT GPIOPinWrite GPIO_PORTB_BASE GPIO_PIN_5 0x00 LED 4 Off else if LED_value gt 4 Cycle through the LEDs on the Orbit board GPIOPinWrite GPIO_PORTC_BASE GPIO_PIN_6 GPIO_PIN_7 0x00 LED 1 off LED 2 Off GPIOPinWrite GPIO_PORTD_BASE GPIO_PIN_6 0x00 LED 3 off Note different PORT GPIOPinWrite GPIO_PORTB_BASE GPIO_PIN_5 0x20 LED 4 on LED_value 4 reset value to maintain range void Accel_int Function to initialize the Accelerometer I2CMasterSlaveAddrSet I2CO_BASE ACCEL_ADDR false false means transmit 2CMasterControl I2CO_BASE 12C_MASTER_CMD_BURST_SEND_START Send Start condition 2CMasterDataPut I2CO_BASE 0x2D Writing to the Accel control reg SysCtIDelay 20000 Delay for first transmission 2CMasterDataPut I2CO_BASE 0x08 Send Value to control Register 12CMasterControl I2CO_BASE 12C_MASTER_CMD_BURST_SEND_FINISH Send Stop condition while I2CMasterBu
7. Explorer 5 aS ye Lab 2 Lab 3 i Lab 4 Active Debug 12 Lab 5 i Lab 6 y Lab 7 ig Lab 8 i Lab 9 Figure 5 CCS Starting Point The laboratory material is created to have the students type in a lot of the code Only by typing the code and then debugging the errors will a user ever really understand how to do projects For the sake of this activity the source code is provided at the end of the tutorial In Lab 7 open main c Then either type in all the code from attachment 2 or copy and paste in the code from Attachement 2 into main c lab activity It is now important to spend a couple of minutes to explain a little more about the accelerometer used in this project If you are looking on the Orbit board there is a small chip in the upper right quadrant It has a silkscreened cross on the board around the chip with a X and Z lettering This is the ADXL345 chip Vs Vppuo O O i N N comro HKOINTI ADXL345 _ SENSE _ ELECTRONICS ty DIGITAL 4 INTERRUPT FILTER LOGIC eA eit Meese 32 LEVEL N FIFO SERIAL UO SDOIALT Vv ADDRESS Q SCLSCLK 07825001 GND cs Figure 6 ADXL345 As can be seen in Figure 6 it has a 3 axis sensor that can be used to detect the orientation of the board In this tutorial only the X axis will be measured This is to keep the tutorial as simple as possible As a result the function will have thre
8. PIN 3 GPIO STRENGTH 2MA GPIO PIN TYPE OD SCL MUST BE OPEN DRAIN lab activity I2CMasterInitExpClk I2CO_BASE SysCtIlClockGet false The False sets the controller to 100kHz communication Accel_int Function to initialize the Accelerometer while 1 JE RAI A AAA A AAA AA AAA AA AAA AAA A AAA AAA AAA AAA AAA AAA AAA AAA AAA AA AAA AA AAA AAA AAA AA AAA AA AAA AA AAA AAA AAA Fill in this section to read data from the Accelerometer and move the LEDs according to the X axis Task call the Accel_read function and add it to LED_value Using a number between 1 4 turn onthe LEDs 1 4 to show tilt in the x axis JR CRE ESCO OHSS OSE SECS ECCS ISAS AI AA AA IAA IAAT AI void Accel_int Function to initialize the Accelerometer I2CMasterSlaveAddrSet I2CO_BASE ACCEL_ADDR false false means transmit 2CMasterControl I2CO_BASE I12C MASTER CMD BURST SEND START Send Start condition I2CMasterDataPut I2CO_BASE 0x2D Writing to the Accel control reg SysCtIDelay 20000 Delay for first transmission I2CMasterDataPut I2CO_BASE 0x08 Send Value to control Register 2CMasterControl I2CO_BASE I2C_MASTER_CMD_BURST_SEND_FINISH Send Stop condition while I2CMasterBusBusy I2CO_BASE Wait for 12C controller to finish operations signed int Accel_read Function to read the Accelerometer signed int data signed short value 0 value of x unsigned char MSB uns
9. SB of X Axis lab activity Attachment 3 Block Diagram of the Pins Used in Projects 2 2 21 2 23 2 2 2 Pin Number 7 6543210 CORE Hex Binary 000 0 0 000 PAT Port A Pin 7 To energize send 0x80 UART PA ORX IN CIRCUIT DEBUGGER YSB Pc PA 1TX ICD PA6_ ORBITSW2 ORBITSW1 12C GPIO B PBS ORBIT LED 4 VCC Fr Pa pH PB2 TEMP ACCEL SENSOR Device ID PC6 Device ID Ox1D GPIO C ORBIT LED 1 Ox4f WROx3A PC7 ORBIT LED 2 RD 0x3B GPIO D PD 6 ORBIT LED 3 ORBIT PD2 ORBITBTN 1 PEO GPIOE ORBIT BTN 2 Tiva Launchpad BTN 2 Tiva Launchpad LED RED Tiva Launchpad LED BLUE Tiva Launchpad LED GREEN Tiva Launchpad BTN 1 14
10. as x3A The key to IC is to remember that it is a very powerful way to attach a wide variety of different sensors onto a single bus This bus is also only two wires wide So to do this each device on the bus must have a unique address With PC devices if you go into their datasheets it is possible to quickly find their unique addresses Some devices often have up to four addresses possible through the use of onboard jumpers ADXL345 PC With CS tied high to Vooi the ADXL345 is in PC mode avail Semiconductor It supports standard 100 kHz and fa data transfer modes if the bus parame i i the R W bit can be cl ADDRESS pin Pin 12 This tran je and OxA7 for a read Figure 9 Datasheet Excerpt The next set of code shown below is a new topic It is called a function prototype Most experienced designers like to have the main starting portion of their code appear at the top of the main c file The beginning of the program is normally identified with void main void To make things cleaner most designers will also use the function prototypes to declare the functions at the top of the file and then further down in the program after the main function will do the full explanation and declaration of what the functions actually do In this case there are two function prototypes The first is to initialize the accelerometer and the second is to read the chip void Accel _int Function to initialize the Acc
11. e returned values 1 going left 0 standing still or 1 going right The chip is very sensitive The system transfers data on an I C line The ADXL345 has an I C output and the ARM processor has PC inputs as shown in Figure 7 from the datasheet PROCESSOR D IN OUT D OUT naow Figure 7 Connection Diagram The T C protocol interface has a unique set of waveforms to allow the system to know when to start and stop the transfer of data This waveform timing diagram is shown in Figure 8 and shows how the processor knows when to receive data REPEATED CONDITION START STOP 3 CONDITION CONDITION 3 5 Figure 8 I2C Waveform Timing Diagram The entire solution code for this project is given at the end of this tutorial in attachment 2 This initially looks like a large amount of very complex code however when you remember that much of the LED lab activity portion has been presented in previous labs it is less scary Add to that the fact that another large portion of the code is nothing more than delays to slow the system down for human consumption and it is less scary Some of the code that is presented in this lab for the first time is shown below define ACCEL_W 0x3A define ACCEL_R 0x3B define ACCEL_ADDR 0x1D These three lines above are the definition parameters for the device They are taken from the ADXL345 datasheet as shown below It clearly defines the address as x1D the read as x3B and the write
12. elerometer signed int Accel _read Function to read the Accelerometer The next portion of the code initializes the LEDs Refer to attachment 3 at the end of this document Find the accelerometer and look at what pins are required This is very similar to what has been done in previous labs All peripherals must be initialized before they can be used The way this code is designed to operate is to have the LEDs fall or flow downhill based on the way the board is tilted If the board is tilted 90 degrees to the left the LEDs will fall down to the bottom If the board is tilted the other direction the LEDs will still attempt to fall to the bottom After this section of the code the two functions that were prototyped earlier are expanded upon Open the main c file that is in the lab installer for Lab 7 When this is compared to the code in attachment 2 it is clear to see that the code for the LED waterfall is missing The task of this tutorial is to type on this lab activity G code When done debug compile and download Run the program and make sure the LEDs flow appropriately As a challenge exercise reduce the time to flow the lights from one end to the other or light up the Tiva board with different color LEDs when extremes are hit The start of the main function outlines how to setup a peripheral to be used The I C controller is housed within a GPIO port Thus setting up the Chip to use this peripheral is a three step process 1
13. et octopart com EK TM4C123GXL Texas Instruments datasheet 15542121 pdf and the manuals for the Digilent orbit board are located at http digilentinc com Products Detail cfm NavPath 2 396 1181 amp Prod ORBIT BOOSTER Here is the datasheet used for the accelerometer http www analog com static imported files data_sheets ADXL345 pdf COSMIAC tutorials found at http cosmiac org thrust areas academic programs and design services education and workforce development microcontrollers ate developed material Lab Procedure Install Connect board to computer Figure 2 ARM and ORBIT Combination This picture of the correct way to mate the Tiva LaunchPad and the Digilent Orbit boards together Please do so at this point and connect them as shown in Figure 1 Gode Composer Figure 3 Code Composer Icon Launch Code Composer and where prompted chose the workspaces location to store your project as shown in Figure 3 lab activity Select a workspace Code Composer Studio stores your projects in a folder called a workspace Choose a workspace folder to use for this session Workspace UOLS ESSENS Use this as the default and do not ask again Figure 4 Workspace Selection Since the installer for the workshop has been run prior to this the user will be presented with the following view Figure 4 where all lab projects exist File Edit View Navigate Project Scri Ta Kvit ri imi R Project
14. igned char LSB I2CMasterSlaveAddrSet I2CO_BASE ACCEL_ADDR false false means transmit I2CMasterDataPut I2CO_BASE 0x32 SysCtIDelay 20000 2CMasterControl I2CO_BASE 12C MASTER CMD SINGLE SEND Request LSB of X Axis SysCtIDelay 2000000 Delay for first transmission I2CMasterSlaveAddrSet I2CO_BASE ACCEL_ADDR true false means transmit 2CMasterControl I2CO_BASE I2C_MASTER_CMD_SINGLE_RECEIVE Request LSB of X Axis SysCtIDelay 20000 LSB 12CMasterDataGet 12C0 BASE SysCtIDelay 20000 I2CMasterSlaveAddrSet I2CO_BASE ACCEL_ADDR false false means transmit I2CMasterDataPut I2CO_BASE 0x33 2CMasterControl I2CO_BASE 12C_MASTER_CMD_SINGLE_SEND Request LSB of X Axis SysCtIDelay 2000000 Delay for first transmission I2CMasterSlaveAddrSet I2CO_BASE ACCEL_ADDR true false means transmit 2CMasterControl I2CO_BASE I2C_MASTER_CMD_SINGLE_RECEIVE Request LSB of X Axis SysCtIDelay 20000 MSB 2CMasterDataGet I2CO_BASE value MSB lt lt 8 LSB Bit shift MSB the OR it with LSB to get 16 bit value if value lt 250 data 1 else if value gt 250 data 1 else SysCtIDelay 20000 data 0 return data testing axis for value 10 return value lab activity lab activity Attachment 2 main c file solution RRR A AAA AAA AAA AAA AA AAA AAA AAA AAA AAA AAA A AAA AAA Project Orbit Lab 8 ATE ACCEL Version
15. memmap h include inc hw_types h include driverlib gpio h include driverlib pin_map h include driverlib sysctl h include driverlib uart h include inc hw_i2c h include driverlib i2c h include inc hw_ints h include driverlib interrupt h include driverlib timer h void Accel_int Function prototype to initialize the Accelerometer signed int Accel_read Function prototype to read the Accelerometer void main void signed short int LED_value 1 SysCtIClockSet SYSCTL_SYSDIV_1 SYSCTL_USE_OSC SYSCTL_OSC_MAIN SYSCTL_XTAL_16MHZ setup clock SysCtlPeripheralEnable SYSCTL_PERIPH_I2CO Enable 12C hardware SysCtlPeripheralEnable SYSCTL_PERIPH_GPIOB Enable Pin hardware GPIOPinConfigure GPIO_PB3_I2COSDA Configure GPIO pin for I2C Data line GPIOPinConfigure GPIO_PB2_I2COSCL Configure GPIO Pin for I2C clock line GPIOPinTypel2C GPIO_PORTB_BASE GPIO PIN 2 GPIO PIN 3 Set Pin Type Enable Peripheral ports for output SysCtlPeripheralEnable SYSCTL_PERIPH_GPIOC PORTC GPIOPinTypeGPIOOutput GPIO_PORTC_BASE GPIO_PIN_6 GPIO_PIN_7 LED 1 LED 2 GPIOPinTypeGPIOOutput GPIO_PORTB_BASE GPIO PIN 5 LED 4 SysCtlPeripheralEnable SYSCTL_PERIPH_GPIOD PORT D GPIOPinTypeGPIOOutput GPIO_PORTD_BASE GPIO PIN 6 LED 3 setup the 12C GPIOPadConfigSet GPIO_PORTB_BASE GPIO_PIN_2 GPIO STRENGTH 2MA GPIO PIN TYPE STD SDA MUST BE STD GPIOPadConfigSet GPIO_PORTB_BASE GPIO
16. sBusy I2CO_BASE Wait for 12C controller to finish operations signed int Accel_read Function to read the Accelerometer signed int data signed short value 0 value of x unsigned char MSB unsigned char LSB I2CMasterSlaveAddrSet I2CO_BASE ACCEL_ADDR false false means transmit I2CMasterDataPut I2CO_BASE 0x32 SysCtIDelay 20000 2CMasterControl I2CO_BASE 12C MASTER CMD SINGLE SEND Request LSB of X Axis SysCtIDelay 2000000 Delay for first transmission 12 I2CMasterSlaveAddrSet I2CO_BASE ACCEL_ADDR true I2CMasterControl I2CO_BASE I2C_MASTER_CMD_SINGLE_RECEIVE SysCtIDelay 20000 LSB I2CMasterDataGet I2CO_BASE SysCtIDelay 20000 I2CMasterSlaveAddrSet I2CO_BASE ACCEL_ADDR false I2CMasterDataPut I2CO_BASE 0x33 2CMasterControl I2CO_BASE 12C_MASTER_CMD_SINGLE_SEND SysCtIDelay 2000000 Delay for first transmission I2CMasterSlaveAddrSet I2CO_BASE ACCEL_ADDR true I2CMasterControl I2CO_BASE I2C_MASTER_CMD_SINGLE_RECEIVE SysCtIDelay 20000 MSB 2CMasterDataGet I2CO_BASE value MSB lt lt 8 LSB if value lt 250 testing axis for value data 1 else if value gt 250 data 1 else SysCtIDelay 20000 data 0 return data return value 13 lab activity false means transmit Request LSB of X Axis false means transmit Request LSB of X Axis false means transmit Request L
17. well suited for mobile device applications It measures the static acceleration of gravity in tilt sensing applications as well as dynamic acceleration resulting from motion or shock Its high resolution 3 9 mg LSB enables measurement of inclination changes less than 1 0 lab activity G Vs Vppu0 CONTROL INT1 AND INTERRUPT SENSOR C SDA SDI SDIO O SDO ALT ADDRESS SCL SCLK e GND cs Figure 1 Functional Block Diagram for the Accelorometer 07925 001 Grading Criteria N A Time Required Approximately one hour Lab Preparation It is highly recommended that the student read through this entire procedure once before actually using it as a tutorial It is also recommended that the tutorial software was run first to preload compiler options and source files Equipment and Materials Access to Tiva TM4C123G LaunchPad software and evaluation kit EK RM4C123GXL as well as the Digilent Orbit board It is assumed that the student has already completed Lab 3 and the software is installed properly Ensure that the boards are plugged in before start of the tutorial Software needed The software requirements from Lab 3 are still applicable here Hardware needed Quantity lab activity G The hardware required is the TI Tiva LaunchPad Kit and the Digilent 1 Corporation s Orbit Daughter card Additional References The Evaluation Board user s manual is on this web site http datashe

Download Pdf Manuals

image

Related Search

Related Contents

(ppri) commune de bras panon    X16PDM Manual - Ronan Engineering  NS-40D510NA15 Guía del usuario Televisor LED de 40 pulg  Make Noise PHONOGENE Specifications    Mode d`emploi  MANUAL DE INSTRUCCIONES  Samsung Samsung Rex 70 Инструкция по использованию  Brinly-Hardy AS-40 BH User's Manual  

Copyright © All rights reserved.
Failed to retrieve file