Sei sulla pagina 1di 18

UNIVERSITY OF GREENWICH MEDWAY SCHOOL OF ENGINEERING

DESIGN OF EMEBEDDED SYTEMS

AN ASSIGNMENT REPORT ON THE DESIGN AND SIMULATION OF A SERVO MOTOR TESTER BY

BABATUNDE LATEEF KAYODE 000744244

MSc ELECTRICAL & ELECTRONICS ENGINEERING

MARCH, 2013

UNIVERSITY OF GREENWICH MEDWAY SCHOOL OF ENGINEERING MSc ELECTRICAL & ELECTRONICS ENGINEERING

Declaration of Originality

I declare that the work contained in this formal report is completely my own. Any material that has not been originated by me has been marked and the creators identified.

Name: Babatunde, Lateef Kayode Signature: Date: 5TH March, 2013 Course: Design of Embedded systems

ii

TABLE OF CONTENTS
TITLE PAGE Declaration of Originality TABLE OF CONTENTS CHAPTER 1.0 Introduction 1 i ii iii

1.1 Problem Definition 1.2 Background 1.3 Aim and Objectives

1 1 1

2.0 Problem Analysis

2.1 Input 2.2 Output 2.3 System 2.4 Software 2.5 Test Plan

2 2 2 2 2

3.0 Possible Solution

3.1 Input 3.2 Output 3.3 System 3.4 Software 3.5 Test Plan

3 3 3 3 3

iii

4.0 Implementation

4.1 Hardware Design 4.2 Software Design 4.3 Program Implementation 4.4 Simulation and Debugging

4 4 5 6

5.0 Results

6.0 Discussion

7.0 Conclusion REFERENCE LIST APPENDIX

10 11

iv

CHAPTER ONE
Introduction
1.1 Problem Definition The design and simulation of an embedded system requires knowledge of programming and the software required to implement them. This assignment involves the design and simulation of a servo motor tester with a LCD position output. 1.2 Background The need to reduce production cost incurred by testing embedded systems that more likely to fail has led to the importance design and simulation. Animated components and microprocessors are used to provide complete simulation before prototypes are produced. This also helps to save time as in the competitive market, the longer it takes to launch a product the less the product is able to attain it maximum return in earning.
Schematic Design Software Developme nt System Simulation

Figure 1: Simulation Process Block Diagram 1.3 Aim and Objectives Aim The aim of the report is to design and simulate a servo motor tester with an LCD position output. Objectives 1) To read a desired angle from an analogue potentiometer. 2) To display a desire angle on a LCD. 3) To output a suitable PWM signal to position a servo motor at a desired angle. 4) To provide an automated a servo motor operation.

CHAPTER TWO
Problem Analysis
2.1 Input: A variable analogue input will be required for the system. A button input was required for the automated operation of the system 2.2 Output: The system will expected to display the motor angle and also a servo motor will be expected to rotate in response to the input. The system was required to automate the servo control operation

2.3 System The system was required to perform analogue to digital conversion of the input and send it to the output. The system was also required to send the value of the angle to the display. The system will also be required to send pulse width modulated signal to the input of the servo motor. The operating frequency of the microcontroller is required also. 2.4 Software An Integrated Development Environment was required to the writing and compiling of the program. A schematic design and simulation software was also required for the connection of the components and simulation. A compiler is also required to compile the code. 2.5 Test : 1) Measure and verify the input ADC. 2) Measure and verify the PWM output 3) Inspect visually the value on the LCD

CHAPTER THREE
Possible Solutions
3.1 Input: A potentiometer may be used to provide the varying analogue input to the system and a push button or a latch switch may be used to provide button input required for the automated operation of the system 3.2 Output: The servo motor may be made to rotate from 0 to 180 or -90 to + 90, it may also be implement to move very fast or very slowly in its automated operation. The servo motor 3.3 System An external A/D converter may be used or the A/D conversion of the microcontroller may be used to convert the analogue input to digital. The internal display driver of the microcontroller may be used to output the display or an external driver may be used. To implement the pulse width modulation, the PWM registers of the pic microcontroller may be used or it may be implemented using the internal clock delays. 3.4 Software MPLAB[1] Integrated Development Environment (IDE) may be used to write the program and Proteus VSM[2] software may be used to simulate and debug the program. Also ISIS [3]schematic capture may be used draw the schematic diagram of the circuit. HiTech PIC C compiler may be used or Microchip C18 may be used as the compiler 3.5 Test 1) The debugging function of the PIC may be used to verify the value in the ADC output register. 2) The virtual oscilloscope may be used to check if the servo PWM is accurate.

CHAPTER FOUR
Problem Implementation
A PIC 16F917, a pwm motor servo, a potentiometer and a 32 segment LCD display were used to implement the system 4.1 Hardware Design The hardware design was implemented using ISIS schematic capture. This was the stage where the virtual connection where specified for the circuit that was implemented. The components were entered directly from the library of the software. 4.2 Software Design Program flowchart
Start

