0% found this document useful (0 votes)
87 views

PW 5

This document contains details for a practical work assignment on interfacing a motor for an embedded systems applications course. It includes sections on theory of DC motors and methods for changing motor direction using relays or an H-bridge motor driver. The assignment involves students constructing motor interfaces using these methods and writing code to control motor direction and speed. Students will be assessed on their ability to complete the programming, circuit construction, and demonstration of the motor operation.

Uploaded by

Akmal Baihaqi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views

PW 5

This document contains details for a practical work assignment on interfacing a motor for an embedded systems applications course. It includes sections on theory of DC motors and methods for changing motor direction using relays or an H-bridge motor driver. The assignment involves students constructing motor interfaces using these methods and writing code to control motor direction and speed. Students will be assessed on their ability to complete the programming, circuit construction, and demonstration of the motor operation.

Uploaded by

Akmal Baihaqi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

ELECTRICAL ENGINEERING DEPARTMENT

ACADEMIC SESSION: SESI 2 2022/2023

DEC40053 – EMBEDDED SYSTEM APPLICATIONS

PRACTICAL WORK5 : HARDWARE INTERFACING - MOTOR


PRACTICAL WORK
DATE :
LECTURER’S NAME:
GROUP NO. :

STUDENT ID : STUDENT NAME : TOTAL MARKS


(100%)

(1)

(2)

(3)

(4)

SUBMIT RETURN
DATE : DATE :
DEC40053 – EMBEDDED SYSTEM APPLICATIONS
NO REG. NO. NAME OF STUDENT TOTAL MARK
1 /100

2 /100

3 /100

4 /100

PRACTICAL WORK 1 / 2 / 3 / 4 / 5 / 6
PRACTICAL SKILL ASSESSMENT RUBRIC - CLO 3:
Construct and simulate real-time embedded system application based on PIC16F/PIC18F microcontroller effectively.
(P4, PLO5)
SCORE weight Score
NO CRITERIA
1 2 3 4 5 S1 S2 S3 S4
1. Program code The program The program The program The program
is incomplete code is code is complete code is code is
with complete with with a little complete with a complete
inconsistent some inconsistence little and well
Write code typing inconsistence code typing and inconsistent organized. X4
program and not well code typing and well organized code typing and
organized well organized after being well organized
after being after being assisted by with a minimum
assisted by assisted by lecturer assist by lecturer
lecturer lecturer
2. The program The program The program The program The program
code still have code have code have three code have one code
an error. three or more or more error. or two error. successfully
Compile
Student error. Student Student can fixed Student can run
X4
and execute cannot fixed can fixed the the error with a fixed the error
program the error after error after minimum assist with a
being assisted being assisted by lecturer minimum assist
by lecturer. by lecturer. by lecturer
3. Student The circuit The circuit Can construct a Can
cannot fixed connection connection have hardware circuit construct a
Construct the circuit have three or three or more one or two hardware
circuit using connection by more error. error. Student error. circuit.
X4
hardware or itself after Student can can fixed the or or
software being assisted fixed the error error with a Can produce a Can produce
(Proteus) by lecturer. after being minimum assist schematic in neat
assisted by by lecturer Proteus one or schematic in
lecturer. two error. Proteus
Unsuccessful Successful Successful Successful Successful
program with program and program and program and program and X4
completely manage to get manage to get manage to get manage to
incorrect the correct the correct the correct get the
output on output on output on output on correct
hardware or hardware or hardware or hardware or output on
Demonstrate
Proteus. Proteus after Proteus with a Proteus. hardware or
circuit using
Student being assist by minimum assist Student Proteus.
4. hardware or having lecturer. by lecturer. understand Student
software difficulties to Student Student most of the understand
(Proteus) understand having understand program and the program
the program. difficulties to most of the can and can
understand program and demonstrate demonstrate
the program can the circuit. the circuit.
demonstrate demonstrate
the circuit. the circuit.
/ /80
TOTAL MARKS /80 /80
80
No Activity Observation Marks
Task Result
1  Program /5
 Circuit /5
2 Discussion /5
3 Conclusion /5
Total /20
1 LEARNING OUTCOMES (LO):

1. : Construct and simulate real-time embedded system application based on


PIC16F/PIC18F microcontroller effectively .( CLO3 - P4, PLO5 - DK6, DP1,
DP3 & DP5 )
2 OBJECTIVE

1. Construct DC motor interface to control direction with relay.


2. Apply program code to control DC motor direction with relay.
3. Construct DC motor interface to control direction with H-Bridge motor
configuration.
4. Apply program code to control DC motor speed using PWM with CCP.

3 THEORY

A. DC Motor

The DC motor direction can be change by changing the power supply polarity, there
are few methods to change the polarity. The most popular are: by using H-Bridge
motor driver and relays interface.

i) Relay interface

Relay is very important component to interface the heavy appliances with the help of
microcontroller. Relay Relays are devices which allow low power circuits to switch a
relatively high Current/Voltage ON/OFF.

Principle
Current flowing through the coil of the relay creates a magnetic field which attracts a
lever and changes the switch contacts. The coil current can be on or off so relays
have two switch positions and most have double throw (changeover) switch
contacts.

