21
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 i

Design and Simulation of a Servo Motor Tester

Embed Size (px)

DESCRIPTION

The aim of the report is to design and simulate a servo motor tester with an LCD position output.

Citation preview

Page 1: Design and Simulation of a Servo Motor Tester

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 KAYODE000744244

MSc ELECTRICAL & ELECTRONICS ENGINEERING

MARCH, 2013

i

Page 2: Design and Simulation of a Servo Motor Tester

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

Page 3: Design and Simulation of a Servo Motor Tester

TABLE OF CONTENTS

TITLE PAGE i

Declaration of Originality ii

TABLE OF CONTENTS iii

CHAPTER

1.0 Introduction 1

1.1 Problem Definition 11.2 Background 11.3 Aim and Objectives 1

2.0 Problem Analysis 2

2.1 Input 22.2 Output 22.3 System 22.4 Software 22.5 Test Plan 2

3.0 Possible Solution 3

3.1 Input 33.2 Output 33.3 System 33.4 Software 33.5 Test Plan 3

4.0 Implementation 4

4.1 Hardware Design 44.2 Software Design 44.3 Program Implementation 54.4 Simulation and Debugging 6

5.0 Results 8

6.0 Discussion 9

7.0 Conclusion 10

iii

Page 4: Design and Simulation of a Servo Motor Tester

REFERENCE LIST 11

APPENDIX

iv

Page 5: Design and Simulation of a Servo Motor Tester

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.

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.

1

Schematic Design

Software Development

System Simulation

Page 6: Design and Simulation of a Servo Motor Tester

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

2

Page 7: Design and Simulation of a Servo Motor Tester

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.

3

Page 8: Design and Simulation of a Servo Motor Tester

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

Analogue input or

Automated operation i

NO

YES

4

Get Analogue Input

Perform Analogue to Digital Conversion

Get Result from A/D register

Convert result to value between 1ms and 2ms

C

B

StartA

Is PortD=01

A

Convert result to value between 0 and 180

Convert value to array to load the display

Page 9: Design and Simulation of a Servo Motor Tester

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 TAD specification of 1.6uS from the microprocessor datasheet the ADSC bits of the ADCON1 register was set to a

5

Has the value in the A/D Register changed?

C

Use value to implement PWM delay

B

Output to Servo

Motor

Page 10: Design and Simulation of a Servo Motor Tester

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; // Set all PORTB pins as outputsTRISC = 0x00; // Set all PORTC pins as outputsTRISD = 0x00; // Set all PORTD pins as outputs

ADCON1 = 0x05; // Fosc/2TRISA = 0x03; // set RA0 & RA1 as inputsANSEL = 0x03; // set RA0 & RA1 as analog inputsADCON0 = 0x00; // set vref & select AN0ADON=1; //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 channelwhile(GO_nDONE==1); //wait for the conversion to finishx=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.

6

Page 11: Design and Simulation of a Servo Motor Tester

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

Figure Configure Diagnostic Menu

7

Page 12: Design and Simulation of a Servo Motor Tester

CHAPTER FIVE

Result

Potentiometer Pulse width uS motor angle0 150 -905 375 -90

10 575 -9015 800 -9020 1150 -5424 1380 -1828 1580 1832 1730 5436 2000 90

Table: PWM Output

8

Page 13: Design and Simulation of a Servo Motor Tester

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.

9

Page 14: Design and Simulation of a Servo Motor Tester

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

Page 15: Design and Simulation of a Servo Motor Tester

REFERENCE LIST

1. Microchip Available at: http://www.microchip.com/pagehandler/en-us/family/mplabx/ Accessed: 15 Febuary 2013

2. Labcenter Electronics Available at: http://www.labcenter.com/ Accessed : 28 Feburary 2013

3. PIC 16f917 Datasheet Available at: http://ww1.microchip.com/downloads/en/DeviceDoc/41250F.pdf Accessed: 20 feburary 2013

11

Page 16: Design and Simulation of a Servo Motor Tester

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; // Set all PORTB pins as outputsTRISC = 0x00; // Set all PORTC pins as outputsTRISD = 0x00; // Set all PORTD pins as outputs

ADCON1 = 0x05; // Fosc/2

12

Page 17: Design and Simulation of a Servo Motor Tester

TRISA = 0x03; // set RA0 & RA1 as inputsANSEL = 0x03; // set RA0 & RA1 as analog inputsADCON0 = 0x00; // set vref & select AN0ADON=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 channelwhile(GO_nDONE==1); //wait for the conversion to finishx=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 Foreverwhile(1) {

__delay_ms(10); // delay for 1 millisecond} // end of while

} // end of main

13

Page 18: Design and Simulation of a Servo Motor Tester

SEG[1..32]

SE

G1

3

SE

G8

SE

G1

SE

G2

SE

G3

SE

G4

SE

G5

SE

G6

SE

G7

SE

G9

SE

G1

0S

EG

11

SE

G2

9S

EG

28

SE

G2

7S

EG

26

SE

G2

5S

EG

24

SE

G2

3S

EG

22

SE

G2

1S

EG

20

SE

G1

9S

EG

18

SE

G1

7S

EG

16

SE

G1

5S

EG

14

SE

G1

2

TITLE:

BY:

DATE:

PAGE:

BL222 ASSIGNMENT DESIGN 05/03/13

A Feasey 1/1REV: 1

R310k

R210k

SW2 SW3

RXD

RTS

TXD

CTS

RX

TX

SEG[1..32]BP

30

DOUT35

CLOCK40

DIN34

LOAD2

LCDCLK31

U4

AY0438/P

RA0/AN0/C1-/SEG122

RA1/AN1/C2-/SEG73

RA2/AN2/C2+/VREF-/COM24

RA4/C1OUT/T0CKI/SEG46

RA5/AN4/C2OUT/SS/SEG57

RE0/AN5/SEG218

RE1/AN6/SEG229

RE2/AN7/SEG2310

RA7/OSC1/CLKI/T1OSI13

RA6/OSC2/CLKO/T1OSO14

RC1/VLCD216

RC2/VLCD317

RC3/SEG618

RD0/COM319

RD120

RB7/ICSPDAT/ICDDAT/SEG1340

RB6/ICSPCLK/ICDCK/SEG1439

RB5/COM138

RB4/COM037

RB3/SEG336

RB2/SEG235

RB1/SEG134

RB0/INT/SEG033

RD7/SEG2030

RD6/SEG1929

RD5/SEG1828

RD4/SEG1727

RD3/SEG1622

RD2/CCP221

RC7/RX/DT/SDI/SDA/SEG826

RC6/TX/CK/SCK/SCL/SEG925

RC5/T1CKI/CCP1/SEG1024

RC4/T1G/SDO/SEG1123

RA3/AN3/C1+/VREF+/SEG155

RC0/VLCD115

RE3/MCLR/Vpp1

U1

PIC16F917SRCFILE=..\Documents\feasey assignment\ADC.c

C340pF

TXRX

D_CLKD_DIN

D_LOAD

D_CLKD_DIN

D_LOAD

LOBAT

1/4

0 2 3 8 9 10 11 12 13 14 15 16 17 18 19 20 21222324 252629 30313238 39 2728

U2VI-302-1

R110k

SW1

47%

RV1

1k

+5V

+88.8

+5VA

B

C

D

14