in this section a short description about how to interface...

77
University of Stuttgart Institute of Industrial Automation and Software Engineering Prof. Dr.-Ing. Dr. h. c. P. Göhner Board++ (Progress Report) Judas Tadeu de Araújo Jr Lucas Cordeiro Stuttgart, 29 th December 2003

Upload: others

Post on 21-Sep-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

University of Stuttgart Institute of Industrial Automation and Software Engineering

Prof. Dr.-Ing. Dr. h. c. P. Göhner

Board++ (Progress Report)

Judas Tadeu de Araújo Jr Lucas Cordeiro

Stuttgart, 29th December 2003

Page 2: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

Document Version Management

Version Authors QA Date Status Changes 0.1 Cordeiro, de

Araújo Jr. Ur 10.12.2003 In progress Creation

1.0 Cordeiro, de Araújo Jr.

Ur 29.12.2003 Submitted

1.1 Cordeiro, de Araújo Jr.

Ur 29.12.2003 In progress Inclusion of the LCD specification and BT module definition.

1.1 Cordeiro, de Araújo Jr.

Ur 04.01.2004 Submitted

1.2 Cordeiro, de Araújo Jr.

Ur 02.02.2004 In progress Inclusion of the chapter Hardware Component Specification and the Installation of the MicroC/OS-II

Document name: Board++_v12.doc

0 TABLE OF CONTENTS

1 LEGO MINDSTORMS SENSORS .......................................................................................... 4

1.1 OVERVIEW............................................................................................................................. 4 1.2 TOUCH SENSOR ..................................................................................................................... 5

1.2.1 Internal Circuit .............................................................................................................. 6 1.2.2 Software Prototype......................................................................................................... 6

1.3 LIGHT SENSOR....................................................................................................................... 7 1.3.1 Internal Circuit .............................................................................................................. 7

1.4 ROTATION SENSOR................................................................................................................ 9 1.4.1 Internal Circuit ............................................................................................................ 11 1.4.2 Software Prototype....................................................................................................... 12

2 ADDITIONAL SENSORS TO THE LEGO MINDSTORMS ............................................. 16

2.1 ULTRASONIC RANGE SENSOR (MODEL US1051)................................................................ 16 2.1.1 Functionality ................................................................................................................ 16 2.1.2 Operation ..................................................................................................................... 16

2.2 INFRARED PROXIMITY SENSOR (MODEL IR1021)............................................................... 17 2.2.1 Functionality ................................................................................................................ 17 2.2.2 Operation ..................................................................................................................... 17

2.3 PRESSURE SENSOR (MODEL AC1072) ................................................................................ 17 2.3.1 Functionality ................................................................................................................ 17 2.3.2 Operation ..................................................................................................................... 17

2.4 MAGNETIC COMPASS SENSOR (MODEL MC1031).............................................................. 18 2.4.1 Functionality ................................................................................................................ 18 2.4.2 Operation ..................................................................................................................... 18

3 LIQUID CRYSTAL DISPLAY............................................................................................... 19

3.1 OVERVIEW........................................................................................................................... 19 3.2 SOFTWARE PROTOTYPE....................................................................................................... 22

4 LEGO MINDSTORMS MOTORS......................................................................................... 23

4.1 OVERVIEW........................................................................................................................... 23 4.2 THE INTERFACE BETWEEN IAS WEBBOARD AND MOTOR DRIVER.................................... 24

2

Page 3: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

4.3 SOFTWARE PROTOTYPE....................................................................................................... 26

5 BLUETOOTH TECHNOLOGY ............................................................................................ 28

5.1 OVERVIEW........................................................................................................................... 28 5.2 WHAT IS BLUETOOTH GOOD FOR?...................................................................................... 28 5.3 BLUETOOTH SPECIFICATION ............................................................................................... 28 5.4 PROTOCOL STACK [INFO01]................................................................................................ 29 5.5 NETWORK TOPOLOGY ......................................................................................................... 31 5.6 PHYSICAL CHANNEL [PHYS01] ........................................................................................... 32 5.7 FUNCTIONAL OVERVIEW..................................................................................................... 33 5.8 PROFILES [PROF01] ............................................................................................................. 33 5.9 THE BLUETOOTH MODULE.................................................................................................. 35 5.10 THE INTERFACE BETWEEN IAS WEBBOARD AND BT MODULE ..................................... 37

6 M16C I/O PORTS DESCRIPTION........................................................................................ 39

6.1 OVERVIEW........................................................................................................................... 39 6.2 M16C PINS DESCRIPTION.................................................................................................... 40

7 HARDWARE COMPONENTS BOARD++ .......................................................................... 43

7.1 CIRCUIT DIAGRAM .............................................................................................................. 43 7.2 LAYOUT............................................................................................................................... 43 7.3 CONNECTORS FOR THE SENSORS AND ACTUATORS............................................................ 44 7.4 COMPONENT LIST................................................................................................................ 45

8 INSTALLING THE MICROC/OS-II..................................................................................... 48

8.1 REQUIREMENTS TO THE INSTALLATION .............................................................................. 48 8.2 COMPANION CD .................................................................................................................. 48 8.3 INSTALLING THE MICROC/OS PORT ................................................................................... 49

APPENDIX A – INDEX OF FIGURES ........................................................................................ 51

APPENDIX B – INDEX OF TABLES .......................................................................................... 52

APPENDIX C – INDEX OF EQUATIONS .................................................................................. 53

APPENDIX D – ABBREVIATIONS............................................................................................. 54

APPENDIX E – TERMINOLOGY ............................................................................................... 56

APPENDIX F – LITERATURE .................................................................................................... 58

APPENDIX G – HEADER AND SOURCE CODE ..................................................................... 60

3

Page 4: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

1 LEGO Mindstorms Sensors

A measurement system is designed to examine parameters (voltage, current, pressure, temperature and so on) and produce an output that indicates its value. For some input values, a range is stipulated in order to provide the current state of a sensor. In engineering systems, a feedback control system is designed to examine a parameter, determine its value, and then actuate some device or process that forces the parameter to a preset value or level.

The LEGO Mindstorms kit allows developing such kind of feedback control system. The sensors measure the signal, the microcontroller process the information and output the results over the actuators. In this section the sensors that come with the LEGO Mindstorms kit will be addressed. The electrical features of the sensors and their software prototype will be discussed in detail, in order to provide a background for understanding their behaviour.

1.1 Overview

The sensors that come with the LEGO Mindstorms kit provide means for measuring a physical or dynamic process in the environment and convert it in signals. The sensors that come with the kit are the following: touch, temperature, rotation and light. The touch and temperature sensors (as described in the following sections) work in the same way and they are called as passive sensors. However, the rotation and light sensors work different from touch and temperature sensors and they are called as active sensors.

When a sensor works in passive mode, it only needs to provide some resistance to create a reading and it is done through a 10KΩ resistors pulling up the inputs to 5 [V]. On the other hand, active sensors work through a two phases scheme: during 2.9 [ms], the microcontroller powers the sensor (+6 [V]), then during about 100µs the analog value is read and no power is provided. Figure 1.1 depicts the electrical behaviour of the active sensors.

Figure 1.1: Power phase and read phase

4

Page 5: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

The voltage on the input is converted to an internal RAW value in the range 0V=0 to 5V=1023, when 10 bits Analog Digital Converter (ADC) is selected. • Touch sensors: If the RAW value is less than about 450 it becomes 1 and if the RAW

value is greater than about 565 it becomes 0. • Temperature sensors: In degrees C, Temp=(785-RAW)/8 within the range -20C to +70C. • Light sensors: Light=146-RAW/7 within the range 0 to 100.

The table 1.1 describes the input range and the corresponding value.

Table 1.1: Input range values

1.2 Touch Sensor

The touch sensor is the simplest sensor, which consist only in a switch. This sensor is a normally closed contact (NCC) and indicates just “5V” when is not pressed and “0V” when is pressed. The Robotic Command Explorer (RCX) uses a 10K pull-up resistor and the sensor is connected to analog input of the ADC. The figure 1.2 depicts the interface circuit.

Figure 1.2: Touch sensor interface

5

Page 6: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

1.2.1 Internal Circuit

The touch sensor internal circuit is depicted in figure 1.3. The sensor is compound of one switch and a voltage of +5 [V] is applied in its terminals. The output signal is collected from point 3. When the sensor has been pressed, the switch will be in the position 1 and point 3 will be direct connected to the ground. When the sensor has been released, the switch will be in the position 2 and point 3 will be about +5 [V].

+5 [V]

.

.. 21

. 3

R

Figure 1.3: Touch sensor schematic

1.2.2 Software Prototype

The touch sensor is represented just like a switch with the states on and off. The figure 1.4 depicts the data flow diagram (DFD) of the touch sensor. As described in section 1.1, the touch sensor works in passive mode, and the microcontroller only needs to read the analog input voltage generated by the sensor. According to the read value, it will be checked if the sensor has been pressed or not. The touch sensor function that has been developed will only indicate if the sensor has been pressed and released.

Read the signal

The sensor hasbeen pressed?

Pressed

ReleasedNo

Yes

Touch

End

Released

Figure 1.4: DFD of the touch sensor

6

Page 7: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

1.3 Light Sensor

The light sensor is an active sensor as described in section 1.1, which works in similar way as rotation sensor. The table 1.1 depicts the voltage range for the light sensor, which can be stipulated in order to provide the current state of the sensor. According to the ambient light level, two modes can represent the state of the sensor. The first one is the raw mode, which the range of reading varies from 0 till 1023 and the second one is the percentage mode, which the range varies from 0 till 100 [Cord03]. The light sensors are usually represented as percentage mode. The figure 1.4 depicts the interface between the light sensor and the M16C microcontroller.

Figure 1.5: Light sensor interface

1.3.1 Internal Circuit

The internal circuit of light sensor is depicted in figure 1.6 [Mind03]. The points 2,3 and 10 depicted in the figure make up the typical LEGO sensor power supply circuit. The A4t84 is a BAV70 and A1p83 is BAW56 high-speed double diodes from Philips. The 11 1/2 is an unused half of a dual op-amp and LM358 is a low power, dual op-amp from Philips and also National Semiconductor.

The 1, 4, 6, 9 make up a 7.5 [mA] current source for the LED 5 and phototransistor 7. The two 3Hp83's are BC857, silicon, PNP, general purpose transistors from Philips. The phototransistor is probably something like the Panasonic, PN168, silicon, NPN phototransistor, which has peak sensitivity at 800nm. An interesting side effect of the circuit is that if the phototransistor is exposed to a very bright light like a laser pointer, the LED will go out. The voltage on the LED is used to bias the op-amp second half 11 2/2 LM358.

7

Page 8: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

The transistor 17 helps to extend the brightness range of the sensor. The 1Ht84 is a BC847W, silicon, NPN, general-purpose transistor from Philips used here as a diode. As the current increases through the phototransistor, the VxI curve of the diode limits the voltage drop and extends the bright end of the range.

The transistor 15 (also used as a diode) in the feedback loop makes up for the voltage drop in transistor 14. Both 1Ht84's are also BC847W silicon, NPN, general purpose transistors from Philips. The point 14 is a voltage follower used to return the light reading through diodes 13 and resistor 12. A4t84 is also a BAV70 high speed double diode from Philips. Data sheets for the semiconductors can be found on the Philips and Panasonic web sites [Phil03].

Figure 1.6: Light sensor schematic [Hurb03]

There is a common operation on LEGO light sensors that involves removal of the

LED. If the LED is removed, then the sensor works better as an ambient light sensor. The simulation of the LEGO light sensor circuit with and without the LED to quantify the effect has been done by [Hurb03]. The figure 1.7 below depicts the light reading that would be made by the RCX over a wide range of ambient light levels. Notice that with the LED the light reading never goes to 0. Not because the LED shines on the phototransistor, but simply the way by which the LED biases the circuit. When the LED is removed it takes a little lighter to make the sensor start to read anything, but it operates over the same light level range as before. Conclusion: Removal of the LED creates a sensor with more resolution (0 to 100) vs. (20 to 100) while slightly losing low light level sensitivity and losing the ability to use it as a reflective sensor.

8

Page 9: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

Figure 1.7: Light sensor behaviour [Hurb03]

1.4 Rotation Sensor

The interface for the rotation sensor looks like the light sensor. About 6V is applied for 2,9ms when the digital output (DO) enables the optocouppler, after this period the voltage sensor is read while 5V is applied through a 10KΩ resistor for 0.1ms. The rotation sensor only outputs 4 analog values of 1.8v, 2.6v, 4.1v and 4.6v. The interface circuit between M16C and the rotation sensor is depicted in figure 1.8.

Figure 1.8: Rotation sensor interface

The figure 1.9 shows the voltage sequence for the rotation sensor with increasing

values. Each voltage corresponds to 22.5 degrees of rotation, so there are 16 counts per one rotation. The pattern of voltages allows the M16C to tell direction from any point.

9

Page 10: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

Figure 1.9: Voltage sequence [Mind03]

The figure 1.10 depicts the read phase of a rotation sensor. Numerous traces are accumulated over some time while rotating axle of sensor. The sensor communicates with M16C through a 4 levels code. The voltages measured for these levels are depicted in table 1.2.

Figure 1.10: Read phase of the rotation sensor

Table 1.2: Rotation sensor voltage levels

Step Volts 1 1.8 2 2.6 3 4.1 4 4.8

As the axle is rotated clockwise, output cycles through steps 1 > 3 > 4 >2 > 1, and

through steps 1 > 2 > 4 > 3 > 1 when rotated counter clockwise. This enables M16C to determinate rotation direction, as depicted in figure 1.11.

10

Page 11: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

Figure 1.11: Rotation sensor direction

There is a problem of rotation sensor: during transition between step 4 and 2, output crosses voltage of level 3, and between step 1 and 3, output crosses voltage of level 2. Since this transition takes some time, there is a probability that it happens just when M16C samples value. In the rotation sensor source code, a delay of 0,1 ms is done in order to allow the discharge of the internal capacitor for the sensor reading. Philippe Hurban tried to determine sampling time, it seems to take place about 60µs after beginning of read phase [Hurb03].

The figure 1.12 depicts the transition between step 4 and step 2. The transition time across 4.1V (step 3) can be evaluated to 1µs. Sampling is done every 3 ms, probability of misread can be evaluated to about 1/3000 at most. One way of tackling this problem for the M16C programming, is to perform the reading after 0,1 ms of the reading phase.

Figure 1.12: Transition between step 4 and 2

1.4.1 Internal Circuit

The figure 1.13 depicts the schematic circuit of the rotation sensor [Hurb03], which D1, D2 rectify power supply, C1 filters it. K1 and K2 are two opto-forks (marked S89), one side contains an infrared led, the other side a phototransistor. Blade of propellar shape part

11

Page 12: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

can interrupt infrared beam of K1, K2, both or none, providing the four phases of the returned value. Since there are 4 blades, we obtain 16 steps per turn. IR leds receive power through R1 (about 5mA). The node between R1 and K1 led is maintained at a 2.2V constant voltage (drop across 2 IR leds. Output of phototransistors are amplified by high gain Darlingtons (Q1, Q2) and (Q3, Q4). Their output drives the base of Q5/Q6, whose base is polarized to the previous 2.2V reference through R4 and R5. Through D3, Q5 and Q6 absorb current provided by 10K ohm resistor in the interface circuit for M16C, and generate the 4 levels, depicted in table 1.3:

Table 1.3: Rotation sensor circuit output

VOUT Q5 Q6 Step 1 1.8 V ON ON Step 2 2.6 V ON OFF Step 3 4.1 V OFF ON Step 4 4.8 V OFF OFF

Figure 1.13: Rotation sensor schematic [Hurb03]

1.4.2 Software Prototype

As described in previous chapters, the rotation sensor works in active mode. The active mode is split into two phases, the first phase the microcontroller over the I/O port power the sensor (+6V) during about 2.9 [ms]. In the second phase, the microcontroller set the I/O port to low, i.e., no power is provided during 0.1[ms] and the analog value is read from the analog input of the AD converter.

12

Page 13: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

The figure 1.14 and 1.15 depict the DFD of the rotation sensor. In the first phase, the output port of the M16C is set to high and a delay of 2.9 [ms] takes place. Thereafter, the M16C set the output port to low and verify in which range the analog input belongs. The voltage intervals, which are verified, are in compliance with the values described in table 1.2. There are too many researchers who have already measured those values [Hurb03] [Mind03]. The values measured by [Hurb03] are different from [Mind03]. The values measured by us are a little different from them as well. The batteries can represent an inconvenient in such case, because if the batteries are not charged appropriately the read values by the sensors cannot represent the real value [Cord03].

After the analog input value has been identified, the parameters: previous and current step are set and the step is incremented or decremented according to the last read values. This process is repeated in a short time interval about 300 [ms], this means that there will be a for-loop with a parameter of 100. This is done because the RCX uses the same time interval for measuring the amount of revolutions when the rotation function is called.

13

Page 14: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

Rotation

Power phase

Delay of 2.9ms

End of the power phase

The read value is >=1.5 and <= 2.1?

no

The read value is >=2.4 and <= 2.8?

The read value is >=2.4 and <= 2.8?

yes

no

yes

yes

Set parameters (currentstep, actual setp)

Set parameters (currentstep, actual setp)

Set parameters (currentstep, actual setp)

The read value is >=2.4 and <= 2.8?

no

yes Set parameters (currentstep, actua setp)

Return

Figure 1.14: DFD of the rotation sensor– Part I

14

Page 15: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

The direction isclockwise ?

The step isincremented

The step isdecremented

no

yes

Previous = CurrentStep

Set Parameters(current step, actual

step)

Current Step = ActualStep

End

Figure 1.15: DFD of the rotation sensor– Part II

15

Page 16: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

2 Additional Sensors to the LEGO Mindstorms

Apart from the sensors that come with the LEGO Mindstorms kit, several groups have designed different kinds of sensor to the LEGO Mindstorms. These sensors are available to purchase over the Internet [Hite01]. In this section the sensors, which are available in the market will be addressed taking into account their functionality and operation.

2.1 Ultrasonic Range Sensor (Model US1051) 2.1.1 Functionality

The Ultrasonic Range Sensor is a sophisticated range-measuring sensor that is compatible with the RCX microcontroller. The US1050 uses high quality ultrasonic transducers and a built in microcontroller to compute the distance to an object or obstruction and provides the result as a light sensor value from 0 – 100 (the light sensor is described in section 1.3), representing the distance in 1/2 inch units to the nearest object. The US1050 has a range from 6 inches to 56 inches (15.2cm - 142.2cm) and connects to an RCX sensor input port. It is housed in a 2x8 x 2 1/3 high brick. It is ideally suited to mobile applications where objects avoidance or range to objects is required.

2.1.2 Operation

The ultrasonic range sensor depicted in figure 2.1 works by emitting a short burst of 40KHz ultrasonic sound from a piezo-electric transducer. A small amount of sound energy is reflected by objects in front of the device and returned to the detector, another piezo-electric transducer. The receiver amplifier sends these reflected signals (echoes) to the microcontroller, which times them to determine how far away are the objects, by using the speed of sound in air. The calculated range is then converted to a constant current signal and sent to the RCX. Detailed information on using the ultrasonic range sensor can be found at [Dean03].

Figure 2.1: Ultrasonic range sensor

16

Page 17: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

2.2 Infrared Proximity Sensor (Model IR1021) 2.2.1 Functionality

The Infrared Proximity Sensor is a highly sensitive sensor housed in a 2x4x1 1/3 high brick and attaches to the RCX input port in the same way as a standard LEGO light sensor. It uses short pulses of relatively bright infrared light and measures the amount of reflected light and generates light sensor values in the range of 0 – 100, where 0 represents no reflection detected. Using bright pulses of infrared light instead of visible light, readings are not affected by bright light or shadows from room lighting or sunshine. It is up to 50 times more sensitive than the standard LEGO light sensor. The sensor has an effective beam of approximately +/- 10 degrees at half power and consumes about 4mA from the active sensor input. 2.2.2 Operation

The infrared proximity sensor depicted in figure 2.2 measures the amount of infrared light reflected from the surface. The greater the distance to the target surface the smaller the reading. When no light is detected, the reading will be 0. If the distance to the surface is less than two inches, the reading will be pegged at 100.

Figure 2.2: Infrared proximity sensor

2.3 Pressure Sensor (Model AC1072) 2.3.1 Functionality

The pressure sensor housed in a 2x4 brick is a precision silicon micro machined pressure sensor and the interface to the RCX is just like the standard light sensor. Just set the RCX sensor input to light sensor mode and the available range of values from 0 to 100 will represent 0 to 50 pounds per square inch pressure. 2.3.2 Operation

The pressure sensor depicted in figure 2.3 measures the pressure relative to current

atmospheric pressure. The sensor is scaled to read 21 [PSI] per light sensor unit. Thus a

17

Page 18: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

reading of 50 can be interpreted as 25 [PSI]. Typical maximum pressures found when using the familiar pneumatic components will be between 30-35 [PSI].

Figure 2.3: Pressure sensor

2.4 Magnetic Compass Sensor (Model MC1031)

2.4.1 Functionality

The magnetic compass sensor calculates a magnetic heading and converts it into light sensor values in the range of 0 - 100 representing 0 - 360 degrees. It is housed in a 6x6x2 1/3 high brick with a 10″ connecting wire to attach to an RCX input port that is configured in the same way as a standard LEGO light sensor.

2.4.2 Operation

The magnetic compass sensor depicted in figure 2.4 uses solid-state magnetometers to measure the two components of the Earth’s magnetic field and calculate a heading. The heading is calculated about 6 times per second and has an accuracy of approximately 5 degrees. This sensor consumes approximately 6mA from the active sensor input.

Figure 2.4: Magnetic compass sensor

18

Page 19: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

3 Liquid Crystal Display

3.1 Overview

The Liquid Crystal Display (LCD) modules are very useful output interfaces to the microcontroller. The LCD that will be integrated in the project has 16 characters x 2 lines, Dot Matrix LCD Module with LED array backlighting. The table 3.1 depicts how each pin of the LCD and M16C should be connected.

Table 3.1: LCD Display Wiring

LCD Module Pin No.

LCD Module Pin (Function) Symbol

M16C Pin Function /

Pin No. 1 Ground (0V) VSS VSS (14,64)

2 Supply Voltage for Logic (+5V) VDD VCC (16, 62)

3 Contrast Adjustment VO See figure 3.1

4 Data / Instruction Select (1 - Data, 0 - Instruction) RS P8.1 (21)

5 Read / Write Select (1 - Read, 0 - Write) R/W P8.2 (20)

6 Signal Enable,

1 or (1 -> 0) - Enable, 0 – Disable

E P8.3 (19)

7 Data Bus Line 0 DB0 P7.0 (30) 8 Data Bus Line 1 DB1 P7.1 (29) 9 Data Bus Line 2 DB2 P7.2 (28) 10 Data Bus Line 3 DB3 P7.3 (27) 11 Data Bus Line 4 DB4 P7.4 (26) 12 Data Bus Line 5 DB5 P7.5 (25) 13 Data Bus Line 6 DB6 P7.6 (24) 14 Data Bus Line 7 DB7 P7.7 (23) 15 LED Supply Voltage + 16 LED Supply Voltage -

19

Page 20: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

Figure 3.1: LCD power supply

The power supply, data and control bus of the LCD and M16C can be connected

directly, as shown in figure 3.2, because the LCD module has an embedded controller.

Figure 3.2: Interconnection between LCD Module and M16C.

The table 3.2 depicts the LCD instructions that are used by the LCD software API,

which will be described in next section. Beyond that, the M16C software should specify a communication protocol allowing bytes exchange between the LCD and M16C, in order to send data and control bytes in one time.

20

Page 21: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

Table 3.2: LCD Instructions

Instruction RS R/W B7 B6 B5 B4 B3 B2 B1 B0 Description and Execution time

Clear Display 0 0 0 0 0 0 0 0 0 1• Clear display and returns

cursor to the first position in the first line

Home Cursor 0 0 0 0 0 0 0 0 1 *

• Returns cursor to the first row and first column

• Returns the previous mesage to its original position.

LCD Mode 0 0 0 0 0 0 0 1 X S

• Defines direction of cursor mode (X=0 to left, X=1 to right).

• Defines if the message should or not be shiftted with an incoming character (S=1 YEs, X=1 to right)

LCD Control 0 0 0 0 0 0 1 D C B

• Turns on (D=1) or off (D=0) Dislay

• Turns on (C=1) or off (C=0) Cursor

• Blink Cursor (B=1) if C=1

Move Cursor or Message 0 0 0 0 0 1 C R * *

• Shift cursor (C=0) or message (C=1) to right if (R=1) or to left if (R=0)

LCD Utilization Mode

0 0 0 0 1 Y N F * *

• Module comunnication with 8 bits (Y=1) or 4 bits (Y=0)

• Number of lines: 1 (N=0) and 2 or more (N=1)

• Character Matrix: 5x7(F=0) or 5x10(F=1)

Point to CGRAM Adress

0 0 0 1 CGRAM Adress • Appoint to the CGRAM

Adress in order to read or write data (byte) posteriorly

Point to DDRAM Adress

0 0 1 DDRAM Adress • Appoint to the DDRAM

Adress in order to read or write data (byte) posteriorly

Read Busy Flag 0 1 BF AC

• Reads the Adress Counter (AC) and Busy Flag (BF). The BF (bit 7) indicates if the last operation was concluded (BF=0) or is still in execution (BF=1)

Write Data in CGRAM / DDRAM

0 1 Data to be written in LCD • Write data appointed by the

Adress Counter (position of the cursor)

Read Data from CGRAM

/ DDRAM 1 1 Data to be read from LCD

• Read data appointed by the Adress Counter (position of the cursor)

21

Page 22: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

3.2 Software Prototype

A software prototype was developed for the LCD Display control, which the DFD is depicted in figure 3.3. The header file describes the I/O ports and the instructions quoted in table 3.2 in the last section.

At first, the algorithm initializes the I/O port of M16C as output and enables the

interruptions. Basically, the writing on LCD display can be in scroll mode or not, if the scroll mode is selected, the LCD_scroll funtion last 200 ms more for shifting the message. After writing a message, the cursor returns to the home position and the delay function is called in order to read the message on display.

Figure 3.3: DFD of the LCD display

22

Page 23: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

4 LEGO Mindstorms Motors 4.1 Overview

The motors will be the primary source of power. The robot will use them to move around, lift loads, operate arms, grab objects, pump air, and perform any other task that requires power. In this section, the electrical features of the LEGO motors will be addressed.

Every motor is designed to run at a specific voltage, but they are very tolerant when it comes to decreases in the supplied voltage. They simply turn more slowly. However, if the voltage is increased above the specific limit for a motor, there will be a good chance of burning it out. The current LEGO THECHNIC line includes three types of 9V DC motors (as depicted in figure 4.1): the ungeared motor (a), the geared motor (b), and the micro-motor (c) and table 4.1 summarizes the electrical properties of these three motors [Elli02].

Figure 4.1: The LEGO TECHNIC Motors

The ungeared motor (a) has been the standard LEGO TECHNIC motor for a long

time. Its axle is simply an extension of the inner electric motor shaft, and for this reason it is called ungeared. Electric motors usually rotate at very high speeds, and this one is no exception, turning at more than 4000 rpm (revolutions per minute). Nevertheless, this motor draws an amazing amount of current and under heavy loads or stall situations; it drains the batteries very quickly.

23

Page 24: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

The geared motor (b) runs at about 350 rpm with no load (typically 200/250 rpm with medium load). It is much more efficient than the older kind, and has low current consumption. The micro-motor (c) is a geared motor as well. It is geared down so much that its output shaft turns at about 30 rpm. Nevertheless, its torque is incredibly low, well below 1 N.cm. It is also surprisingly noisy, and very easy to jam.

Table 4.1: Properties of the LEGO TECHNIC Motors

Properties Maximum voltage [V]

Minimum current (no load) [mA]

Maximum current (stall)

[mA]

Maximum speed (no

load) [rpm]

Speed under typical load

[rpm] Ungeared

Motor 9 100 450 4000 2500

Geared Motor

9 10 250 350 200

Micro-motor

9 5 90 30 25

4.2 The Interface between IAS WebBoard and Motor Driver

In this section a description about how to interface the LEGO DC motor to the IAS WebBoard will be addressed. Basically, the motor control means that the microcontroller or a PC must turn on, off and change the direction of the motors in a given period of time. There are many dedicated chips for this purpose. For this purpose, we have used the L293D which has a dual H-bridge driver that can handle continuous loads up to 36 V and 0.6 A. This device is suitable for using in switching applications at frequencies up to 5KHz.

The figure 4.2 depicts the interface between the IAS WebBoard and the LEGO motors. It only requires two ENABLES (one for each motor) and four PHASES (two for each motor) signals. ENABLE must be a pulse-width-modulated (PWM) signal. PWM is a very common, highly and efficient method for controlling motor speed.

The schematic shows that the L293D requires only 3 digital lines to control a single motor. The gear motor of the LEGO described in section 4.1 requires a voltage supply of +9V. This voltage supply is connected to pin 8. No external heat sinks are required. The L293D handle much stronger motors with supply voltage up to 36V and 0.6A

24

Page 25: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

Figure 4.2: LEGO motor interface

The PWM can be understood as a bicycle. There are time when the cyclist pedal (on-

time), and times when the cyclist coast (off-time). When coasting the cyclist is using his momentum. When the cyclist feels (modulation) he is going too slowly, he pedals (pulse) again for some time (width) and the coast again. This pedal-coast-pedal cycle is called PWM. The amount of time the cyclist pedal is called on-time (equation 4.1). The amount of time the cyclist coast is called the off-time (equation 4.2). The total time is the sum of on-time and off-time.

PWM signals are described by a duty cycle (D.C) percentage. The duty cycle is the ratio of the on-time and total time. For example, a 100% D.C means that the motor is receiving energy all the time. A 50% means that the motor receives energy only half the time.

Typically motor speed controllers are designed in hardware with timer circuitry. However, the PWM signals can be programmed via software. This is much more economical and efficient. Any external circuitry is unnecessary and the new duty cycle can be quickly reprogrammed.

100DutyCycleTotalTimeTimeOn ∗

=−

Equation 4.1: On-time pulse

OnTimeTotalTimeTimeOff −=−

Equation 4.2: Off-time pulse

25

Page 26: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

As an illustration, consider the figure 4.3. The two pulse width modulated signals (S1 and S2) have the same period (total-time) of 1ms, thus their frequency is 1KHz. The duty cycles are 10% and 25% respectively. However, it can be seen that their relative on-time (Ton) and off-time (Toff) are different.

Figure 4.3: Depict two pulse width modulated signals

The on-time and off-time signals from S1 and S2 can be calculated as:

sTimeOff

sTimeOnTimeOn

µ

µ

900101001011_

1001_100

101011_

63

3

=×−×=−

=−∴××

=−

−−

sTimeOff

sTimeOnTimeOn

µ

µ

750102501012_

2502_100

251012_

63

3

=×−×=−

=−∴××

=−

−−

4.3 Software Prototype

A software prototype was developed and implemented in the IAS WebBoard. The figure 4.4 depicts the DFD of the motor. As described in section 4.2, to generate the PWM signals the on-time, off-time and total-time must be known beforehand. The variable speed is considered as duty cycle.

The algorithm calculates the time in which the signals remain in high and low. After that, it enables the motor and check in which direction the motor must run. A simple delay function is used to keep the signals in the on-time period. Therefore, the signals are set to low and another delay function keeps the signal in the off-time period. The ports in which the motors are connected must be know beforehand because the software will send the signals to the I/O ports with the purpose to switch the motor on or off in compliance with the PWM signals.

26

Page 27: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

Calculate the On andOff Time signal

Enable the motor driver

PositiveDirection ?

Enable port 1 anddisable port 2

Disable port 1 andenable port 2

Delay OnTime

Disable both ports

Delay OffTime

No

Yes

Motor

End

Figure 4.4: DFD of the motor

27

Page 28: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

5 Bluetooth Technology

In this section an introductory level regarding the features of Bluetooth Technology will be addressed. The key role in maintaining specifications of the protocol, network topology, physical channel and profiles will be discussed.

5.1 Overview

Bluetooth has become the de-facto global standard for short-range wireless data communications that allows devices to communicate with each other using secure radio waves, and is the basis for the IEEE 802.15.1 standard. Bluetooth operates in the 2.4 GHz Industrial, Scientific, and Medical (ISM) band. Bluetooth has been designed to be robust enough to operate in noisy environment.

5.2 What is Bluetooth Good For?

The cost of adding bluetooth wireless capability is expected to be less than the cost of cable it is replacing, especially regarding the additional cost of the connectors at the receiving end in a device that is already space-limited such as PC, PDA, or cellular phone. Additional savings are realized in devices such as PC’s where a single Bluetooth radio can replace several cables.

The Personal Area Networks (PAN) allows the Personal Digital Assistant (PDA) to synchronize with your PC automatically when they come within range. Many usage models are envisioned for Bluetooth, ranging from embedded tire sensors, which will notify the driver of abnormal tire pressure or temperature conditions.

5.3 Bluetooth Specification

The bluetooth specification, which is controlled by Special Interest Group (SIG)1, defines a short-range link capable of voice or data communication with a maximum throughput of 720 Kbit/s, over a distance of roughly 3 to 100 meters. Key features are robustness, low complexity, low power, and low cost.

The bluetooth protocol uses a combination of circuit and packet switching. Up to three simultaneous 64Kbit/s full duplex voice channels are supported. Alternatively, a channel that supports asynchronous data and synchronous voice may be used. The synchronous data

1 The SIG was created by Ericsson Mobile Communications with the purpose for monitoring the technical development of a

short-range radio and create an open global standard, thus preventing the technology from becoming the property of any single company.

28

Page 29: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

channel can support asymmetric data rates up to 723.2 Kbit/s with a 57.6 Kbit/s back channel, or a symmetric channel data rate of 433.9 Kbit/s in both directions [Blue01].

When producing the radio specification, high emphasis was placed on developing a design that would enable single-chip CMOS implementations, thereby reducing cost, power consumption, and the chip size required for implementation in mobile devices [Eric00]. Single-chip CMOS implementations, such as depicted in figure 5.1, are already available from multiple manufacturers. This device contains the RF radio, base band controller and microprocessor on a single CMOS integrated circuit.

Figure 5.1: Single-chip CMOS

Documentation for Bluetooth consists primarily of the specification, which comprise

the core hardware and software protocol specification, usage case scenario profiles, and interoperability requirements.

5.4 Protocol Stack [Info01]

The Bluetooth specifications define not only a radio system but also cover the underlying structure. The Core Specification contains a software protocol stack similar to the more familiar Open Systems Interconnect (OSI) standard reference model for communication protocol stacks. It permits applications to discover devices, the services they offer and permission to use these services. The stack is a sequence of layers with features crossing single or multiple layered boundaries. Figure 5.2 depicts the stack with each block corresponding to a Core Specification chapter. The core specification consists of over 1000 pages and details the Bluetooth protocol architecture and describes how the technology works. • Radio • Baseband • Link Manager Protocol (LMP) • Host Controller Interface (HCI) • Logical Link Control and Adaptation Protocol (L2CAP) • RFCOMM • Service Discovery Protocol (SDP)

29

Page 30: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

If we ascend the stack, we first come across the fundamental component, the radio. The radio modulates and demodulates data for transmitting and receiving over the air. The operating band of the radio is divided into 1 MHz spaced channels with a chosen modulation scheme of Gaussian Frequency Shift Keying (GFSK). Each channel is specified to signal at 1mega symbols per second, equivalent to 1 Mb/s. Above the radio are the Baseband and Link Controller, they are responsible for controlling the physical links via the radio, assembling the packets and controlling the frequency hopping.

Progressing through the layers, the Link Manager (LM) controls and configures links to other devices. The Host Controller Interface (HCI) is above the LM layer and is probably one of the most important layers to consider as a designer. It handles communication between host and the module. The standard defines the HCI command packets that the host uses to control the module, the event packets used by the host to inform lower protocol layers of changes, the data packets for voice and data traffic between host and module and the transport layer used by the HCI packets. The transport layer can be USB (H2), RS232 (H3), UART (4) or a robust proprietary standard such as BCSP (BlueCore Serial Protocol).

The Logical Link Control and Adaptation (L2CAP) is a multiplexor, adapting data from higher layers and converting between different packet sizes. The next 4 layers could be loosely grouped as communication interfaces. These are RFCOMM (Radio Frequency COMMunication port), which provides an RS232 like serial interface. Wireless Application Protocol (WAP) and OBject EXchange (OBEX) are responsible for providing interfaces to other Communications Protocols. The final member of this rough grouping is the Telephony Control protocol Specification (TCS) providing telephony services. Service Discovery Protocol (SDP) lets devices discover the services available on another Bluetooth device.

Figure 5.2: The Bluetooth protocol stack

30

Page 31: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

5.5 Network Topology

Bluetooth devices exist in small ad-hoc network configuration with the ability to operate as either master or the slave; the specification also allows a mechanism for master and slave to switch their roles. The configurations can be single point, which is the simplest configuration with one master and one slave. Multipoint, called a Piconet, based on up to 7 slaves clustered around a single Master. And a third type called a Scatternet, this is a group of Piconets effectively hubbed via a single Bluetooth device acting as a master in one Piconet and a slave in the other Piconet. For instance, a cellular phone may be a piconet master with a headset as a slave. Additional slaves may be added to the piconet, such as, PDAs and PCs. This cellular phone may also be slave in another piconet to a master landline phone base unit. The Scatternet permits either larger coverage areas or number of devices than a single Piconet can offer. Figure 5.3 depicts the different master and slave topologies permitted for networks in the standard.

The role of the master is to control the available bandwidth between the slaves, it calculates and allocates how often to communicate with each slave and locks them into the appropriate frequency hopping sequence. The specification describes an algorithm that calculates the hop sequence, the seed being based on the master’s device address and clock. In addition to hop sequence control, the master is responsible for transmitting control by dividing the network into a series of time slots amongst the net members, as part of a Time Division Multiplexing (TDM) scheme. These time slots can consist of data and potentially additional voice traffic i.e. you will always need a data channel before you can add a voice channel. The time slot is defined as 625 µs and all packet traffic is allocated 1, 3 or 5 slots, grouped together in transmit and receive pairs. Prior to connection some operations such as inquiry, paging and scanning operations may sometimes occur on half slots.

Figure 5.3: Point to point, Piconet and Scatternet [Blue01]

31

Page 32: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

5.6 Physical Channel [Phys01]

The bluetooth radio channel2 is represented by a pseudo-random hopping sequence that hops through 79 (in restricted countries a limited frequency hopping schemes with just 23 channels is used and is catered for in the bluetooth specification). RF channels with a channel spacing of 1 MHz. Starting at a base frequency of 2402 MHz then the frequency of the channels, f, can be expressed as:

nMHzf += 2402 Equation 5.1: Frequency of the channels

where, n, is the channel number with an integer value in the range of 0 to 78.

In this frequency hope sequence scheme there are 1600 hops per second, which is a hop every 625 µs. Part of this hop timing is taken up by the guard time of 220 µs allowing the synthesizer time to settle. The frequency hopping implements time division multiplexing as shown in Figure 5.4. The basis of the scheme has the Master device transmitting in the first 625 us slot, k, and here the Slave receives. In the next slot k = 1 the Slave is permitted to transmit and the master listens.

Figure 5.4: Frequency Hopping, master and slave interact on corresponding slots

The radio must be able to retune and stabilize on a new frequency within tight time

constraints. This is pushed further when establishing a connection; the hop rate can be shortened to every 312.5 us. As the radios are constantly hopping to different radio channels, this ensures that packets affected by interference on one channel can be retransmitted on a different frequency channel. To further enhance resilience both ARQ (Automatic Repeat reQuest) and FEC (Forward Error Correction) form part of the specification.

One drawback with the normal hop sequence is the time taken for production testing. Bluetooth ensures adequate frequency coverage with a test sequence allowing the radios to be tested at a faster rate.

2 Bluetooth uses Frequency Hopping Spread Spectrum (FHSS) techniques in order to improve its immunity from interference.

32

Page 33: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

5.7 Functional Overview

The bluetooth baseband describes the specifications of the signal digital processing part of the hardware, the bluetooth link controller, which controls how connections in a Piconet are created and maintained. Bluetooth radios transition through the following connection state during normal operation: • Standby – Waiting to join a piconet • Inquire – Ask about a radio to connect to • Page – Connect to a specific radio • Connected – Actively on a piconet (master or slave) • Park/Hold/Sniff – Low power connected states

Figure 5.5 illustrates the Bluetooth radio’s functional states, along with typical state transition times. Note that the typical inquiry time is about 2 seconds, but may be as long as 10 seconds, which may preclude using Bluetooth for high-speed “drive-by” applications involving moving vehicles and fixed access points.

Figure 5.5: Functional State Diagram [Kard00]

5.8 Profiles [Prof01]

The profile section of the specification consists of about 400 pages describing how the technology is used. Profiles describe how different parts of the specification can be used to fulfill a desired function for a Bluetooth device. In other words, profiles define the protocols and protocol features supporting a particular usage model. There are a number of usage models identified by the Bluetooth SIG as fundamental. Each usage model is accompanied by a profile.

33

Page 34: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

Each bluetooth device must support at least one profile, but may support several profiles. The idea is that if two devices support the same profile, then they should be able to interoperate. The profiles specified in version 1.1 of the Bluetooth specifications are: • Generic Access Profile (GAP) • Service Discovery Application Profile (SDAP) • Cordless Telephony Profile (CTP) • Intercom Profile (IP) • Serial Port Profile (SPP) • Headset Profile (HP) • Dial-up Networking Profile (DNP) • Fax Profile (FP) • LAN Access Profile (LAP) • Generic Object Exchange Profile (GOEP) • Object Push Profile (OPP) • File Transfer Profile (FTP) • Synchronization Profile (SP)

There are four general profiles that are widely utilized by these usage model oriented profiles. These are the generic access profile, the serial port profile, the service discovery application profile, and the generic object exchange profile (GOEP).

The Generic Access Profile defines the generic procedures related to discovery of Bluetooth devices and link management aspects of connecting to Bluetooth devices. It is the core on which all other Profiles are based.

The Service Discovery Application Profile defines the features and procedures for an application in a Bluetooth device to discover services registered in other Bluetooth devices and retrieves any desired available information pertinent to these services.

The Cordless Telephony Profile defines the features and procedures that are required for interoperability between different units active in the 3-in-1-phone use case. This profile also shows how the use case can be applied generally for wireless telephony in a residential or small office environment.

The Intercom Profile defines the requirements for Bluetooth devices necessary for the support of the intercom functionality within the 3-in-1 phone use case. This is also referred to as the “walkie-talkie” usage of Bluetooth.

The Serial Port Profile defines the requirements for Bluetooth devices necessary for setting up emulated serial cable connections using RFCOMM between two peer devices.

34

Page 35: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

The Headset Profile defines the requirements that shall be used by devices implementing the usage model called “Ultimate Headset”.

The Dial-up Networking Profile defines the requirements that shall be used by devices (modems, cellular phones) implementing the usage model called “Internet Bridge”.

The Fax Profile defines the requirements for Bluetooth devices necessary to support the fax use case. This allows a Bluetooth cellular phone (or modem) to be used by a computer as wireless fax modem to send/receive a fax message.

The LAN Access Profile defines how Bluetooth enabled devices can access the services of a LAN using PPP. Also, this profile shows how the same PPP mechanisms are used to form a network consisting of two Bluetooth enabled devices.

The Generic Object Exchange Profile lays the basis (defines the protocols and procedures) for Bluetooth devices necessary for the support of the object exchange usage models. The usage model can be the Synchronization, File Transfer, or Object Push Model.

The Object Push Profile defines the requirements for applications providing the object push usage model. Typical scenarios covered by this profile involve the pushing/pulling of data objects between Bluetooth devices.

The File Transfer Profile defines the requirements for applications providing the file transfer usage model. Typical scenarios involve a Bluetooth device browsing, transferring and manipulating objects on/with another Bluetooth device.

The Synchronization Profile defines the requirements for applications providing the synchronization usage model. Typical scenarios covered by this profile involve manual or automatic synchronization of Personal Information Manager (PIM) data when two Bluetooth devices come within range.

5.9 The Bluetooth Module

As described in previous sections, the M16C microcontroller that is used in the IAS WebBoard belongs to the RenesasTechnology Corporation. Renesas Technology has been engaged with the development of Bluetooth H/W and S/W since 1998 when bluetooth specification Version 0.7 was released. Thus, we have decided to use the bluetooth (BT) module from Renesas, by the fact that there are already many bluetooth applications developed with the M16C.

The module that will be used is called M3A-ZA12. This module is based on the Renesas Technology chipset of baseband IC M64110WG and the RF transceiver IC M64846FP plus an additional SMD antenna. The Renesas Baseband provides the full

35

Page 36: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

functionality of HCI, Link Manager and Baseband (as described in section 5.4), in compliance with Bluetooth specification V1.1. The M64846FP is a semiconductor integrated designed for 1 chip RF/IF transceiver with synthesizer for Bluetooth. The M3A-ZA12 specification is depicted in table 5.1.

Table 5.1: M3A-ZA12 Specification

Size 15.0x25.0x2.5mm (shield part) Feature HCI module with antenna, SMD type surface mount possible on

board HCI HCI-UART

Voice Interface 14 bit Linear PCM Supply Voltage 1.8~2.0 [V] (Internal), 2.7~3.3 [V] (I/O)

Clock 16 [MHz], 32.768 [KHz] built-in

The Renesas bluetooth adopt a dual power supply system (1.9 [V] system for the internal logic; 3.0 [V] for RF and external I/O’s) and dual clocks. The dual clocks consist of a main clock operating on the frequency of 16 [MHz] and a sub clock operating on a lower frequency of 32.768 [KHz]. The figure 5.6 depicts the M3A-ZA12 power consumption.

[email protected],[email protected]

[email protected],[email protected]

Transmit[HV1][email protected],48mA@3V

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

[email protected],[email protected]

[email protected],[email protected]

Low Power [email protected],[email protected]

Disconnection

Figura 5.6: Bluetooth power consumption

The M3A-ZA12 is compound of 28 pins and table 5.2 depicts each pin.

36

Page 37: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

Table 5.2: M3A-ZA12 Pins

Pin No Name Pin No Name 1 NC 15 GND 2 MODE[2] 16 TESTOUT 3 GND 17 DVDD18 4 GND 18 TXDBASE 5 EXIREQ 19 RXDBASE 6 INTOUT 20 UCTS 7 MODE[0] 21 URTS 8 MODE[1] 22 URXD 9 VUDATA 23 UTXD 10 VBITCLK 24 NC 11 VDDATA 25 XRDY 12 V8KFP 26 RSTIN 13 GND 27 GND 14 VDD(3V) 28 NC

5.10 The Interface between IAS WebBoard and BT Module

The interface between IAS WebBoard and BT Module is depicted in figure 5.7. The UART0 was used as board internal communication between the M3A-ZA12 and M16C. The UART0 works as asynchronous HCI interface to the M3-ZA12.

URTSURXD

1.9V

RxD0

M3A-ZA12

1516171819202122232425262728 1

234567891011121314

GNDTESTOUTDVDD18TXDBASERXDBASEUTCSURTSURXDUTXDNCXRDYRSTINGNDNC NC

MODE[2]GNDGND

EXIREQINTOUT

MODE[0]MODE[1]VUDATAVBITCLKVDDATA

V8KFPGND

VDD(3V)

RTS0

3V

Figure 5.7: BT module interface

The table 5.3 depicts the pins of board internal interface and the direction. The RTS0

signal of the M16C is not generated automatically by the MCU, thus the RTS0 signal must be fixed to low level just setting the port, to show the BT module a continuous ready signal.

37

Page 38: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

Table 5.3: Pinning of board internal interface and direction

Interface M16C pin M16C name Direction BT-Module M3A-ZA12

P6.3 TxD0 → URxD P6.0 CTS0 ← URTS P6.2 RxD0 ← UTxD

UA

RT

0

P6.1 RTS0 → UCTS

38

Page 39: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

6 M16C I/O Ports Description

In this section the description of the I/O ports for the M16C microcontroller will be addressed. The number of I/O ports is distributed among the Ethernet Controller, Serial Communication, LCD Display, Bluetooth Module, Motor Interface and Sensors Interfaces.

6.1 Overview The M16C is 16-bit microcontroller from Mitsubishi with following features [Mits03]:

Table 6.1: M16C Features

Feature Description

Memory capacity • ROM – 256K bytes; • RAM - 20K bytes

Shortest instruction execution time • 62.5ns (f(XIN)=16MHZ, VCC=5V) • 100ns (f(XIN)=10MHZ, VCC=3V, with

software one-wait) : Mask ROM, flash memory 5V version

Supply voltage

• 4.2V to 5.5V (f(XIN)=16MHZ, without software wait) : Mask ROM, flash memory 5V version.

• 2.7V to 5.5V (f(XIN)=10MHZ with software one-wait) : Mask ROM, flash memory 5V version

Low power consumption 25.5mW ( f(XIN)=10MHZ, with software one-wait, VCC = 3V)

Interrupts 25 internal and 5 external interrupt sources, 4 software interrupt sources; 7 levels (including key input interrupt)

Multifunction 16-bit timer 5 output timers + 6 input timers (3 for timer function only)

Serial I/O 5 channels (2 for UART or clock synchronous, 1 for UART, 2 for clock synchronous)

DMAC 2 channels (trigger: 24 sources)

A-D converter 10 bits X 8 channels (Expandable up to 10 channels)

D-A converter 8 bits X 2 channels CRC calculation circuit 1 circuit Watchdog timer 1 line

Programmable I/O 70 lines, P0 to P10 (except P85) (8 bits x 6, 7 bits x 2, 4 bits x 2)

Input port 1 line (P8.5 shared with NMI pin)

Clock generating circuit 2 built-in clock generation circuits (built-in feedback resistor, and external ceramic or quartz oscillator)

Number of basic instructions 91 instructions

39

Page 40: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

The figure 6.1 depicts the Block Diagram of M16C [Mits03]:

Figure 6.1: M16C Block Diagram

6.2 M16C Pins Description

In this section a description of the M16C pins is addressed, indicating which I/O port will be used for interface the Ethernet Controller, Serial Communication, LCD Display, Bluetooth Module, 8 Motors and Sensors, as depicted in Table 6.2 [Mits03].

From the original project of IAS WebBoard, the configuration of the Ethernet Controller and the Serial Communication (UART1) were kept, whereas the LCD Display, Bluetooth Module (UART0), 8 Motors (Motor_A to Motor_H) and Sensor (Touch, Rotation and Light) interfaces were added, as shown at Table 6.2 [Mits03].

Table 6.2: M16C Pins Description Pin Name

Signal Name

I/O Type Function Description LEGO Board

Interface

Vcc,Vss Power Supply Input

Supply 2.7 to 5.5 V to the VCC pin. Supply 0 V to the VSS pin.

CNVss CNVss Input This pin switches between processor modes. It should be connected to the

VSS pin.

40

Page 41: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

RESET Reset Input Input A Low Signal (0V) on this input resets the

microcomputer.

XIN Clock Input Input

XOUT Clock Output Output

These pins are provided for the main clock generating circuit. A ceramic

resonator or crystal sholub be conneted between the XIN and the XOUT pins.

AVCC This pin is a power supply input for the

A-D converter. It should be connected to Vcc

AVSS

Analog power supply input

This pin is a power supply input for the A-D converter. It should be connected to

Vss

VREF Reference

voltage input

Input This pin is a reference voltage input for the A-D converter

P0.0 to P0.7

I/O port P0

Input/ Output

This is an 8-bit CMOS I/O port. It has an input/output port direction register that

allows the user to set each pin for input or output individually. When set for input, the user can specify in units of four bits via software whether or not they are tied

to a pull-up resistor.

Ethernet Controller (D0 to D7)

P0.0 to P0.7

I/O port P1

Input/ Output

This is an 8-bit I/O port equivalent to P0. P1.5 to P1.7 also function as external interrupt pins as selected by software

Ethernet Controller

(D8 to D15)

P2.0 to P2.3

This is an 8-bit I/O port equivalent to P0. These pins output 4 low-order adresses

bits (A0 to A3)

Ethernet Controller (A0 to A3)

P2.4, P2.5 and

P2.6

I/O port P2 Output

This is an 8-bit I/O port equivalent to P0. These pins output the control of Motor_A Motor_A

P2.7, P3.0 and

P3.1

I/O port P2 and

P3 Output This is an 8-bit I/O port equivalent to P0.

These pins output the control of Motor_B Motor_B

P3.2, P3.3 and

P3.4

This is an 8-bit I/O port equivalent to P0. These pins output the control of Motor_C Motor_C

P3.5, P3.6 and

P3.7

I/O port P3 Output

This is an 8-bit I/O port equivalent to P0. These pins output the control of Motor_D Motor_D

P4.0, P4.1 and

P4.2 Output This is an 8-bit I/O port equivalent to P0.

These pins output the control of Motor_E Motor_E

P4.4 to P4.7

I/O port P4 Input/

Output

This is an 8-bit I/O port equivalent to P0. Used by the Ethernet Controller (NCS0 to

NCS3)

P5.0 to P5.7

I/O port P5

Input/ Output

This is an 8-bit I/O port equivalent to P0. Used by the Ethernet Controller (NBHE,

NWR, NWR, NRD, NRDY, NALE, NHOLD, HOLDA, BCLK)

Ethernet Controller

41

Page 42: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

P6.0 to P6.3

I/O port P6

Input/ Output

This is an 8-bit I/O port equivalent to P0. Pins in this port also function as UART0

I/O pins as selected by software.

Bluetooth Module

(UART0)

P6.4 to P6.7

I/O port P6

Input/ Output

This is an 8-bit I/O port equivalent to P0. Pins in this port also function as UART1

I/O pins as selected by software.

Serial Communication

(UART1)

P7.0 to P7.7

I/O port P7

Input/ Output

This is an 8-bit I/O port equivalent to P0. Pins in this port are used for transmitting the bytes to the LCD Display (D0 toD7)

LCD Display (D0 toD7)

P8.0 Output This is an 8-bit I/O port equivalent to P0.

This pin is . used for control the LCD Display (RS – Data or Instruction Select)

LCD Display (RS)

P8.1 Output

This is an 8-bit I/O port equivalent to P0. This pin is . used for control the LCD

Display (R/W – Read or Write Instruction)

LCD Display (R/W)

P8.2 Output This is an 8-bit I/O port equivalent to P0. Ethernet Controller

P8.3 Input This is an 8-bit I/O port equivalent to P0.

This pin is used for control the LCD Display (E – Signal Enable)

LCD Display (E)

P8.5 Input

P8.5 is an input-only port that also functions for NMI. The NMI interrupt is

generated when the input at this pin changes from “H” to “L”. The NMI function cannot be cancelled using

software. The pull-up cannot be set for this pin.

P8.4, P8.6 and

P8.7

I/O port P8

Output This is an 8-bit I/O port equivalent to P0. These pins output the control of Motor_F Motor_F

P9.0, P9.1 and

P9.2

This is an 8-bit I/O port equivalent to P0. . These pins output the control of Motor_G Motor_G

P9.3, P9.4 and

P9.7

I/O port P9 Output

This is an 8-bit I/O port equivalent to P0. . These pins output the control of Motor_H Motor_H

P9.5 and P9.6

I/O port P9 Input

This is an 8-bit I/O port equivalent to P0. These pins are used as ANEX0 and

ANEX1 extending the A-D converter to 10 channels.

Sensor Interfaces

P10.0 to P10.7

I/O port P10 Input

This is an 8-bit I/O port equivalent to P0. These Pins function as A-D converter

input pins

Sensor Interfaces

42

Page 43: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

7 Hardware Components Board++

The circuit diagram, layout and component sizing of the board++ are addressed in this section. The implementation of the schematic was done according to the previous chapter of this document. The whole schematic of the board++ consists of the circuit interface of 10 (ten) sensors working either in passive or in active mode, 6 (six) geared motors, one bluetooth module from the Mitsumi so-called WML-C10 and one LCD display.

There are three different levels of voltages (3.3; 6.0; 9.0 [V]) available in the board++. The bluetooth module requires a voltage level of 3.3 [V], the sensors require 6.0 [V] and the motors require a maximum voltage of 9 [V]. The connectors that are responsible for connecting the board++ with the microcontroller M16C are the same of the IAS Webboard, because both boards must be directly coupled.

7.1 Circuit Diagram

Figure 7.1: Board++ Schematic

7.2 Layout

43

Page 44: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

Figure 7.2: The board++ layout

7.3 Connectors for the Sensors and Actuators

In this section a description of the pins for the hardware transducer of the LEGO Mindstorms will be addressed. As described in section 6.2 regarding the pins description of the microcontroller M16C, the board++ is able to connect up to 10 sensors (active or passive) and 5 geared motors simultaneously.

Any sensor that has the same electrical behaviour of the LEGO Mindstorms sensors can be connected to the board++. The only change to be made is regarding the software, because the signals that this new sensor produces can respond in a different way from the LEGO sensors but in the same voltage range as described in section 1 regarding the electrical behaviour.

Thereby the programmer must know beforehand which parameter must be measured (e.g., voltage, current, pressure, temperature and son on) and provide by the software a value that indicates the current state of the sensor. For instance, a sensor that measures a temperature from 15 to 40 [ºC] in a room produces as output a voltage level from 0 to 5 [V]. Therefore, the following adaptation via software must be done:

51525

515 ×+=∴+= XTXT NEWNEW

Equation 7.1: Adaptation Formula

Where X represents the voltage produced by the sensor for a given temperature.

44

Page 45: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

Table 7.1: Pins description for the sensors and actuators

Pins Description X5-1 Connection of the active or passive sensor 1 X5-2 Connection of the active or passive sensor 2 X5-3 Connection of the active or passive sensor 3 X5-4 Connection of the active or passive sensor 4 X5-5 Connection of the active or passive sensor 5 X5-6 Connection of the active or passive sensor 6 X5-7 Connection of the active or passive sensor 7 X5-8 Connection of the active or passive sensor 8 X5-9 Connection of the active or passive sensor 9 X5-10 Connection of the active or passive sensor 10 X6-1 Connection of the geared motor A X6-2 Connection of the geared motor A X6-3 Connection of the geared motor B X6-4 Connection of the geared motor B X6-5 Connection of the geared motor C X6-6 Connection of the geared motor C X6-7 Connection of the geared motor D X6-8 Connection of the geared motor D X6-9 Connection of the geared motor E X6-10 Connection of the geared motor E

7.4 Component List

The table 7.1 depicts all components used in the board++. The most components are already available in the Eagle; other components were imported from the IAS-Webboard project. Only the BT module was designed and implemented in this project. The table was described in details tanking into account all relevant specification of each component.

Table 7.2: Component List

Part Value Device Package Library R_01 10K TRIM_EU-B64W B64W B64W R_02 10K R0805 0805 IAS-Webboard R_03 10K R0805 0805 IAS-Webboard R_04 1K R-EU_0204/5 0204/5 Rcl R_05 1K R-EU_0204/5 0204/5 Rcl R_06 1K R-EU_0204/5 0204/5 Rcl R_07 1K R-EU_0204/5 0204/5 Rcl R_08 1K R-EU_0204/5 0204/5 Rcl R_09 1K R-EU_0204/5 0204/5 Rcl R_10 1K R-EU_0204/5 0204/5 Rcl R_11 1K R-EU_0204/5 0204/5 Rcl R_12 1K R-EU_0204/5 0204/5 Rcl R_13 1K R-EU_0204/5 0204/5 Rcl

45

Page 46: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

R_14 470Ω R-EU_0204/7 0204/7 Rcl R_15 470Ω R-EU_0204/7 0204/7 Rcl R_16 470Ω R-EU_0204/7 0204/7 Rcl R_17 470Ω R-EU_0204/7 0204/7 Rcl R_18 470Ω R-EU_0204/7 0204/7 Rcl R_19 470Ω R-EU_0204/7 0204/7 Rcl R_20 470Ω R-EU_0204/7 0204/7 Rcl R_21 470Ω R-EU_0204/7 0204/7 Rcl R_22 470Ω R-EU_0204/7 0204/7 Rcl R_23 470Ω R-EU_0204/7 0204/7 Rcl R_24 10K R-EU_0204/5 0204/5 Rcl R_25 10K R-EU_0204/5 0204/5 Rcl R_26 10K R-EU_0204/5 0204/5 Rcl R_27 10K R-EU_0204/5 0204/5 Rcl R_28 10K R-EU_0204/5 0204/5 Rcl R_29 10K R-EU_0204/5 0204/5 Rcl R_30 10K R-EU_0204/5 0204/5 Rcl R_31 10K R-EU_0204/5 0204/5 Rcl R_32 10K R-EU_0204/5 0204/5 Rcl R_33 10K R-EU_0204/5 0204/5 Rcl R_34 1K R-EU_0204/5 0204/5 Rcl R_35 3K3 R-EU_0207/10 0207/10 Rcl R_36 560Ω R-EU_0207/2 0207/2 Rcl IC_01 8-bit serial-in /

parallel-out shift register

74HCT164D SO14 74xx-eu

IC_02 Push_Pull four channel drivers

L293D DIL16 St-microeletronics

IC_03 Push_Pull four channel drivers

L293D DIL16 St-microeletronics

IC_04 Push_Pull four channel drivers

L293D DIL16 St-microeletronics

IC_05 LM741 Operational Amplifier

uA741D SO08 linear

IC_06 LM741 Operational Amplifier

uA741D SO08 linear

IC_07 LM741 Operational Amplifier

uA741D SO08 linear

IC_08 LM741 Operational Amplifier

uA741D SO08 linear

IC_09 LM741 Operational Amplifier

uA741D SO08 linear

IC_10 LM741 Operational Amplifier

uA741D SO08 linear

IC_11 LM741 Operational Amplifier

uA741D SO08 linear

IC_12 LM741 Operational Amplifier

uA741D SO08 linear

IC_13 LM741 Operational uA741D SO08 linear

46

Page 47: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

Amplifier IC_14 LM741 Operational

Amplifier uA741D SO08 linear

IC_15 Bluetooth Module WML-C10 Mitsumi Board++ IC_16 LM317 – Regulator 317T TO220H linear IC_17 LM2575 – Regulator LM2575T-5.0 5-LEADTO-220 national IC_18 7806 - Regulator 7806H T039 linear

C1 0.1uF C0805 0805 IAS-Webboard C2 1uF C0805 0805 IAS-Webboard C3 330uF CPOL-EUE5-10.5 E5-10,5 Rcl C4 100uF CPOL-EUE.2.5-6 E2,5-6 Rcl C5 100uF CPOL-EUE2,5-6E E2,5-6E Rcl C6 100nF C0805 0805 IAS-Webboard C7 100nF C0805 0805 IAS-Webboard L1 330uH PE-52627 LOWPROFILE Pulse L2 22uH Inductor Inductor IAS-Webboard D1 1N5819 BYV10 DO41-10 Diode D2 1N5819 BYV10 DO41-10 Diode X1 Pin Header MA-17-2 MA17-2 IAS-Webboadr X2 Pin Header MA16-2 MA16-2 IAS-Webboard X3 Pin Header MA15-2 MA15-2 IAS-Webboard X4 Pin Header MA12-2 MA12-2 IAS-Webboadr

47

Page 48: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

8 Installing the MicroC/OS-II

The MicroC/OS-II is a completely portable, ROMable, scalable, preemptive, real-time, multitasking kernel. MicroC/OS-II is written in ANSI C and contains a small portion of assembly language code to adapt it to different architecture processor. Therefore, the installation of the MicroC/OS-II in the microcontroller M16C under the TASKING IDE requires that a couple of steps must be followed.

This section is concerned with the installation of MicroC/OS-II and its port, taking into account the installation process, constraints, compiler, debugger and so on. Sometimes we refer in the text Real-Time Kernel instead of MicroC/OS-II but both terms have the same meaning.

8.1 Requirements to the Installation

For the operation of the system we used the operating system Microsoft Windows NT, Version 4.00.1381 installed on the PC desktop. TASKING Embedded Development Environment (EDE) for the M16C v2.2r2 was used to develop the application that is running on the microcontroller. The MicroC/OS-II v2.52 was used with the port of the version 2.0.4.30 for the M16C made by Jan Homuth.

8.2 Companion CD

The MicroC/OS-II v2.52comes with the book [Labr04]. The following steps must be carried out in order to install the Real-Time Kernel: 1. Insert the CD that comes with the book in your drive and then select the file

uCOSV252.exe. 2. The figure 8.1 shows the window, which will appear when we execute this file. 3. Thereafter, you will select an installation directory. 4. After the completion of the installation process, you can execute the examples that are

available on the CD as well as use the files that execute the functionality of the Real-Time Kernel in our application.

Figure 8.1: MicroC/OS-II Installation

48

Page 49: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

8.3 Installing the MicroC/OS Port

There is already a porting to the M16C under the TASKING IDE and can be downloaded over the website [uCOS04]. Unfortunately, there is incompatibility between the versions in which the MicroC/OS-II was ported to the current that we have used in our project. In order to overcome this problem, you have to make a couple of changes in the code provided for the TASKING IDE. The following steps must be carried out in order to put the Real-Time Kernel in operation: 1. Copying the Files

You have to download the port over the website [uCOS04]. Thereafter, unzipped the file M16C-Tasking-uCOS-II-V204.zip.in a directory different from the uCOS-II v2.54. Therefore, copy the files from the source directory of the uCOS-II v2.52 to the source directory of the uCOS-II v2.04. Thereby, the structure of the directory must looks like the figure 8.2.

Figure 8.2: The directory structure

2. OS_CFG.H

You will have to copy the file OS_CFG.H from the CD that accompanies the book and paste it into the directory software\ucos-ii\m16c\tasking\test\LEDBlink. Moreover, you have to select the appropriate features that you need in your application. Change the value of the variable OS_LOWEST_PRIO to 63, this means that the lowest priority (the higher the number, the lower the priority) in the application. The MicroC/OS is able to create up to 63 tasks. 3. OS_CPU_C.C

You have to add an empty function OSTaskIdleHook. You can write anything that you want in this function, e.g., you can use to stop the CPU with the purpose to save energy

49

Page 50: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

because this function is in only called inside the OS_TaskIdle when there is no task in the state running. void OSTaskIdleHook(void)

4. OS_CPU.H

There is no change in this file. 5. uCOS_II.C

You need to change the location of the files, which are responsible for running the MicroC/OS-II. These files come with the CD and should be in the past \software\ucos-ii\source.

50

Page 51: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

Appendix A – Index of Figures FIGURE 1.1: POWER PHASE AND READ PHASE ......................................................................................... 4 FIGURE 1.2: TOUCH SENSOR INTERFACE ................................................................................................. 5 FIGURE 1.3: TOUCH SENSOR SCHEMATIC ................................................................................................ 6 FIGURE 1.4: DFD OF THE TOUCH SENSOR ............................................................................................... 6 FIGURE 1.5: LIGHT SENSOR INTERFACE .................................................................................................. 7 FIGURE 1.6: LIGHT SENSOR SCHEMATIC [HURB03] ................................................................................ 8 FIGURE 1.7: LIGHT SENSOR BEHAVIOUR [HURB03] ................................................................................ 9 FIGURE 1.8: ROTATION SENSOR INTERFACE............................................................................................ 9 FIGURE 1.9: VOLTAGE SEQUENCE [MIND03] ........................................................................................ 10 FIGURE 1.10: READ PHASE OF THE ROTATION SENSOR ......................................................................... 10 FIGURE 1.11: ROTATION SENSOR DIRECTION........................................................................................ 11 FIGURE 1.12: TRANSITION BETWEEN STEP 4 AND 2 .............................................................................. 11 FIGURE 1.13: ROTATION SENSOR SCHEMATIC [HURB03]...................................................................... 12 FIGURE 1.14: DFD OF THE ROTATION SENSOR– PART I........................................................................ 14 FIGURE 1.15: DFD OF THE ROTATION SENSOR– PART II ...................................................................... 15 FIGURE 2.1: ULTRASONIC RANGE SENSOR ............................................................................................ 16 FIGURE 2.2: INFRARED PROXIMITY SENSOR.......................................................................................... 17 FIGURE 2.3: PRESSURE SENSOR............................................................................................................. 18 FIGURE 2.4: MAGNETIC COMPASS SENSOR............................................................................................ 18 FIGURE 3.1: LCD POWER SUPPLY ......................................................................................................... 20 FIGURE 4.1: THE LEGO TECHNIC MOTORS ....................................................................................... 23 FIGURE 4.2: LEGO MOTOR INTERFACE................................................................................................. 25 FIGURE 4.3: DEPICT TWO PULSE WIDTH MODULATED SIGNALS ............................................................ 26 FIGURE 4.4: DFD OF THE MOTOR .......................................................................................................... 27 FIGURE 5.1: SINGLE-CHIP CMOS.......................................................................................................... 29 FIGURE 5.2: THE BLUETOOTH PROTOCOL STACK.................................................................................. 30 FIGURE 5.3: POINT TO POINT, PICONET AND SCATTERNET [BLUE01]................................................... 31 FIGURE 5.4: FREQUENCY HOPPING, MASTER AND SLAVE INTERACT ON CORRESPONDING SLOTS ....... 32 FIGURE 5.5: FUNCTIONAL STATE DIAGRAM [KARD00] ........................................................................ 33 FIGURA 5.6: BLUETOOTH POWER CONSUMPTION.................................................................................. 36 FIGURE 5.7: BT MODULE INTERFACE.................................................................................................... 37 FIGURE 7.1: BOARD++ SCHEMATIC ...................................................................................................... 43 FIGURE 7.2: THE BOARD++ LAYOUT..................................................................................................... 44 FIGURE 8.1: MICROC/OS-II INSTALLATION.......................................................................................... 48 FIGURE 8.2: THE DIRECTORY STRUCTURE............................................................................................. 49

51

Page 52: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

Appendix B – Index of Tables TABLE 1.1: INPUT RANGE VALUES .......................................................................................................... 5 TABLE 1.2: ROTATION SENSOR VOLTAGE LEVELS ................................................................................ 10 TABLE 1.3: ROTATION SENSOR CIRCUIT OUTPUT .................................................................................. 12 TABLE 3.1: LCD DISPLAY WIRING ....................................................................................................... 19 TABLE 3.2: LCD INSTRUCTIONS ........................................................................................................... 21 TABLE 4.1: PROPERTIES OF THE LEGO TECHNIC MOTORS ............................................................... 24 TABLE 5.1: M3A-ZA12 SPECIFICATION ............................................................................................... 36 TABLE 5.2: M3A-ZA12 PINS ................................................................................................................ 37 TABLE 5.3: PINNING OF BOARD INTERNAL INTERFACE AND DIRECTION............................................... 38 TABLE 7.1: PINS DESCRIPTION FOR THE SENSORS AND ACTUATORS..................................................... 45 TABLE 7.2: COMPONENT LIST ............................................................................................................... 45

52

Page 53: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

Appendix C – Index of Equations EQUATION 4.1: ON-TIME PULSE ................................................................................................ 25 EQUATION 4.2: OFF-TIME PULSE ............................................................................................... 25 EQUATION 5.1: FREQUENCY OF THE CHANNELS ........................................................................ 32 EQUATION 7.1: ADAPTATION FORMULA ................................................................................... 44

53

Page 54: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

Appendix D – Abbreviations

ADC Analog-Digital Converter

AI Analog Input

AO Analog Output

BT Bluetooth

CTP Cordless Telephony Profile

DFD Data Flow Diagram

DI Digital Input

DNP Dial-up Networking Profile

DO Digital Output

FP Fax Profile

FTP File Transfer Profile

GAP Generic Access Profile

GOEP Generic Object Exchange Profile

HP Headset Profile

IP Intercom Profile

LAP LAN Access Profile

NOC Normally Open Contact

54

Page 55: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

OPP Object Push Profile

OS Operating System

RCX Robotic Command Explorer

RPM Revolutions Per Minute

SDAP Service Discovery Application Profile

SP Synchronization Profile

SPP Serial Port Profile

MicroC/OS-II Micro-Controller Operating System, Version 2.

55

Page 56: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

Appendix E – Terminology

Light Sensor The light sensor is responsible for measuring the amount of brightness in the environment. This sensor has two modes. The first one is the raw mode and the second one is the percentage mode.

Touch Sensor The touch sensor only indicates the presence of an obstacle. The sensor has only two states: pressed and released. When the sensor is released, there is about +5 [V] in the terminals of the sensor and when the sensor is pressed the voltage decrease to 0 [V].

Rotation Sensor The rotation sensor is responsible for measuring the amount of revolution in a given time interval. This sensor has 16 steps and each step has 22.5°.

Temperature Sensor

The temperature sensor is responsible for measuring the presence of heat in a given environment in degrees [°C]. This sensor works within the range of -20C to +70C.

Ultrasonic Range Sensor

The ultrasonic range sensor is responsible for measuring the distance from an object or obstruction. This sensor has a range from 6 inches to 56 inches (15.2 [cm] - 142.2 [cm]).

Infrared Proximity Sensor

The infrared proximity sensor is responsible for sending short pulses of relatively bright infrared light and measures the amount of reflected light.

Pressure Sensor The pressure sensor is responsible for measuring the pressure relative to current atmospheric pressure. This sensor is scaled to read 2

1

[PSI] per light sensor unit.

Magnetic Compass Sensor

The magnetic compass sensor is responsible for measuring the two components of the Earth’s magnetic field and calculates a heading as output.

Motor The motor is responsible for moving around, lift loads, operate arms, grab objects, pump air, and perform any other task that requires power. The motor works with about 9 [V] applies in its terminal and runs at about 350 [rpm]

56

Page 57: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

IAS WebBoard The IAS WebBoard is a versatile microcontroller board featuring a complete Ethernet 10Base-T network interface with 10Mbps. It is based on the powerful 16-bit Renesas M16C microcontroller architecture. M16C microcontroller can be clocked with up to 24MHz and include up to 384 KB flash and 31 KB RAM memory.

RCX The RCX is a Hitachi H8 microcontroller with 32K of external RAM. The microcontroller is used to control three motors, three sensors, and an infrared serial communications port. The RCX has a piezoelectric speaker, which produces 6 distinct tones. Using infrared communication the RCX can communicate with a computer, sending messages back and forth and communicate with other RCX bricks.

MicroC/OS-II The MicroC/OS-II is a completely portable, ROMable, scalable, preemptive, real-time, multitasking kernel. MicroC/OS-II is written in ANSI C and contains a small portion of assembly language code to adapt it to different architecture processor

57

Page 58: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

Appendix F – Literature

[Kard00] Kardach J (2000). Windows Wireless Scenarios and Strategies: Bluetooth Architecture Overview, WinHEC Technical Session.

[Elli02] Elliot J., Witherspoon T. L., Ferrari M (2002). 10 Cool LEGO Mindstorms Robotics Invention System 2 Projects: Amazing Projects You Can Build in Under OneHhour. Syngress Publishing.

[Mind03] Mindstorms RCX Sensors Input, [On-Line]. Available at http://www.plazaearth.com/usr/gasperi/lego.htm [21st December 2003].

[Phil03] Phillips Semiconductor, [On-Line]. Available at http://www.phillipssemiconductors.com [21st December 2003].

[Hurb03] Hurban P. LEGO Mindstorms Compatible Devices, [On-Line]. Available at http://www.philohome.com/sensors/legorot.htm [21st December 2003].

[Garr81] Garret P. H (1981). Analog I/O Design: Acquisition, Conversion and Recovery. Prentice Hall, Virginia.

[Garr88] Carr J.J (1988). Data Acquisition and Control: ;Microcomputer Applications for Scientists and Engineers. TAB Professional and Reference Books, USA.

[Cord03] Cordeiro L.C (2003). Developing real-time applications with LEGO Mindstorms. IAS, Stuttgart.

[Dean03] Dean T. Ultrasonic Range Sensor, [On-Line]. Available at http://www.cs.brown.edu/people/tld/courses/cs148/02/sonar.html [26th December 2003].

[Deit01] Deitel H.M, Deitel P. J (2001). C++ Como Programar. Bookman.

[Hite01] HiTechnic Products and Accessories, [On-Line] Available at http://www.hitechnic.com/products.htm [3rd January 2004].

[uCOS] Micriµm Empowering Embedded Systems, [On-Line] Available at www.ucos-ii.com [20th February 2004].

58

Page 59: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

[Labr02] Labrosse J. J. (2002), MicroC/OS-II The Real-Time Kernel. Second Edition, CMP Books, California.

Manuals

[Blue01] Bluetooth Specification (2001). General Description, Version 1.1.

[Info01] InfoTooth (2001). Bluetooth Tutorial – Specifications.

[Eric00] Ericsson Bluetooth (2000). Beginners Guide.

[Phys01] Bluetooth Specification (2001). Physical Channel, Version 1.1.

[Bmp03] BlueMP3 reference design for MP3 streaming over Bluetooth (2003), Application Note.

[Hand03] BlueFree reference design for Hands-Free application (2003). Application Note.

[Mits03] Mitsubishi Microcomputers. M16C/62A Group Datasheet.

59

Page 60: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

Appendix G – Header and Source Code /**************************************************************************

* File: Touch.h

* Abstract: The touch sensor interface

* Platform Renesas M16C

* Project LEGO Board

* Copyright (C) 2003 IAS, University of Stuttgart

**************************************************************************/

#ifndef _TOUCH_H

/****************************** Constants ********************************/

#define PRESSED 1

#define RELEASED 0

/*************************** Function Prototype **************************/

bool TouchSensor(void);

#endif /* _TOUCH_H */

60

Page 61: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

/**************************************************************************

* File: Touch.c

* Abstract: The touch sensor interface

* Platform Renesas M16C

* Project LEGO Board

* Copyright (C) 2003 IAS, University of Stuttgart

**************************************************************************/

/**************************************************************************

* Function: Verify the state of the touch sensor

* Return value: Bool

*

* Comments:

* - Verify the state of the touch sensor. If the AD input is greater than *2[V] then the sensor is released, otherwise the sensor has been *pressed.

**************************************************************************/

bool TouchSensor(void)

bool State; /* Indicates the state of the touch sensor */

PD10_4 = 0; /* initialise the direction registers and values of port P10_4 */

ADCON0 = 0x84; /* AN4 is selected and fAD/2 */

ADCON1 = 0x20; /* A-D registers for 8-bits, one-shot mode, Vref connected */

ADCON2 = 0x01; /* A-D conversion method with sample and hold */

ADST = 1;

while (ADST==0);

TempStore = AD4 & 0x00FF;

ADST = 1;

if (TempStore > 0x60)

State = RELEASED; /* The touch sensor has been released */

else

State = PRESSED; /* The touch sensor has been pressed */

return State;

61

Page 62: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

/*************************************************************************

* File: Rotation.h

* Abstract: The rotation sensor interface

* Platform Renesas M16C

* Project LEGO Board

* Copyright (C) 2003 IAS, University of Stuttgart

**************************************************************************/

#ifndef _ROTATION_H

/***************************** Constants *********************************/

#define ONE_HUNDERD_US_BY_COUNTER_LOOP 0x0000004C

#define Step1 1

#define Step2 2

#define Step3 3

#define Step4 4

/**************************** Functions Prototype ************************/

void Delay(unsigned long dwMilliSeconds);

int RotationSensor(void);

#endif /* _ROTATION_H */

62

Page 63: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

/*************************************************************************

* File: Rotation.c

* Abstract: The rotation sensor interface

* Platform Renesas M16C

* Project LEGO Board

* Copyright (C) 2003 IAS, University of Stuttgart

**************************************************************************/

/*************************************************************************

* Procedure: Delay execution for a given number of mili-seconds

* Return value: None

*

* Comments:

* - The rotation sensor will have a period of 3ms. During 2.9ms the

* sensor is powered and during 0.1ms the analog value is read. This

* procedure determine the amount of time that the sensor will be

* powered.

**************************************************************************/

void Delay(unsigned long dwMilliSeconds)

unsigned long i;

/* Wait for specified number of milli-seconds */

while (dwMilliSeconds--)

for (i=0; i<ONE_HUNDERD_US_BY_COUNTER_LOOP; i++) ;

/*************************************************************************

* Function: Measure the amount of steps in a given interval.

* Return value: int

*

* Comments:

* - The Rotation Sensor function returns the numbers of transitions

* from one step to another. It carries out 100 cycles, namely one

* hundred power phase and reading phase.

**************************************************************************/

int RotationSensor(void)

int Step=0,Previous_Step=0, Current_Step=0, TempStore=0, Counter;

63

Page 64: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

for (Counter=0;Counter<100;Counter++)

P10_1 = 1; /* P10_1 is used as digital output enabling

the power phase */

LedDelay(34); /* Power phase last approximately 2.9 ms */

P10_1 = 0; /* End of the power phase */

LedDelay(2); /* Waits 0,1 for the discharge of the internal

capacitor */

ADST = 1; /* Starts A-D conversion */

while (ADST==1);

TempStore = AD5 & 0x00FF;

/* First Step 1.8V , Between 1.5(0x51) and 2.1(0x66) */

if ((TempStore >= 0x51)&&(TempStore <= 0x66))

Previous_Step = Current_Step;

Current_Step = Step1;

if (Previous_Step == Step2)

Step++; /* Direction is Clockwise and the rotation

sensor step is set */

else if (Previous_Step == Step3)

Step--; /* Direction is Counter Clockwise and the

rotation sensor step is set */

/* Second Step 2.6V , Between 2.4(0x7A) and 2.8(0x8E) */

else if ((TempStore > 0x7A) && (TempStore <= 0x8E))

Previous_Step = Current_Step;

Current_Step = Step2;

if (Previous_Step == Step4)

Step++; /* Direction is Clockwise and the rotation

sensor step is set */

else if (Previous_Step == Step1)

Step--; /* Direction is Counter Clockwise and the

rotation sensor step is set */

64

Page 65: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

/* Third Step 4.1V , Between 3.9(0xC6) and 4.3(0xDB) */

else if ((TempStore > 0xC6) && (TempStore <= 0xDB))

Previous_Step = Current_Step;

Current_Step = Step3;

if (Previous_Step == Step1)

Step++; /* Direction is Clockwise and the rotation

sensor step is set */

else if (Previous_Step == Step4)

Step--; /* Direction is Counter Clockwise and the

rotation sensor step is set */

/* Fouth Step 4.8V , Between 4.6(0xEA) and 5.0(0xFF) */

else if (TempStore > 0xEA && TempStore <= 0xFF)

Previous_Step = Current_Step;

Current_Step = Step4;

if (Previous_Step == Step3)

Step++; /* Direction is Clockwise and the rotation

sensor step is set */

else if (Previous_Step == Step2)

Step--; /* Direction is Counter Clockwise and the

rotation sensor step is set */

return Step; /* Number of Transitions among all Steps */

65

Page 66: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

/**************************************************************************

* File: Motor.h

* Abstract: Interface of the DC Motors

* Platform: Renesas M16C

* Project LEGO Board

* Copyright (C)2003 IAS, University of Stuttgart

**************************************************************************/

#ifndef _MOTOR_H

#define _MOTOR_H

//Minimum Motor Speed

#define MIN_SPEED 0

//Maximum Motor Speed

#define MAX_SPEED 100

//Motor States

#define off 0

#define fwd 1

#define rev 2

/*********************** Public function prototypes **********************/

void pwm(int TotalTime, int Speed, bool Enable,

int Direction, double angle);

#endif /* _MOTOR_H */

66

Page 67: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

/*************************************************************************

* File: Motor.c

* Abstract: Set the LEGO motor speed according to the PWM signal

* Platform Renesas M16C

* Project LEGO Board

* Copyright (C) 2003 IAS, University of Stuttgart

**************************************************************************/

// Includes

#include "Board.h"

#include "Motor.h"

#include <math.h>

/********************** Private function prototypes **********************/

/**************************************************************************

* Function: Calculate the time that the signal is set to 1

* Return value: Float

*

* Comments:

* - Calculate the time in which the sinal of the motor remains in high

**************************************************************************/

static float OnTime_Pulse(int TotalTime, float DutyCycle);

/**************************************************************************

* Function: Calculate the time that the signal is set to 0

* Return value: Float

*

* Comments:

* - Calculate the time in which the sinal of the motor remains in low

**************************************************************************/

static float OffTime_Pulse(int TotalTime);

/**************************************************************************

* Function: Simple delay function using large double loop.

* Return value: Float

*

* Comments:

* - The motor must remain a certain amount of time in high and low. To this purpose,

* a simple delay function is used as a large double loop.

**************************************************************************/

67

Page 68: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

static void Sleep( int delay )

/************************ Private function definitions *******************/

/**************************************************************************

*Calculate the time that the signal is set to 1

**************************************************************************/

static float OnTime_Pulse(int TotalTime, float DutyCycle)

float OnTime;

OnTime = (float)(TotalTime * DutyCycle / 100); /* Calculate the Time in which the signal will remain in off */

return OnTime;

/**************************************************************************

*Calculate the time that the signal is set to 0

**************************************************************************/

static float OffTime_Pulse(int TotalTime)

float OffTime;

OffTime = (float)(TotalTime - OnTime); /* Calculate the Time in which the signal will remain in off */

return OffTime;

/**************************************************************************

* Simple delay function using large double loop

**************************************************************************/

static void Sleep( int delay )

long i, j; /* Run-time variables */

for ( i=0; i<(long)delay; i++ )

for ( j = 0; j<1000; j++ )

_nop();

68

Page 69: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

/**************************************************************************

* Procedure: The implementation of the pwm signals

* Return value: none

*

* Comments:

* - Calculate the amount of time in which the sinal of the motor remains in high and low.

**************************************************************************/

void pwm(int TotalTime, int Speed, bool Enable, int Direction, double angle)

OnTime_Pulse(TotalTime, Speed); /* Caculate the OnTime period based on the Total Time and DutyCycle */

OffTime_Pulse(TotalTime); /* Caculate the OffTime period based on the Total Time and OnTime */

P10_0 = Enable; /* Enable the motor driver L293D */

if (Direction == fwd) /*Turn on the motor to the positive dir */

P10_1 = 1;

P10_3 = 0;

else if (Direction == rev) /*Turn on the motor to the negative dir*/

P10_1 = 0;

P10_3 = 1;

Sleep(OnTime); /* The motor will keep going run until the Ontime expire */

P10_1 = 0; /* Turn Off the motor */

P10_3 = 0;

Sleep(OffTime); /* The motor will keep going stopped until the Offtime expire */

69

Page 70: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

/**************************************************************************

* File: LCD.h

* Abstract: Interface of the LCD

* Platform: Renesas M16C

* Project LEGO Board

* Copyright (C)2003 IAS, University of Stuttgart

**************************************************************************/

#ifndef _LCD_H

/**************************************************************************

* Declare LCD connections

**************************************************************************/

#define rw P8_2 /* LCD read/write pin */

#define rs P8_1 /* LCD register select */

#define lcd_enable P8_3 /* LCD enable pin */

#define lcd_out P7 /* LCD data output */

/************************ Declare LCD Instructions ***********************/

#define clr_dsp 0x01 /* Clear Display */

#define return_home 0x02 /* Return Home */

#define scr_entry 0x05 /* Scroll entry mode */

#define inc_entry 0x06 /* increment entry mode */

#define disp_on 0x0C /* Display on, Cursor off, Blink cursor off */

#define disp_c_on 0x0E /* Display on, Cursor on */

#define disp_b_on 0x0F /* Display on, Cursor on, Blink cursor */

#define disp_off 0x08 /* Display off */

#define disp_mode 0x38 /* 8 bit, 2 line, 5x8 mode */

#define scr_entry_inc 0x07 /* scroll entry, increment mode */

#define DD_RAM_AD1 0x80 /* Line 1 home */

#define DD_RAM_AD2 0xC0 /* Line 2 home */

#define DD_RAM_AD3 0x8F /* End of line 1 */

#define DD_RAM_AD4 0xCF /* End of line 2 */

/*************************** Functions Prototype ************************/

void delay_1ms();

void LCD_int();

void SendCmd(unsigned char);

void SendChar(unsigned char);

void clrLCD();

void L1homeLCD();

void L2homeLCD();

void L1endLCD();

70

Page 71: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

void L2endLCD();

void LCDinc();

void LCDscr();

void LCDscr_inc();

void LCD_write (_far char *, int);

void LCD_scroll (_far char *, int);

#endif /* _LCD_H */

71

Page 72: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

/*************************************************************************

* File: LCD.c

* Abstract: Interface of the LCD

* Platform: Renesas M16C

* Project LEGO Board

* Copyright (C)2003 IAS, University of Stuttgart

**************************************************************************/

#include "LCD.h"

/**************************************************************************

* Procedure: Creates 1ms delay

* Return value: none

*

* Comments:

* - This procedure creates 1ms delay with the puporse to

* obtain a synchronization of the LCD. A certain amount

* of time between the operations is required.

**************************************************************************/

void delay_1ms()

ta3ic = 0x00; /* make sure that the

interrupt is not active */

ta3mr = 0x42; /* set for one shot

timer mode */

ta3 = 0x0800; /* 1 mS time delay */

ta3s = 1; /* get ready */

ta3os = 1; /* start it here */

while (ir_ta3ic != 1); /*wait for timer to run out*/

ta3s = 0; /* stop the timer */

/*************************************************************************

* Procedure: LCD Initialization

* Return value: none

*

* Comments:

* - Before using the LCD, it must be initialize to enable

* the operations like writing, reading, and so on.

**************************************************************************/

void LCD_init (void)

72

Page 73: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

unsigned short i;

for (i=50; i>0; i--)

delay_1ms(); /* Startup delay 50mS */

SendCmd(disp_mode); /* 8 bit, 2 line, 5x8 mode */

SendCmd(disp_b_on); /* Display on, Cursor on,

Blink cursor */

SendCmd(clr_dsp); /* Clear display */

delay_1ms(); /* additional delay (min. 1.53ms) */

SendCmd(inc_entry); /* increment mode */

/*************************************************************************

* Procedure: Sends a character to the LCD

* Return value: none

*

* Comments:

* - This procedure sends a character to the LCD as a

* parameter.

**************************************************************************/

void SendChar (unsigned char lcd_data)

rs = 1; /* Set for data */

rw = 0; /* write data */

lcd_enable = 1; /* Clock data into LCD */

lcd_out = lcd_data; /* put data on Port 0 */

lcd_enable = 0; /* Latch data */

delay_1ms();

/*************************************************************************

* Procedure: Sends command to the LCD

* Return value: none

*

* Comments:

* - This procedure clear the previous command in the LCD

* and write a data over the Port 0.

**************************************************************************/

void SendCmd (unsigned char lcd_data)

73

Page 74: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

rs = 0; /* clear for command */

rw = 0; /* clear for command */

lcd_enable = 1; /* Clock data into LCD */

lcd_out = lcd_data; /* put data on Port 0 */

lcd_enable = 0; /* Latch data */

delay_1ms();

/*************************************************************************

* Procedure: Clear the Contents of the LCD

* Return value: none

*

* Comments:

* - This procedure clear the previous contents of the LCD

**************************************************************************/

void clrLCD ()

SendCmd(clr_dsp); /* clear display */

delay_1ms();

delay_1ms();

/*************************************************************************

* Procedure: Move cursor

* Return value: none

*

* Comments:

* - Moves the cursor to home position on line 1

**************************************************************************/

void L1homeLCD ()

SendCmd(DD_RAM_AD1); /* home position on line 1 */

delay_1ms();

/*************************************************************************

* Procedure: Move cursor

* Return value: none

*

* Comments:

* - Moves the cursor to home position on line 2

**************************************************************************/

74

Page 75: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

void L2homeLCD ()

SendCmd(DD_RAM_AD2); /* home position on line 2 */

delay_1ms();

/*************************************************************************

* Procedure: Move cursor

* Return value: none

*

* Comments:

* - Moves the cursor to the end of line 1

**************************************************************************/

void L1endLCD ()

SendCmd(DD_RAM_AD3); /* last address of line 1 */

delay_1ms();

/*************************************************************************

* Procedure: Move cursor

* Return value: none

*

* Comments:

* - Moves the cursor to the end of line 2

**************************************************************************/

void L2endLCD ()

SendCmd(DD_RAM_AD4); /* last address of line 2 */

delay_1ms();

/*************************************************************************

* Procedure: LCD entry

* Return value: none

*

* Comments:

* - Puts the LCD in normal increment entry mode

**************************************************************************/

void LCDinc ()

SendCmd(inc_entry); /* set entry mode, increment on*/

75

Page 76: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

delay_1ms();

/*************************************************************************

* Procedure: LCD scroll

* Return value: none

*

* Comments:

* - Puts the LCD in scroll entry mode

**************************************************************************/

void LCDscr ()

SendCmd(scr_entry);

delay_1ms();

/**************************************************************************

* Procedure: LCD scroll increment

* Return value: none

*

* Comments:

* - Puts the LCD in scroll increment entry mode

**************************************************************************/

void LCDscr_inc()

SendCmd(scr_entry_inc);

delay_1ms();

/*************************************************************************

* Procedure: LCD write

* Return value: none

*

* Comments:

* - This routine outputs some text to the LCD display

**************************************************************************/

void LCD_write ( _far char * msg_string, int line )

int i;

if (line == 1)

L1homeLCD(); /* home display on line 1 */

76

Page 77: In this section a short description about how to interface ...ufam-automation.net/lucascordeiro/images/reports/Board_v12.pdf · Document Version Management Version Authors QA Date

else

L2homeLCD(); /* home display on line 2 */

for (i=0; msg_string[i]; i++) /* This loop reads

in the text string*/

SendChar(msg_string[i]);

/*************************************************************************

* Procedure: LCD scroll

* Return value: none

*

* Comments:

* - This routine scrolls text on the LCD display

**************************************************************************/

void LCD_scroll ( _far char * msg_string, int line )

int i, j;

SendCmd(disp_on); /* cursor off, blink off */

if (line == 1)

L1endLCD(); /* start at end of line 1 */

else

L2endLCD(); /* start at end of line 2 */

for (i=0; msg_string[i]; i++) /* This loop reads

in the text string */

SendChar(msg_string[i]);

for (j=200; j>0; j--)

delay_1ms(); /* scroll delay 200 ms */

77