Professional Documents
Culture Documents
DATE:
LECTURER’S NAME:
GROUP NO.:
SECTION/CLASS:
TOTAL
STUDENT ID & NAME: MARKS
(100%)
(1)
(2)
(3)
1
PRACTICAL SKILL ASSESSMENT RUBRIC (CLO3)
Student Number 1 2
Score description
Weightage
Item Aspects Poor Moderate Good Excellent Score
2 3 4 5
2
REPORT ASSESSMENT RUBRIC (CLO3)
Student Number 1 2
Score description
Weightage
Item Aspects Poor Moderate Good Excellent Score
2 3 4 5
G Questions (10%)
1
Some formatting errors Proper formatting with Proper formatting, Proper formatting,
or missing sections. labelled sections with section labelled and section clearly labelled
Result and
algorithm, schematic, organized with and well organized
H Documentation 2
no comments and no algorithm, schematic, with appropriate
(10%)
output a few comments and algorithm, schematic,
only a few output comments and output
3
1 LEARNING OUTCOMES (LO):
2 OBJECTIVE
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.
The L293D is a 16-pin Motor Driver IC which can control a set of two DC motors
simultaneously in any direction. The L293D is designed to provide bidirectional drive currents of
up to 600 mA (per channel) at voltages from 4.5 V to 36 V (at pin 8!). You can use it to control
small dc motors - toy motors.
Figure 2: Motor Controller Circuit using L293D Table 1: Input Logic table of L293D
4
PWM Overview
PWM, or pulse width modulation is a technique which allows us to adjust the average value of
the voltage that’s going to the electronic device by turning on and off the power at a fast rate.
The average voltage depends on the duty cycle, or the amount of time the signal is ON versus
the amount of time the signal is OFF in a single period of time.
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:
• PR2 registers
• TxCON registers
• CCPRxL registers
• CCPxCON registers
1. Load the PR2 value which will decide the period of the pulse.
2. Set the duty cycle by loading value in the CCPR1L: CCP1CON<5: 4>
3. Configure the CCP1CON register for setting a PWM mode.
4. Initialize the pin CCP1as an output pin which will give PWM output.
5. Configure the T2CON register and enable TMR2 using T2CON
4 EQUIPMENT / TOOLS
i. PC installed software:
a. MPLABX IDE integrates with XC8 compiler.
b. PROTEUS Professional
5
5 PROCEDURE
5.1 PART A: CONTROL DC MOTOR USING MOTOR DRIVER
16 8 U2
U1
2 15 2 3
RA0/AN0 RC0/T1OSO/T1CKI IN1 VSS VS OUT1
3 16 7 6
RA1/AN1 RC1/T1OSI/CCP2/UOE IN2 OUT2
4 17 1
RA2/AN2/VREF-/CVREF RC2/CCP1/P1A EN1
5 23
RA3/AN3/VREF+ RC4/D-/VM
6 24
RA4/T0CKI/C1OUT/RCV RC5/D+/VP
7 25 9
RA5/AN4/SS/LVDIN/C2OUT RC6/TX/CK EN2
14 26 10 11
RA6/OSC2/CLKO RC7/RX/DT/SDO IN3 OUT3
13 15 14
OSC1/CLKI IN4 GND GND OUT4
33 19
RB0/AN12/INT0/FLT0/SDI/SDA RD0/SPP0
34 20 L293D
RB1/AN10/INT1/SCK/SCL RD1/SPP1
35 21
RB2/AN8/INT2/VMO RD2/SPP2
36 22
RB3/AN9/CCP2/VPO RD3/SPP3
37 27
RB4/AN11/KBI0/CSSPP RD4/SPP4
38 28
RB5/KBI1/PGM RD5/SPP5/P1B
39 29
RB6/KBI2/PGC RD6/SPP6/P1C
40 30
RB7/KBI3/PGD RD7/SPP7/P1D
R1
8 10k
RE0/AN5/CK1SPP
9
RE1/AN6/CK2SPP
10
RE2/AN7/OESPP
18 1
VUSB RE3/MCLR/VPP
PIC18F4550
5.3 Write a Program A , save it as MOTOR1.c then build the program until successful. If any error
occurs, fix it.
Program A
#include <xc.h>
while (1)
{
//motor FORWARD 5 second
EN1= 1;
IN1=1;
IN2=0;
delay_ms(5000);
6
//motor STOP 1 second
EN1 = 0;
delay_ms (1000);
Observation:
State your observation of the circuit.
By using the same circuit in step 5.1, add 3 switches (active LOW) at pins RE0 (SW1),
RE1(SW2) and RE2 (SW3). Write program to perform as below:
7
b) Calculate the value of PR2 register and CCPR1L for each speed:
Use PWM frequency 1.22 kHz, TMR2 prescale value 16 and FOSC= 20 MHz.
5.4 Write a Program B, save it as MOTOR2.c then build the program until successful.
Program B
#include <xc.h>
#define _XTAL_FREQ 20000000
void main(void)
{
// Configure I/O pins
_______________
_______________
_______________
while (1)
{
if ( __________ ) // SW1 is pressed
{
CCPR1L = ___; // 30% Duty cycle
//motor FORWARD
INP1=__;
8
INP2=__;
}
Observation:
State your observation of the circuit.
6 DISCUSSION / TASK
3. Find the PR2 value and the prescaler needed to get 1.22 kHz PWM frequencies:
(6 marks)
7 CONCLUSION
Appendix 1
9
10