Construction and working


Relays are made up of electromagnet and a set of contacts generally based on
Single Pole Double Throw (SPDT) or Double Pole Double Throw (DPDT) switching
method. It has 3 pins to perform function –
COM = Common, always connect to NC; it is the moving part of the switch.
NC = Normally Closed, COM is connected to this when the relay coil is off.
NO = Normally Open, COM is connected to this when the relay coil is on.
Figure 1

ii) H-Bridge motor driver interface

L293 Motor Driver (H-Bridge)


The L293 and L293D are quadruple high-current half-H drivers. The L293 is
designed to provide bidirectional drive currents of up to 1 A at voltages from 4.5 V to
36 V. The L293D is designed to provide bidirectional drive currents of up to 600-mA
at voltages from 4.5 V to 36 V. Both devices are designed to drive inductive loads
such as relays, solenoids, dc and bipolar stepping motors, as well as other high-
current/high-voltage loads in positive-supply applications.

All inputs are TTL compatible. Each output is a complete totem-pole drive circuit,
with a Darlington transistor sink and a pseudo- Darlington source. Drivers are
enabled in pairs, with drivers 1 and 2 enabled by 1,2EN and drivers 3 and 4 enabled
by 3,4EN. When an enable input is high, the associated drivers are enabled, and
their outputs are active and in phase with their inputs. When the enable input is low,
those drivers are disabled, and their outputs are off and in the high-impedance state.
With the proper data inputs, each pair of drivers forms a Full-H (or bridge) reversible
drive suitable for solenoid or motor applications.

Figure 2: Bidirectional DC Motor Control

PWM Overview
Pulse-Width Modulation (PWM) is a scheme that provides power to a load by
switching quickly between fully on and fully off states. The PWM signal resembles a
square wave where the high portion of the signal is considered the on state and the
low portion of the signal is considered the off state. The high portion, also known as
the pulse width, can vary in time and is defined in steps. A larger number of steps
applied, which lengthens the pulse width, also supplies more power to the load.
Lowering the number of steps applied, which shortens the pulse width, supplies less
power. The PWM period is defined as the duration of one complete cycle or the total
amount of on and off time combined. PWM resolution defines the maximum number
of steps that can be present in a single PWM period. A higher resolution allows for
more precise control of the pulse width time and in turn the power that is applied to
the load. The term duty cycle describes the proportion of the on time to the off time
and is expressed in percentages, where 0% is fully off and 100% is fully on. A lower
duty cycle corresponds to less power applied and a higher duty cycle corresponds to
more power applied.
Figure 3 : CCP PWM Output Signal

STANDARD PWM OPERATION

The standard PWM function described in this section is available and identical for
CCP and ECCP modules.
The standard PWM mode generates a Pulse-Width modulation (PWM) signal on the
CCPx pin with up to 10
bits of resolution. The period, duty cycle, and resolution are controlled by the
following registers:

• PRx registers
• TxCON registers
• CCPRxL registers
• CCPxCON registers

SETUP FOR PWM OPERATION

The following steps should be taken when configuring the CCP module for standard
PWM operation:

a. Disable the CCPx pin output driver by setting the associated TRIS bit.
b. Select the 8-bit TimerX resource, (Timer2, Timer4 or Timer6) to be used for
PWM generation by setting the CxTSEL<1:0> bits in the CCPTMRSx register.
c. Load the PRx register for the selected TimerX with the PWM period value.
d. Configure the CCP module for the PWM mode by loading the CCPxCON
register with the appropriate values.
e. Load the CCPRxL register and the DCxB<1:0>bits of the CCPxCON register,
with the PWM duty cycle value.
f. Configure and start the 8-bit TimerX resource:
 Clear the TMRxIF interrupt flag bit of the PIR2 or PIR4 register. In
order to send a complete duty cycle and period on the first PWM
output, the above steps must be included in the setup sequence. If it is
not critical to start with a complete PWM signal on the first output, then
step 6 may be ignored.
 Configure the TxCKPS bits of the TxCON register with the Timer
prescale value.
 Enable the Timer by setting the TMRxONbit of the TxCON register.

g. Enable PWM output pin:


 Wait until the Timer overflows and the TMRxIF bit of the PIR2 or PIR4
register is set.
 Enable the CCPx pin output driver by clearing the associated TRIS bit
4 EQUIPMENT / TOOLS

1. PC installed software:
a. MPLABX IDE integrates with XC8 compiler.
b. PROTEUS Professional

2. PIC Trainer

5 SAFETY OPERATING PROCEDURE (SOP)


This is a partial list of basic safety precautions to use when working on a computer:
 Keep food and drinks out of your workspace.
 Keep your workspace clean and free of clutter.
 Remove your watch and jewelry and secure loose clothing.
 Make sure the computer equipment is plug in and turn ON the power switch.
 Never unplug a power supply while the equipment working.
 Do not touch areas at hot or that use a high voltage.
 Know where the fire extinguisher is located and how to use it.
 Bend your knees when lifting heavy objects to avoid injuring your back.
 Follow electrical safety guidelines to prevent electrical fires, injuries, and