Analogue input or
Get Analogue Input Perform Analogue to Digital Conversion Get Result from A/D register Convert result to value between 0 and 180

Automated operation i
Is PortD= 01

NO

YES

Convert result to value between 1ms and 2ms

Convert value to array to load the display

Use value to implement PWM delay

Output to Servo Motor

Has the value in the A/D Register changed?

4.3 Program Implementation The internal A/D converter of the microprocessor was used to convert the analogue input to digital. In order to make use of this certain registers were loaded with bits which selected the configuration that was desired. The PIC 16f917 has a 8 channel A/D converter and has a 10 bit resolution output that is stored between two registers. The CHS bits of the ADCON registers were used to set the channel and the ADFM bit of the ADCON0 register was used to select which format the output was and ultimately which register was used to perform system operations. The TRISx register was used to set the I/O status of the port and the ANSEL register was used to select which analogue input port bits. The VCFG bit of the ADDCON was set to provide independent control of the voltage reference. Using the T AD specification of 1.6uS from the microprocessor datasheet the ADSC bits of the ADCON1 register was set to a
5

conversion rate of FOSC/2. The ADC module was enabled by setting the ADON bit of the ADCON0 register to 1. The GO/!DONE bit of the ADCON0 register was used start the A/D conversion when it was set to 1. The code below shows the value of bit assigned to the various register to configure it. TRISB = 0x00; TRISC = 0x00; TRISD = 0x00; ADCON1 = 0x05; TRISA = 0x03; ANSEL = 0x03; ADCON0 = 0x00; ADON=1; // Set all PORTB pins as outputs // Set all PORTC pins as outputs // Set all PORTD pins as outputs // Fosc/2 // set RA0 & RA1 as inputs // set RA0 & RA1 as analog inputs // set vref & select AN0 //switch on the adc module

