PW 5
PW 5
(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):
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.
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.
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
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
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.
1. PC installed software:
a. MPLABX IDE integrates with XC8 compiler.
b. PROTEUS Professional
2. PIC Trainer
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.
#include <xc.h>
#define _XTAL_FREQ 4000000
#define IN1 LB0
#define IN2 LB1
#include <xc.h>
#define _XTAL_FREQ 4000000
#define IN1 LB0
#define IN2 LB1
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
Write a Program Code5 and save it as PW5D than build the program until
successful. If any error occurs, fix it.
#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
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)
Example:
CCP1CON = 0b00111100; //PWM mode