Issuu on Google+

ITI-Embedded Systems Department Exercise on Introduction to Embedded Systems

EMBEDDED SYSTEMS

ITANK


iTank Software Design

2

Introduction to Embedded Systems

Index: 1. Introduction 1.1 1.2 1.3

System Context Diagram Data Flow Diagram State Machine

2. System Constraints 2.1 2.2

Memory Constraint

2.1.2 NVRAM implementation

PWM generation

2.2.1 Simple Timer

3. Dynamic Design 3.1 3.2

Task Description

3.1.1 3.1.2 3.1.3

Initialization Task Cyclic Tasks Event Based Tasks

Table of tasks

4. Timing Diagram 5. Static Design 5.1 5.2 5.3

Application Layer (service layer) ECUAL MCAL

6. Sequence Diagram


iTank Software Design

3

Introduction to Embedded Systems

1.Introduction The purpose of this document is to design a software of Demo iTank that basically tracks a black line If two black tracks are detected in the iTank path the iTank has to stop and wait for an external action to guide the iTank direction.The iTank shall detect the objects that obstacle its path and stops if the obstacle is detected and move again once it is removed If the iTank have two possible paths if one of them has an obstacle it shall go to the another path. The iTank shall detect the obstacle starting from distance 2 meter through four front sensors and detect if the obstacle is fixed or moving. The iTank shall decrease its speed untill stops every time it becomes nearer to the obstacle.

1.1 System Context Diagram:

1.2 Data Flow Diagram:


iTank Software Design

4

Introduction to Embedded Systems

1.3 State Machine:


iTank Software Design

5

Introduction to Embedded Systems

2. System Constraints In our design we implemented some techniques in order to utilize the hardware resources available and meet the system requirements within the constraints introduced. In this section we introduce these constraints along with the techniques used to overcome them.

2.1 Memory Constraints

We faced a problem of limited resources and that was the case of the EEPROM (being only 8KBytes) and a simple calculation would show that in order to save all sensor readings within 5 minutes, more specifically 4 bytes every 1msec for the ultrasonic sensors and 1 byte for the color and floor sensors every 5msec, would require 1260 kBytes of memory which dramatically exceeds the 8 Kbytes EEPROM size. To overcome this constraint we are saving the sensors readings in significant actions only (by significant actions we mean: increasing speed, decreasing speed, moving left or right or stopping) assuming that the iTank’s normal condition is a no-obstacle track (clean track). U

U

2.1.2 NVRAM implementation

The sensors readings are stored in the RAM (RAM mirror) in order to be written to the EEPROM later, so after the iTank enters the automatic mode the iTank would repeat the first five minutes in the tracking mode. In order to repeat the exact same track done by the iTank, a Time ID is associated to each of the time readings to track the state of the system and start repeating it in case that it didn’t change. The Time ID is simply a static variable counter that is acting as a clock, incrementing while the system is on. U

U

2.2 PWM generation

Controlling the motor speed was done through manipulating the PWM applied to each of the DC motors, in our system one simple timer was available, and we had to utilize it in order to generate the PWM needed.

2.2.1 Simple Timer

The simple timer gives an interrupt when the comparison value is reached. A simple example shows how we applied the desired PWM on both motors through the simple timer.


iTank Software Design

6

Introduction to Embedded Systems

3. Dynamic Design In this section we give a brief description to the dynamic design tasks and we list the table of the tasks.

3.1 Task Description

3.1.1 Initialization tasks: This task is an initialization task that is run as the system starts and is considered a critical section and is responsible for: 1- Configuring PortA as an output port for the motor drivers communication(PWM leftMotor, PWM rightMotor, Forward_Dir_CTRL_rMotor,Reverse_Dir_CTRL_rMotor, Forward_Dir_CTRL_lMotor,Reverse_Dir_CTRL_lMotor) 2- Configure PortB as an input port for the (LFS,RFS,LCS,MCS,RCS) 3- Load ECT with 1msec value 4- Intialize SPI module 5- Intialize EEPROM (exec 0.1 msec apx) 3.1.2 Cyclic Tasks: ControlDS_1msec: Based on the 1msec interrupt This function shall: 1- read from the SPI the data read by the ASIC chip , through calling ReadSPI function that is responsible for the SPI read and that takes approximately 0.32msec . 2- Afterwards the function checks for the ultrasonic sensors readings and set an event for one of two functions: IS_E for IncreaseSpeed command and DS_E for DecreaseSpeed command when their conditions hold. 3- Increment a counter that shall generate an interrupt every 5msec 4- Increment a counter that shall generate an interrupt every 22msec (exec 0.4 msec apx) ControlCFS_5msec: Based on the interrupt after 5msec This function shall: 1- read the color and floor sensors (5 bytes), through calling ReadCFS function that is responsible for that. 2- Afterwards the function checks for the color and floor sensors readings and set an event for one of two functions: MR_E for MoveRight command or ML_E for MoveLeft command or SP_E for StopMotor command


iTank Software Design

7

Introduction to Embedded Systems

3- Else it would move to the automatic mode and repeat the track and that’s through setting A_E for RepeatTrack command as long as any of their conditions hold. (exec: 0.2msec apx)

WEEPROM_22msec: Based on the interrupt after 22msec This function shall: 1- write to the EEPROM the readings stored in the RAM mirror. (exec: 50usec apx) 3.1.3 Event-Based Tasks:

IncreaseSpeed: This is an event based task that is activated upon setting the IS_E event to 1, and it’s responsible for 1- Increasing the speed of both of the motors in an incremental manner by writing in their timers the specific speed until 80% of the duty cycle is reached. 2- The function enables the timers interrupts and once it is called IncreaseSpeed starts copying the sensor readings along with the current time to a RAM mirror in order to be moved later to the EEPROM. (exec: 80usec apx)

DecreaseSpeed: This is an event based task that is activated upon setting the IS_E event to 1, and it’s responsible for 1- Decreasing the speed of both of the motors in an incremental manner by writing in their timers the specific speed until the duty cycle reduction reaches 20% is reached. 2- The function enables the timers interrupts and once it is called DecreaseSpeed starts copying the sensor readings along with the current time to a RAM mirror in order to be moved later to the EEPROM. (exec: 80usec apx)

StopMotor: This is an event based task that is activate in order to 1- send a stop command to the motor, through setting FORWARD_DIR_CRTL and REVERSE_DIR_CTRL to 0,0 respectively and it disables the timers interrupts. Once it is called StopMotor starts copying the sensor readings along with the current time to a RAM mirror in order to be moved later to the EEPROM. (exec: 80usec apx )

MoveLeft: This is an event based task that is activated upon setting the ML_E event to 1, and it’s responsible for decreasing the speed of the left motor and sustaining the current speed on the right and hence forcing the tank to move Left and this is done by:


8

iTank Software Design

Introduction to Embedded Systems

writing to their timers the specific speed . The function enables the timers interrupts and once it is called, MoveLeft starts copying the sensor readings along with the current time to a RAM mirror in order to be moved later to the EEPROM. (exec: 80usec apx) MoveRight This is an event based task that is activated upon setting the MR_E event to 1, and it’s responsible for decreasing the speed the left motor and sustaining the current speed on the right and hence forcing the tank to move right and this is done by writing to their timers the specific speed . The function enables the timers interrupts and once it is called, MoveRight starts copying the sensor readings along with the current time to a RAM mirror in order to be moved later to the EEPROM. (exec: 80usec apx)

REEPROM: This is an event based task that is activated upon setting the REEPROM_E to 1 in the RepeatTrack function in the automatic mode. The function is responsible for 1- reading from the EEPROM the data in sequence (The ultrasonic sensors, the color sensors, the floor sensors and the time ID) and then set these variables and set RDONE_F flag to 1 declaring the reading completion. RepeatTrack: Once the system is exposed to a white floor and the three color sensor detects that , the iTank is moved to the automatic mode where it is supposed to repeat the track it took for the first five minutes, this is done by the RepeatTrack function that is responsible for: • Reading from EEPROM and extracting the data (the sensors readings and the time ID) in sequence from it, through REEPROM function, in order to be passed next to the Repeat function that is responsible for interpreting these readings and carrying out the logic that would allow it to take the actions performed once in the tracking mode and also checks for how long they have been taking place using the time ID.


iTank Software Design

9

Introduction to Embedded Systems

3.2 Table of tasks

Task

3.2.1 Cyclic Tasks

Jitter

Period

Response Time

Max Delay

Priority

•120 usec

• 0 msec

•0

•init

•once

•controlDS_1msec

•1msec

• +0.48msec

• 1.48msec

•0.1msec

•1

•ControlCFS_5msec

•5msec

•+0.25msec

• 5.25 msec

•0.5 msec

•2

•WEEPROM_22msec

•22msec

•+0.6msec

• 22.6msec

•0.7msec

•3

3.2.2 Event Based Tasks

Task

Response Time

•IncreaseSpeed

•0.1 msec

•DecreaseSpeed

•0.1 msec

•StopMotor

•0.1 msec

•MoveLeft

•0.1 msec

•MoveRight

•0.1 msec

•RepeatTrack •REEPROM

3.2.3 Interrupts

•0.1msec

Interrupt

Exec. time

Max Delay

Priority

•Simple Timer

•10usec

•0 msec

•0

•Cyclic Timer

•5usec

•10usec

•1


iTank Software Design

10

Introduction to Embedded Systems

4. Timing Diagram:


iTank Software Design

11

Introduction to Embedded Systems

5. Static Design 5.1 Application layer (service layer)

This layer is responsible for managing the system’s drivers

5.2 ECUAL

This layer is responsible for the system’s external drivers


iTank Software Design

12

Introduction to Embedded Systems

5.3 MCAL

This layer is responsible for the system’s internal drivers


iTank Software Design

13

Introduction to Embedded Systems

6. Sequence Diagram


14

iTank Software Design

Introduction to Embedded Systems


15

iTank Software Design

Introduction to Embedded Systems


embeded