The program below returns a digital value from the ADC output register to a variable. for(;;) { CHS0 = 0; __delay_us(2); GO_nDONE=1; // initiate conversion on the selected channel while(GO_nDONE==1); //wait for the conversion to finish x=ADRESH; // return 8 MSB of the result The program below implements the PWM for the servo x = ADRESH; n = (float)x/10; int i; for (i=0; i<=n; i++) { PORTC= PULSEON ; } PORTC=PULSEOFF; __delay_ms(18); 4.4 Simulation and Debugging In order to simulate the system the coded program from MPLAB saved as .COF file was loaded into the PIC in Proteus VSM as shown in the figure 2 below. The .COF contains all the necessary files for debugging. To make of the debugging feature of the .cof file the pause button is pressed and the code will pop up, the ADC module was activated in the configure diagnostics menu as shown in figure 3 below and this enabled the value of the ADC output register to be monitored.

Figure2 Component property of the PIC where the .cof file will be loaded

Figure Configure Diagnostic Menu 7

CHAPTER FIVE
Result

Potentiometer 0 5 10 15 20 24 28 32 36

Pulse width uS 150 375 575 800 1150 1380 1580 1730 2000

motor angle -90 -90 -90 -90 -54 -18 18 54 90

Table: PWM Output

CHAPTER SIX
Discussion of Results
The PWM result is not performing as expected, the potentiometer reading was only valid for 36% after which the delay time had exceeded 20mS that was specified by the code. This may the due to the time it takes the microcontroller to execute an instruction and given that the delay loop that implements the PWM is very long, this has affected the output for the PWM restricting to only two step values.

CHAPTER SEVEN
Conclusion
In conclusion the overall exercise did not meet the all of the objectives, haven said that, the important of design and simulation of embedded systems was clearly seen as it was easy to debug the codes without having to spend money to complete the circuit diagram. This will have a lot of application in the production and manufacturing industry where cost and time are major factors in success of a product.

10

REFERENCE LIST
1. Microchip

Available at: http://www.microchip.com/pagehandler/enus/family/mplabx/ Accessed: 15 Febuary 2013

2. Labcenter Electronics Available at: http://www.labcenter.com/ Accessed : 28 Feburary 2013 3. PIC 16f917 Datasheet Available http://ww1.microchip.com/downloads/en/DeviceDoc/41250F.pdf Accessed: feburary 2013 at: 20

11

APPENDIX
#ifndef _XTAL_FREQ // Unless already defined assume 8MHz system frequency // This definition is required to calibrate __delay_us() and __delay_ms() //#define _XTAL_FREQ 8000000L // 8MHz #define _XTAL_FREQ 500000L // 500kHz #endif #include <stdio.h> #include <htc.h> #include "usart.h" // PROGRAM CONSTANTS #define PULSEON 0x01 #define PULSEOFF 0x00 #define D_CLK RB0 // set pin for display driver clock #define D_DIN RB1 // set pin for display driver data input #define D_LOAD RB2 // set pin for display driver load // set chip configuration bits __CONFIG(FOSC_INTOSCIO & WDTE_OFF& PWRTE_OFF & BOREN_OFF & CPD_OFF & CP_OFF); /*void delay_manualus(unsigned int ms) { int i; int x; for (i=0; i<=x; i++) { __delay_us(100); } }*/ void main(void) { int n,x; #if _XTAL_FREQ == 4000000L OSCCON = 0x60; #endif #if _XTAL_FREQ == 2000000L OSCCON = 0x50; #endif #if _XTAL_FREQ == 1000000L OSCCON = 0x40; #endif #if _XTAL_FREQ == 500000L OSCCON = 0x30; #endif INTCON=0; // Disable the interrupts. init_comms(); // set up the USART - settings defined in usart.h TRISB = 0x00; TRISC = 0x00; TRISD = 0x00; ADCON1 = 0x05; // Fosc/2 // Set all PORTB pins as outputs // Set all PORTC pins as outputs // Set all PORTD pins as outputs

12

TRISA = 0x03; // set RA0 & RA1 as inputs ANSEL = 0x03; // set RA0 & RA1 as analog inputs ADCON0 = 0x00; // set vref & select AN0 ADON=1; //switch on the adc module __delay_us(2); unsigned char data[]= {0x00,0x3f,0x06,0x00}; char tempstring[20]; int n=0,x; int temp = 100; for(;;) { CHS0 = 0; __delay_us(2); GO_nDONE=1; // initiate conversion on the selected channel while(GO_nDONE==1); //wait for the conversion to finish x=ADRESH; // return 8 MSB of the result x = ADRESH; n = (float)x/10; PORTC= PULSEON; int i; for (i=0; i<=n; i++) { PORTC= PULSEON } PORTC=PULSEOFF; __delay_ms(18); PR2 = 0x9B; T2CON = 0x07; CCPR1L = n; CCP1CON = 0x3C; } ADON=0; //switch off adc */

//

// // // //

// Loop Forever while(1) { __delay_ms(10); } // end of while } // end of main

// delay for 1 millisecond

13

U2
VI-302-1

RXD TXD RTS CTS

TX RX

LOBAT

+5V

1/40

U1
2 3 4 5 6 7 14 13 8 9 10 1 D_CLK D_DIN D_LOAD 33 34 35 36 37 38 39 40 RA0/AN0/C1-/SEG12 RA1/AN1/C2-/SEG7 RA2/AN2/C2+/VREF-/COM2 RA3/AN3/C1+/VREF+/SEG15 RA4/C1OUT/T0CKI/SEG4 RA5/AN4/C2OUT/SS/SEG5 RA6/OSC2/CLKO/T1OSO RA7/OSC1/CLKI/T1OSI RE0/AN5/SEG21 RE1/AN6/SEG22 RE2/AN7/SEG23 RE3/MCLR/Vpp RD0/COM3 RD1 RD2/CCP2 RD3/SEG16 RD4/SEG17 RD5/SEG18 RD6/SEG19 RD7/SEG20 19 20 21 22 27 28 29 30 15 16 17 18 23 24 25 26
47%

U4
D_CLK D_DIN D_LOAD 40 34 2 31 CLOCK SEG[1..32] DIN BP LOAD LCDCLK DOUT AY0438/P 30 35

SEG[1..32]

1k

C3

40pF

RB0/INT/SEG0 RB1/SEG1 RB2/SEG2 RB3/SEG3 RB4/COM0 RB5/COM1 RB6/ICSPCLK/ICDCK/SEG14 RB7/ICSPDAT/ICDDAT/SEG13

RC0/VLCD1 RC1/VLCD2 RC2/VLCD3 RC3/SEG6 RC4/T1G/SDO/SEG11 RC5/T1CKI/CCP1/SEG10 RC6/TX/CK/SCK/SCL/SEG9 RC7/RX/DT/SDI/SDA/SEG8

+5V A TX RX B C D +88.8

PIC16F917 SRCFILE=..\Documents\feasey assignment\ADC.c

R1
10k

R2
10k

R3
10k

SW1

SW2

SW3
TITLE: DATE:

BL222 ASSIGNMENT DESIGN


BY: A Feasey REV: 1

14

SEG29 SEG28 SEG27 SEG26 SEG25 SEG24 SEG23 SEG22 SEG21 SEG20 SEG19 SEG18 SEG17 SEG16 SEG15 SEG14 SEG13 SEG12 SEG11 SEG10 SEG9 SEG8 SEG7 SEG6 SEG5 SEG4 SEG3 SEG2 SEG1

38 2 39 28 3 8 32 31 9 10 11 29 30 12 27 26 13 14 15 24 25 16 23 22 17 18 19 20 21

RV1

05/03/13
PAGE:

1/1

Potrebbero piacerti anche