fatalities in the workplace. Power supplies and monitors contain a high
voltage.

CAUTION
Do not repairing power supplies or monitors if broken. Only experienced
technicians should attempt to repair power supplies and monitors.
6.0 PROCEDURE

6.1 To begin, create a project named PW5A in Proteus 8 and save on your FOLDER
directory.
6.2 A. DC MOTOR USING RELAY

Write a Program Code1 into your PW5A project, than build the program until
successful. If any error occurs, fix it.

Program Code1 : One direction

#include <xc.h>
#define _XTAL_FREQ 4000000
#define IN1 LB0
#define IN2 LB1

void main (void) {


TRISB0 = 0; TRISB1 = 0;
ADCON1 = 0x0E;
while (1){
IN1=1; IN2=0; __delay_ms (1000); //Forward
IN1=0; IN2=0; __delay_ms (1000); //Stop
}
}
6.3 Construct circuit shown below in Proteus. State your observation of the circuit.

Circuit: DC Motor One Direction with Relay


6.4 Write a Program Code2 and save it as PW5B project than build the program until
successful. If any error occurs, fix it. RUN the simulation. State your observation of
the circuit.

Program Code2 : Two direction

#include <xc.h>
#define _XTAL_FREQ 4000000
#define IN1 LB0
#define IN2 LB1

void main (void) {


TRISB0 = ; TRISB1 = ;
ADCON1 = 0x0E;
while (1){
IN1= ; IN2= ; __delay_ms (1000); //Forward
IN1= ; IN2= ; __delay_ms (1000); //Stop
IN1= ; IN2= ; __delay_ms (1000); //Reverse
IN1= ; IN2= ; __delay_ms (1000); //Stop
}
}
6.5 B. DC MOTOR USING MOTOR DRIVER

Write a Program Code3 in Proteus 8 and save it as PW5C project than build the
program until successful. If any error occurs, fix it.

Program Code3

#include <xc.h>
#define _XTAL_FREQ 4000000
#define IN1 LB0
#define IN2 LB1
#define EN1 LB2

void main (void) {


TRISB0 = 0; TRISB1 = 0; TRISB2 = 0;
ADCON1 = 0x0E;
while (1){
EN1 = 1; IN1=1; IN2=0; __delay_ms (1000); //FORWARD
EN1 = 0; __delay_ms (1000); //STOP

EN1 = 1; IN1=0; IN2=1; __delay_ms (1000); //REVERSE


EN1 = 0; __delay_ms (1000); //STOP
}
}
6.6 Construct circuit shown in below in Proteus. RUN the simulation. State your
observation of the circuit.

Circuit: Control DC Motor using Motor Driver

6.7 C. DC Motor Speed Control

Write a Program Code5 and save it as PW5D than build the program until
successful. If any error occurs, fix it.

Program Code5: DC Motor Speed Control

#include <xc.h>
#define _XTAL_FREQ 4000000
#define IN1 LC0
#define IN2 LC1
#define EN1 LC2
#define SW1 RE0
#define SW2 RE1
#define SW3 RE2

void main(void) {
TRISC0 =0; TRISC1 =0; TRISC2 =0; TRISE=0xFF;
ADCON1= 0x0F;
T2CON = 0b00000101;
CCP1CON = 0b00111100;
PR2 = 249; // full scale
CCPR1L = 125; //50%

while (1) {
if (SW1 == 0) {
CCPR1L = 74;
IN1=1;
IN2=0;
}

else if (SW2 == 0) {
CCPR1L = 149;
IN1=0;
IN2=1;
}

else if (SW3 == 0) {
CCPR1L = 249;
IN1=1;
IN2=0;
}

else {
CCPR1L = 0;
IN1=0;
IN2=0;
}
}

Construct circuit shown below in Proteus. RUN the simulation. State your
observation of the circuit.
Circuit: DC Motor Speed Control

7 TASK

A conveyer control system consists of TWO (2) switches (active LOW) and a 12V
DC motor which is interface with L293D H-bridge. The control system used PWM
frequency 1.22 kHz, TMR2 prescale value 16 and F OSC= 20 MHz.

Draw the circuit diagram and write a program using PWM features in PIC
microcontroller to control the speed of the DC motor as below:

1. If SW1 is pressed and released the duty cycle value will increase by 10.
2. If SW2 is pressed and released the duty cycle value will decrease by 10.

8 TASK RESULT
9 DISCUSSION

10 CONCLUSION
Appendix 1

TIMER2 Control Register

1
7

Example:
T2CON = 0b00000101; //1:1 Postscale , Timer2 is On, 01-Prescale is 4

Calculation:
PWM frequency 1.22 kHz, TMR2 prescale value 16 and FOSC= 20 MHz.
PR2 = [ Fosc / (Fpwm x 4 x N) ] – 1 ; where N is Prescale (1:1 or 1:4 or 1:16)

PR2 = [20M / (1.22K x 4 x 16) ]-1= 256.15 -1 = 255

PR2 = 255; // full scale

CCPR1L = 26; //10%


CCPxCON Register

Example:
CCP1CON = 0b00111100; //PWM mode

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy