Homework 10: Software Design Considerations

Total Page:16

File Type:pdf, Size:1020Kb

Homework 10: Software Design Considerations

ECE 477 Digital Systems Senior Design Project Spring 2007

Homework 10: Software Design Considerations Due: Friday, February 9, at NOON

Team Code Name: Hazard Rover Group No. 10 Team Member Completing This Homework: Nuhairi Anuar e-mail Address of Team Member: [email protected]

NOTE: This is the last in a series of four “design component” homework assignments, each of which is to be completed by one team member. The completed homework will count for 20% of the individual component of the team member’s grade. The body of the report should be 3- 5 pages, not including this cover sheet, references, attachments or appendices.

Evaluation:

Component/Criterion Score Multiplier Points Introduction & Summary 0 1 2 3 4 5 6 7 8 9 10 X 1 Software Design Considerations 0 1 2 3 4 5 6 7 8 9 10 X 3 Software Design Narrative 0 1 2 3 4 5 6 7 8 9 10 X 3 List of References 0 1 2 3 4 5 6 7 8 9 10 X 1 Appendices 0 1 2 3 4 5 6 7 8 9 10 X 1 Technical Writing Style 0 1 2 3 4 5 6 7 8 9 10 X 1 TOTAL

Comments: ECE 477 Digital Systems Senior Design Project Spring 2007

1.0 Introduction The Hazard Rover is a remote-control vehicle with a 5-axes mechanical arm that is controlled by an operator through a wireless Ethernet interface. The vehicle is also attached with a wireless camera to help the user operating the vehicle. To increase the visibility of the surrounding view, Hazard Rover is equipped with LEDs and light sensors. Whenever the ambient light goes lower than the preset setting, the LEDs will be turned on. Hazard rover also has an HTTP server that will transmit and receive data wirelessly from a computer. Freescale’s 9S12NE64 is selected to be Hazard Rover’s processor mainly because it has an embedded web server. Through the web browser, an operator is able to control the movement of the vehicle, control the position of the arm, control the pan/tilt of the camera and view the surroundings of the vehicle. The web interface also displays battery status and the brightness of ambient light.

2.0 Software Design Considerations The chosen microprocessor, MC9S12NE64CPVE has 64KB of internal EEPROM flash, 8KB of internal SRAM, eight A/D converters, four PWM channels and one built-in Ethernet interface. Our design will use two PWM channels, 4 out of 8 A/D converters, 15 General Pin IO, the Ethernet interface and approximately 40KB of the Flash for the web server and all its accompanying libraries. 2.1 Memory Mapping: There are two types of memory, Flash and SRAM. Non-volatile Flash memory is used to store permanent program codes and data for our website. On the other hand, volatile SRAM memory will be used to store temporary data. The memory mapping of the MC9S12NE64 is as follows: [1] $0000-$03FF: Register space $0400-$1FFF: 7K RAM(1K RAM hidden) $2000-$3FFF: 8K Bytes SRAM $4000-$FFFF: Flash EEPROM This figure shows the memory map as suggested by Freescale Semiconductor:

-2- ECE 477 Digital Systems Senior Design Project Spring 2007

Figure 1: Memory Mapping [1] For our design, our code and web page will be stored at location $4000 to $FF00. On location $2000-$2FFF, static data, variables and heap are stored here. Stack will be stored at location $3000-$3FFF and the stack pointer will start at $3FFF. 2.1 External Interface Mapping The mapping of external interface is as follows: [2] Module Port Address Functions PWM PTT4 $0240(4) DC motor speed PTT5 $0240(5) Servo for wireless camera A/D (ATD) PAD2 $008F (2) Light sensor PAD4 $008F (4) Battery status PAD0 $008F (0) Front distance sensor PAD1 $008F (1) Rear distance sensor SCI SCI0 $00CC Reprogram the memory. EPHY EPHY $0120-$0123 Ethernet Interface and Network status LEDs GPIO PTS6 1- Headlight

-3- ECE 477 Digital Systems Senior Design Project Spring 2007

PTH 0-4, PJ0-1, 10 – Robotic arm DC motor PORTB0-2 PTH5, PTH6 2 – Vehicle steering PJ6, PJ7 2 – Vehicle forward/reverse

2.2 Integrated Peripherals: Our design utilizes four integrated peripherals, PWM, ATD, SCI, and EPHY. Because of limited time and space, I only elaborate on PWM and ATD modules. For the PWM module, the I/O port control register is located at the Port Integration Module. Here, the Data Direction Register (DDRT) is set to be an output and PTT is also set to its appropriate state. The TEN bit of TSCR1 is set to enable, and this enables the timer module. TIOS is set with its appropriate bit to enable the timer channel for output compare. Output Mode (OM) is set to bit ‘1’. [3] The ATD module is set to operate for program-driven operation. ADPU (ATDCTL2(7)) is set to ‘1’ to enable ATD. ATDDIEN is set to ‘0’ because we use analog input for ATD. ATDCTL3 need to be set to a certain value for the conversion sequence length. ATDCTL4 (7) is set to ‘1’ for 8 bit resolution. ATDCTL4 (6:5) is set to a certain value corresponding to sample time needed. ATDCTL4(4:0) is used to set clock prescalar. To start conversion, write to the ATDCTL5 register. [4] 2.3 Code Organization Our design utilizes a polling loop type of execution. After startup, the program goes to an initialization process where all registers are set to certain values. Then the program goes into a polling loop until it receives input from Ethernet interface. After the input received, the program determine what module it should execute such as drive, arm control etc. The automatic lighting and distance sensors are also implemented using polling loop execution. The program keeps polling the ATD module and turns light on if it is dark or stop the car if an obstacle detected. The flow chart of the program is on Appendix A. 2.4 Debugging and Self-test The self_test() function execute the self-test routine. To activate this function, user need to turn one the self-test switch. The self-test routine will check if there any peripherals that are

-4- ECE 477 Digital Systems Senior Design Project Spring 2007 not working properly or not connected. This function will spin all motors indefinitely and will turn on all LEDs. For debugging purpose we used Background Debug Monitor (BDM) so part of the memory will be reserve for BDM. 3.1 Software Narrative 3.1.1 Vehicle Movement Control For the vehicle motor speed control, our design uses a timer channel to simulate a PWM signal. There will be three speed of the motor. Forward or backward direction is controlled using two GPIO. Steering control also use two GPIO. From the web interface, user can control the speed and the direction of the vehicle. 3.1.2 Arm Movement Control The mechanical arm contains five DC motors. Each of the DC motor controlled by two GPIOs. The mechanical arm is controlled by an operator through the web interface. 3.1.3 Camera Movement Camera movement system contains an analog servo. The servos is controlled by a PWM signals. The operator manually controlled the movement of the wireless camera through the web interface. 3.1.4 Peripheral Devices and Sensors The headlight LED is connected to a GPIO. The microcontroller automatically turns it on when low light condition is detected by the light sensor. The light sensor is connected to an ATD port. 3.1.5 Web Interface The web interface is accessed wirelessly through an embedded web page and wireless bridge. The embedded web browser is coded using C#. The web interface allows user to control the movement of the vehicle, the movement of the mechanical arm and pan/tilt of the camera. From the web interface also, user able to see the status of the vehicle and the life feed video from the wireless webcam. We are using open source OpenTCP for our Ethernet interface. The user interface communicates with the microcontroller by sending and receiving UDP packet.

-5- ECE 477 Digital Systems Senior Design Project Spring 2007

3.2 Code Modules The hierarchical arrangement diagram is shown on Appendix B. None of the block has been translated into programming language. main(): This is the starting point of our program after reset or after startup. This function will call another function and also do some initialization and variable assignment. demoinit(): This function will do initializations required for our program such as to set appropriate value to register. my_ATD_init(): Initialize the ATD module. myLightSensor (): This function read the value from ATD module that connected to light sensor and turns on the LEDs when the ambient light is low. myFrontDistSensor(), myRearDistSensor() and check_stop():These functions read the value from ATD module that connected to distance sensors and stop the car when necessary. myBatteryStatus (): This function read the battery voltages from ATD and send UDP packet to update the web display. This function also send warning if the battery voltage go lower than predetermine threshold. car_status(): Sending UDP packet about the car status to the host computer. udp_demo_eventlistener(): this function compares the received UDP flags and determines the function it should call. steering(): Control the direction of the car. myMove_forward() and myMove_reverse(): Control the drive motor of the car. This functions is called by the udp_demo_eventlistener(). arm_base(), arm_one(), arm_two(), arm_three() and arm_grip(): Control the movement of the mechanical arm. These functions will control the movement of five DC motors on the arm using H-Bridges(FAN8082) through 10 GPIOs. This function does not do any calculation on how to move the arm since all of the calculation will be done on the operators computer. myMove_camera (): This function called by the udp_demo_eventlistener () function. The movement of the wireless camera is controlled by this function using a PWM channel. isr(): This is the interrupt service routine. Isr() looks up on interrupt and calls the relevant functions. self_test(): This function runs a test program to determine that every peripheral working properly.

-6- ECE 477 Digital Systems Senior Design Project Spring 2007

4.0 Summary In this document, the software design consideration is analyzed. It detailed the mapping of memory and also the mapping of external peripherals. The code organization of our design is also explained to be mainly interrupt-driven and the flowchart of the overall program is included in this document. On the second part, the modules of the program were explained and the hierarchy diagram of the program is included in the Appendix section of this report.

-7- ECE 477 Digital Systems Senior Design Project Spring 2007

List of References

[1] Freescale MC9S12NE64 Datasheet, “Device Memory Map” Feb. 2007. Available at HTTP: http://www.freescale.com/files/microcontrollers/doc/data_sheet/MC9S12NE64V1.pdf

[2] Freescale MC9S12NE64 Datasheet, “Detailed Register Map” Feb. 2007. Available at HTTP: http://www.freescale.com/files/microcontrollers/doc/data_sheet/MC9S12NE64V1.pdf

[3] PWM Generation Using HCS12 Timer Channels, Feb. 2007. Available at HTTP: http://www.freescale.com/files/microcontrollers/doc/data_sheet/MC9S12NE64V1.pdf

[4] An Overview of the HCS12 ATD Module, Feb. 2007. Available at HTTP: http://www.freescale.com/files/microcontrollers/doc/app_note/AN2428.pdf

-8- ECE 477 Digital Systems Senior Design Project Spring 2007

Appendix A: Flowchart/Pseudo-code for Main Program

Start/Reset

Initialization

Get flags Read light sensor

Y Dri Forward/r Turn ve everse LEDs Dar on N k? Y Y N Ar Move Arm m N

Y Pan/ Move camera Tilt

N

Y Tur Shutdown Halt n off N

-9- ECE 477 Digital Systems Senior Design Project Spring 2007

Appendix B: Hierarchical Block Diagram of Code Organization

main()

demo_i car_status() battery_statu myLightSensor Udp_event_list isr() nit() s() () ener()

self_test() distance_sens ors()

steering(), myMove_forward(), arm_functions myMove_camera() myMove_reverse()

-10-

Recommended publications