Anda di halaman 1dari 203

Edesign 424 Report

written by

Jacques

The study-notes marketplace


Buy and sell all your summaries, notes, theses, essays, papers, cases, manuals, researches, and
many more...

www.stuvia.co.uk

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

DESIGN (E) 414

Electronic Remote Control


operated Security Gate System

PRESENTED BY
Jacques du Preez (15063518)
Campbell Smith (14818264)

DEPARTMENT OF ELECTRIC & ELECTRONIC ENGINEERING

16 MAY 2011

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Declaration of own work

We, _____________________________and________________________________ the undersigned,


hereby declare that this report and the work contained therein is our own
original work, except where indicated.

Signature

___________________

______________________

J du Preez

C.M. Smith

Date

_________________

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Summary
This report discusses the design, construction, measurements and results for the Electronic
Remote control Security Gate product. The product was a fully integrated electrical &
electronic device. The product consists of four main systems naming; The Main Board,
Infrared Remote Control, The Motor Pulley Gate driven simulator, and the Software
package.
The requirements for the product were to enable a user to operate a remote controlled
security gate. A simulation of a motor driven security gate was done during the
demonstration opportunity were the functionality and viability of the product was tested. The
outcomes of the demonstration will be discussed in this report. Security measures were
implemented in the product design which allowed the user to sound the panic alarm situated
on the Main Board via the infrared remote control.
Maintenance and control parameters were implemented on the Main Board to allow
additional users to receive access to the remote control security gate system. The product
was designed to have three user interfaces naming; The Infrared Remote Control, The Main
Board user menu interface, and the Universal Serial Bus communication interface.

ii

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Table of Contents
Summary ................................................................................................................................................. ii
1.

Introduction .................................................................................................................................... 1

2.

System Description ......................................................................................................................... 2


2.1 Main Board System Description.................................................................................................... 2
System Block Diagram......................................................................................................................... 3
2.1.1 Microprocessor .......................................................................................................................... 4
2.1.2 Voltage Regulator ...................................................................................................................... 4
2.1.3 Universal Serial Bus .................................................................................................................... 5
2.2 Main Board Sub-System Description ............................................................................................ 6
2.2.1 LCD Screen ................................................................................................................................. 6
2.2.2 Infra-Red Receiver...................................................................................................................... 6
2.2.3 Eeprom ....................................................................................................................................... 7
2.2.4 DMOS FULL-BRIDGE MOTOR DRIVERS....................................................................................... 7
2.2.5 MOC & TRIAC ............................................................................................................................. 8
2.2.6 Buzzer ......................................................................................................................................... 9
2.2.7 Menu Keys.................................................................................................................................. 9
2.2.8 Optical Gate Sensor ................................................................................................................. 10
2.2.9 Motor ....................................................................................................................................... 10
2.2.10 Operational Amplifier & A/D Converter ................................................................................ 10
2.3 IR Remote Control ....................................................................................................................... 11
2.3.1 MICROPROCESSOR ................................................................................................................... 11
2.3.2 VOLTAGE REGULATOR ............................................................................................................. 12
2.3.3 IR LED ....................................................................................................................................... 12
2.3.4 BUTTONS .................................................................................................................................. 13

3.

System Detail Design..................................................................................................................... 14


3.1 Hardware Calculations ................................................................................................................ 14
3.1.1 The MOC and Triac................................................................................................................... 14
3.1.1.1 MOC ...................................................................................................................................... 14
3.1.1.2 Triac....................................................................................................................................... 15
3.1.2 Light Sensor .............................................................................................................................. 15
3.1.3 A/D Converter (Main Board) .................................................................................................... 17

3.2
4.

Design for IR Remote ................................................................................................................ 18


Programs ....................................................................................................................................... 27

iii

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

4.1.1 Mainboard Pin Assignments .................................................................................................... 27


4.1.2 Infra-Red Pin Assignments ....................................................................................................... 27
4.2

Software Calculation Design of Mainboard .............................................................................. 28

4.2.1 U0brg, UART0 serial port bit rate: ........................................................................................... 28


4.2.2 U1brg, UART1 serial port bit rate: ........................................................................................... 28
4.2.3 Buzzer frequency ..................................................................................................................... 28
4.2.4 PWM ........................................................................................................................................ 28
4.3

Software Calculation Design of IR Remote ............................................................................... 30

4.3.1 Infrared 36kHz waveform ........................................................................................................ 30


4.3.2 Automatic Power On/Off ......................................................................................................... 30
4.4

Software Design of Mainboard ................................................................................................. 31

4.4.1 Initialization in main() .............................................................................................................. 31


4.4.2 Initialized in ports_initialise()................................................................................................... 31
4.4.3 Serial port ................................................................................................................................. 31
4.4.4 LCD ........................................................................................................................................... 31
4.4.5 EEPROM ................................................................................................................................... 32
4.4.6 PWM ........................................................................................................................................ 32
4.4.7 Triac.......................................................................................................................................... 32
4.4.8 Light sensor .............................................................................................................................. 33
4.4.9 Real Time Clock ........................................................................................................................ 33
4.4.10 Infrared functions .................................................................................................................. 33
4.4.11 Menu ...................................................................................................................................... 33
4.4.12 Display Log ............................................................................................................................. 34
4.4.13 Motor Current ........................................................................................................................ 34
4.5

Software Design of Infrared Remote ........................................................................................ 35

4.5.1 Initialization in main() .............................................................................................................. 35


4.5.2 Initialized in ports_initialise()................................................................................................... 35
4.5.3 Serial port ................................................................................................................................. 35
4.6

System Flow Diagram................................................................................................................ 36

4.7

Interrupt Flow Diagram for Mainboard .................................................................................... 37

4.8

Interrupt Flow Diagram for IR Remote ..................................................................................... 41

5.

Measurements and Results .......................................................................................................... 42


5.1 Supply Voltage ............................................................................................................................ 42
5.2 Buzzer .......................................................................................................................................... 42
iv

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

5.3 Pulse Width Modulation ............................................................................................................. 43


5.4 The IR remote control Signal output........................................................................................... 44
6.

Conclusion ..................................................................................................................................... 45

7.

References .................................................................................................................................... 46

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

List of Figures
Figure 1) Main Board Illustration ............................................................................................................ 2
Figure 2) R8C/27 Microprocessor, circuit diagram [2] & Illustration...................................................... 4
Figure 3) LM7805 5V voltage regulator circuit diagram[2] & illustration ............................................... 4
Figure 4) Universal Serial Bus communication circuit diagram[2] .......................................................... 5
Figure 5) Universal Serial Bus communication ....................................................................................... 5
Figure 6) LCD screen circuit Diagram ...................................................................................................... 6
Figure 7) Hitachi HD44780 LCD screen ................................................................................................... 6
Figure 8) TSOP 1136 IR Receiver ............................................................................................................. 7
Figure 9) Eeprom M24C64 ...................................................................................................................... 7
Figure 10) DRV8801 PWM Full-Bridge Motor Driver Circuit Diagram [8] & Illustration ......................... 8
Figure 11) MOC & Triac Safety Light Circuit Diagram ............................................................................. 8
Figure 12) MOC & Triac Safety Light ....................................................................................................... 9
Figure 13) Buzzer Circuit Diagram & Illustration..................................................................................... 9
Figure 14) The Menu Keys .................................................................................................................... 10
Figure 15) Optical Gate Sensor circuit diagram & Gate optical sensor system .................................... 10
Figure 16) Operational Amplifier (MCP6244) ....................................................................................... 11
Figure 17) Infrared Remote Control...................................................................................................... 11
Figure 18) R8C/27 Microprocessor located on IR remote control........................................................ 12
Figure 19) LM2931 Voltage Regulator .................................................................................................. 12
Figure 20) Infrared Light Emitting Diode .............................................................................................. 13
Figure 21) Remote Control Switches (Buttons) .................................................................................... 13
Figure 22) TRIAC and MOC circuit (Blanckenberg,M, 2011:Lecture 6) ................................................. 14
Figure 23) IR circuit (Blanckenberg, M, 2011: Lecture 3)...................................................................... 18
Figure 24) Transistor Q1 ....................................................................................................................... 19
Figure 25) Transistor Q2 ....................................................................................................................... 20
Figure 26) Transistor Q2 with Thevenin voltage and resistance .......................................................... 21
Figure 27) LED circuit ............................................................................................................................ 23
Figure 28: Voltage Divider (adjusted figure Photoresistors, [S.a.]) ...................................................... 24
Figure 29) IR diode circuit ..................................................................................................................... 25
Figure 30) Radiant Power (TSAL5300 datasheet) ................................................................................. 25
Figure 31) PWM waveform ................................................................................................................... 29

vi

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

List of Tables
Table 1) 2N4403 On Characteristics...................................................................................................... 18
Table 2: Electrical Characteristics (R8C Manual) .................................................................................. 20
Table 3) 2N222A Saturation characteristics.......................................................................................... 21
Table 4) LED Operating characteristics (LED datasheet)....................................................................... 23
Table 5) IR diode characteristics (TSAL5300 datasheet) ....................................................................... 25

vii

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

1. Introduction
The purpose for this project was to design and build a security gate with infra-red remote
controller. The project required the synthesis of both hardware and software to create a fully
functional electronic controlled security gate system. Knowledge in electric circuits,
electronics, C++ format programming, and basic physics of a motor controlled gate was
mandatory to implement the final product.
The final product consisted of four main systems. The first system was the Main Board
where most of the operation controlled devices were situated. The Main Board functioned as
the user interface for calibration and maintenance purposes. The alarm sub-system was
situated on the Main Board, and could be reset on the Main Board. The access codes and
the real time clock were also situated on the Main Board. The Main Board allowed the user
to connect a computer to it via a serial USB connection. This capability allowed the user to
control the basic functioning of the Security Gate system. The user could display access
codes, erase access codes, sound the alarm and reset the alarm, switch the triac (courteous
lights) on or off, open and close the gate, accept new access codes by the IR (Infra-Red)
Remote Control, and lastly display the motor current. The Main Board could receive IR
(Infra-Red) command signals from the IR Remote Control. The Main board was directly
connected to the motor and gate system. Every time alarm sounded or the gate was opened
or closed by the remote control the data was logged in the onboard eeprom device for future
reference and security purposes.
The second system was the IR (Infra-Red) Remote Control. This system consisted of an IR
transmitter LED (Light-Emitting-Diode) which transmitted the remote signal via infra-red
waves. Three switches were situated on the remote which gave the user the option to control
the Gate Open/Closing, Sound the Alarm, Generate new access codes, or to reset the
remote control. The access codes for the remote were saved on an onboard eeprom device.
The battery life indication capability was included in the design of the remote control. The
battery life was received by the Main Board and logged in its database for future
investigation.
The third system was the software package specifically created for this product. The user
interface and the software package functioned together to create a product that could
respond effectively and efficiently to user defined commands. The user interface consisted
out of three divisions. The first division was the USB serial command interface. The second
division was the remote control user interface. The third user interface was the LCD (Liquid
Crystal Display) screen and command keys situated on the Main Board.
The fourth system was the Motor and Gate hardware which was directly connected to the
Main Board. The Motor was the driving force for the gate movement. The gate was created
to fit on a pulley system track which guided the gate to move in a linear direction to the open
and close states. A light sensor was positioned so that an appropriate response was sensed
and to stop the gate movement automatically when a close or open state was achieved.

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

2. System Description
The hardware configuration and description of the Main Board, IR Remote Control, and the
Gate systems are to follow in the following sections. The Security Gate system was a very
complex integrated design.
2.1 Main Board System Description
The Main Board system consist of various components which function together to form a
product that is fully integrated and easy to operate and to maintain. Refer to figure for the
overview of the product.

3
4
1
2

9
5

8
12

10
11

Figure 1) Main Board Illustration

Legend
1. R8C/27 Microprocessor
2. Voltage Regulator
3. USB interface (UART0)
4. LCD Screen
5. IR Receiver ( TSOP)
6. Eeprom (M24C64)
7. DMOS Full-Bridge Motor Driver (DRV8801)
8. MOC & Triac
9. Buzzer
10. Menu Keys
11. Optical Sensor
12. Op Amp

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

System Block Diagram

2kHz Buzzer
RS232/
USB Port

Reset

Programmer
Interface

FT232BL
USB UART

+
_

Voltage Regulator
5V DC Output

R8C/27
Microprocessor

LCD Screen

12V DC Supply

+
_

DVR8801 PWM
unit

Op Amp

Menu Keys

12V DC Motor
Test Input

+
_

Test Optical
Sensor

Triac

30V AC Supply

Infrared Receiver
Eeprom
M24C64

MOC

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

2.1.1 Microprocessor
The R8C/27 Renesas 16-bit single chip MCU microprocessor was used for the input and
output ports for the various components and control of the entire system. The R8C/27 unit is
fabricated using high-performance silicon gate CMOS process. [1] Typical applications for
the R8C/27 microprocessors involve electronic household appliances, office equipment,
audio equipment, consumer products, and automotive products.

Figure 2) R8C/27 Microprocessor, circuit diagram [2] & Illustration

The Microprocessor has 25 ports for I/O pins, an additional 8 I/O ports for LED drive ports, 4
timers (RA, RB, RC, and RE), 2 channels for Serial interfaces (UART0 and UART1), I2C bus
interface, A/D converter, 3 circuits for clock generation, voltage detection circuit, and a
power-on reset circuit.
2.1.2 Voltage Regulator
The Power supply to the Main Board is 12V DC (Direct Current). The 12V DC supply is
scaled down by the voltage regulator to ensure that no more than 5V reach the components
on the board. The R8C/27 microprocessor function around 3.5V to 5V of power supply
therefore the LM7805 voltage regulator will function as a safety mechanism to allow the
required amount of power to enter the circuitry of the Main Board.

Figure 3) LM7805 5V voltage regulator circuit diagram[2] & illustration

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

The maximum current output of the LM7805 is 1 A (ampere). This protects the system
components from melting or blowing up. The LM7805 has thermal overload protection and
short circuit protection capabilities. [3]
2.1.3 Universal Serial Bus
The USB (Universal Serial Bus) communication module allows the user to connect the Main
Board to a personal computer. The communication between the Main Board and a personal
computer is vital in the construction and design phases of the project. All the functions of the
board can be tested using the serial communication to a PC. Calibration and debugging
potential errors form part of the project design. The USB communication capability allowed
the user to demonstrate and simulate the functions of the Main Board using this technology.

Figure 4) Universal Serial Bus communication circuit diagram[2]

Figure 5) Universal Serial Bus communication

The FTD323 unit identifies itself as a USB serial port and can thus be used as a
asynchronous serial port. The FTD323 component has many features that is advantages to
the entire system. The FTD323 unit is compatible with eeprom functionality, has power
saving capability, has an Integrated Level Converter on UART interface and control signals,
and an Integrated Power-On-Reset (POR) Circuit. [4]

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

2.2 Main Board Sub-System Description


2.2.1 LCD Screen
The LCD (Liquid Crystal Display) screen acts as the visual stimules of the user interface.
The Menu system is displayed on the LCD screen and used to operate the Main Board
functions. The LCD used is a Hitachi HD44780 dot-matrix controller and driver component.
[5] The LCD screen driven by a 4-bit or 8-bit microprocessor. This particular LCD screen
displays two 8 character lines. The HD44780 LCD has lower power consumption
compatibility of 2.7 5.5 V which is ideal for our product specifications.

Figure 6) LCD screen circuit Diagram

Figure 7) Hitachi HD44780 LCD screen

2.2.2 Infra-Red Receiver


The IR Receiver we used was the TSOP1136 component. The IR Receiver is used in
remote control applications. The IR Receiver is a photo detector and has pre-amplification
capability. The component has CMOS compatibility which is a prerequisite for our product.
The advantages of this component is that is has high immunity to ambient light disturbances,
low power consumption, and shielding against electric field disturbances. The component
functions at a frequency of 36kHz. [6]

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Figure 8) TSOP 1136 IR Receiver

2.2.3 Eeprom
The Eeprom is an electrical erasable, programmable, memory device. The M24C64 eeprom
component was used to write and read saved data for the remote access codes and log
information for the remote and gate operation of our product. The component functioned at a
typical operating power of 5V. The life cycle of the component is more than a Million cycles
and have a lifespan of about 40 years. This component is therefore very reliable and robust.
[7]

Figure 9) Eeprom M24C64

2.2.4 DMOS FULL-BRIDGE MOTOR DRIVERS


The DRV8801 component was used to control the DC (Direct Current) motor for our gate by
implementing a PWM (pulse width modulation) signal. We were able to control the speed
and direction of the DC motor by using this device. We were able to measure the power the
motor was pulling with the DRV8801 component which was useful in detecting physical
obstructions when the gate was trying to open. The component was a low power
consumption unit and had short-to-ground protection. [8]

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Figure 10) DRV8801 PWM Full-Bridge Motor Driver Circuit Diagram [8] & Illustration

2.2.5 MOC & TRIAC


The MOC3023M device used was a optically isolated triac driving component which
functions on the principle of infrared light emitting diode and light activated switch
technology. This technology is used to control resistive and inductive loads which are driven
by AC (Alternating Current) voltage supplies. In our design we used the MOC3023M
component and a thyristor semi-conductor to drive the courteous/safety lights when the gate
is opened at night time. [9]

Figure 11) MOC & Triac Safety Light Circuit Diagram

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Figure 12) MOC & Triac Safety Light

2.2.6 Buzzer
The Buzzer is used as the alarm sounding device for the product we designed. The
Buzzer/Alarm was triggered when a remote, with wrong access codes, tried to access the
gate opening function 5 or more times. Or the Alarm sounded when the alarm key was
pressed on the IR remote. The operation frequency for the buzzer was 2kHz to achieve a
relatively easy to hear sound. The sound was distinguished as a sound that is annoying and
can be recognized as a alarming sound.

Figure 13) Buzzer Circuit Diagram & Illustration

2.2.7 Menu Keys


The Menu keys were installed near the LCD screen on the Main Board and functioned as
another user interface that is used to communicate with the menu operating system. The
menu was displayed on the LCD screen and controlled by the direction and select buttons of
the menu keys.

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Figure 14) The Menu Keys

2.2.8 Optical Gate Sensor


The optical gate sensor was used to sense when the gate was in a closed or opened
positioned. There were narrow slots cut into the gates surface which were used as
indicators for the optical sensor to determine the state of the gate.

Figure 15) Optical Gate Sensor circuit diagram & Gate optical sensor system

2.2.9 Motor
A 12V DC (Direct Current) motor was used to drive the gate system. The motors had speed
variation, directional change capability. The motor was not capable of driving a life size gate,
but was ideal for simulation purposes for the prototype gate design.
2.2.10 Operational Amplifier & A/D Converter
The operational amplifier strengthened the signal transmitted by the DRV8801 unit. The
R8C/27 internal A/D converter used the strengthened operational amplifier signal from the
DRV8801 PWM unit to determine the current the motor was using during operation. This
current reading was used to determine when unusual fluctuations would occur indicating that
the gate has been obstructed by an external object like a car or person. This unusual

10

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

fluctuation in current triggered the gate motor to stop, thereof allowing the object to be
removed or prevent further damage to be caused to the object by the gate.

Figure 16) Operational Amplifier (MCP6244)

2.3 IR Remote Control


The IR remote control was the primary user interface used to control the security gate
system. The IR remote control could open, close, and stop the gate by pressing the gate
button. The remote could also trigger the Main Board alarm in a situation of panic. The
option of generating new access codes for the gate was included in the remote. Once new
codes were generated by the remote no further access was allowed by security gate system.
Only when the command was given on the Main Board to accept the new access codes of
remote, would the specific remote be granted access. The following systems are included in
the IR remote control.

Figure 17) Infrared Remote Control

2.3.1 MICROPROCESSOR
The microprocessor used for the IR remote control was the same as the Main Board
(R8C/27). It was easy to synchronise and integrate the functioning of the Main Board and the

11

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

IR remote control because they functioned on the same principles by using the same
microprocessors and programming language.

Figure 18) R8C/27 Microprocessor located on IR remote control

2.3.2 VOLTAGE REGULATOR


The power supply to the remote control was a 9V DC battery. A 5V DC voltage regulator was
used to downscale the power supplied to the microprocessor. The LM2931 voltage regulator
component used was for the remote control. The LM2931 component is ideal for power
standby and battery operated systems. The components has a reverse battery installation
protection capability. [10]

Figure 19) LM2931 Voltage Regulator

2.3.3 IR LED
The IR LED used was the TSAL5300 component. The device has high reliability, radiant
power, and radiant intensity. The TSAL5300 is ideal for remote control applications where
relative far away distance control can be achieved. The TSAL5300 transmitter component
communicated with the Main Board TSOP1136 component receiver effectively.

12

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Figure 20) Infrared Light Emitting Diode

2.3.4 BUTTONS
The keys used for the IR remote control was the same as the buttons used on the Main
Board for the Menu control operating system. The keys were very rigid and seldom
experienced switch bounce. Switch 1 was used as for the gate opening and closing control.
Switch 3 was used for the alarm triggering control. To generate new access codes for the IR
remote control both switch 1 and switch 3 was pressed. Both switches had to be held in the
pressed in sate for 2 seconds before new codes were generated. The 2 second grace period
allowed the user to not accidently generates new access codes and therefore losing their
ability to grant access to the gate themselves. The new access codes had to be
synchronised at the Main Board system separately. This was designed as a safety
mechanism for the unwanted access of trespassers using the IR remote control.

Switch 3

Switch 1

Figure 21) Remote Control Switches (Buttons)

2.3.5 A/D CONVERTER


The internal A/D converter on the R8C/27 microprocessor was used to determine the battery
life of the IR remote control. The amount of voltage was calculated using the A/D converter
current sensing capability. We knew that full battery voltage meant that 9300mV was
supplied to the IR remote control. If the battery voltage decreased due to repetitive use of
the IR remote control the information would be sent via the IR signal to the Main Board for
logging purposes.

13

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

3. System Detail Design


The product required a detailed design in circuitry and software. The first detail design was
circuitry hardware planning and calculations. The second detail design was the software
development and initialisation of I/O (Input or Output) ports.
3.1 Hardware Calculations
A series of calculations were done to select resistors, capacitors, and electronic components
to achieve the response desired. Many electrical and electronic components were combined
to form a single sub-system. The following section will discuss the relevant calculations for
the sub-systems.
3.1.1 The MOC and Triac

Figure 22) TRIAC and MOC circuit (Blanckenberg,M, 2011:Lecture 6)

3.1.1.1 MOC
Refer to Appendix D, datasheet MOC3023M.

= 0.45V

Recommended operating

lies between max

= 5mA for

MOC3023M and absolute max

(Choose

( Acceptable for max

14

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

For typical V  1.15V


5  1,15  0,4
 I
340
I  10.15mA (We want this)
We used     (only available option)
5  1,5  0,45
 I
390
I  7,8 ( Acceptable for max V &  5 )

3.1.1.2 Triac
Refer to Blanckenberg lecture 6 notes.
V  3v !worst case*, Trigger Current  30mA, Trigger voltage  1,5V2
12  30m2 R 6  V  1,57
12  3  1, 5  302 86
86  250 (Choose 86  240 )
We used 9:  ;; due to availability
12  3  1,5
 Trigger current
86
86  220
Trigger current = 34mA (Acceptable,
>30mA)
3.1.2 Light Sensor

Refer to BPI-3C1-05 datasheet.


5  R< I=  V=>?@2  0
5  0,4
 8<
0,25
8<  18,5 A

15

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

If the transistor is in the on state R8C input pin will read 0,4V which is a logical zero.
If I  10mA, V  1,18V (from forward current vs forward voltage)
Typical V  1,2V
5RB I V = 0
5RB I 1,2=0
RB 

5  1,2
 380
10m

CD EFG
CD HEFG

 190 > (390)

We used 8<  18A


5  0,4
 I  25,5
18A
(Acceptable)

We used 8B  390
5  1,2
 I  9,7mA
390
(Acceptable)

16

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

3.1.3 A/D Converter (Main Board)

Refer to MCP6244 and DRV8801 datasheet. Also above figure was obtained using Blanckenberg,M
lecture 5 notes.
0,555V Measured2
5V  ampliLication 0,555V
AmpliLication  9
7MNOMP  7Q R
7G 
7G 

7  5 ST 8UVWUV

(8UVWUV  2,22

82 X 81
7Q
81

12A X 1,5A
7Q
1,5A

7G  9 7Q ( R1=1,5 k & R2=12 k )

17

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

3.2 Design for IR Remote


IT

Figure 23) IR circuit (Blanckenberg, M, 2011: Lecture 3)

Choose

, R1 needs to be big so that virtually no current flows through it.

We want Q1 to be in saturation. The emitter-base voltage drop for Q1 at saturation at the worst
case is
according to the 2N4403 transistor datasheet in Table 1. Assuming only one
button is pressed and choosing
to ensure that there is enough current for the other
components.

Table 1) 2N4403 On Characteristics

18

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Figure 24) Transistor Q1

Treating 81 as an open circuit and assuming only one button is pressed at a time (S1) and that Q2 is
the off-state (also an open circuit) one can make use of KVL (Kirchoffs Voltage Law). Using Figure
24 as reference:

7YZ[  7\] UZ[  ^_<Y 82  0

For saturation the design equation for `aV is:

`aV  10
From transistor laws its given that ^b  `aV ^Y . Therefore

^_<Y 

Sc
60

 6
10
`aV

With

7YZ[  97
7\] UZ[  0.95
^_<Y  6
82 

7YZ[  7\] UZ[


 1.34A
^_<Y

Therefore choosing 82  1.2A (which is a standard resistor) is acceptable and will only increase
^_<Y to 6.958. Choosing 83  1.2A as well will only double ^_<Y to 13.916 when both
buttons are pressed simultaneously. This will result in Sc  139.16. Referring to the datasheet
of the 2N4403, the absolute maximum rating is 500, so the operating conditions are safe from
damaging the transistor.
19

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

is chosen the same size as

&

to have almost the same current as when a button is pressed.

Q2
A

Figure 25) Transistor Q2

The voltage before

is:

Assuming both buttons are not pressed and that the R8C (with

according to the electrical characteristics in Table 2. The worst case for


which is found to be 1.2V.
Table 2: Electrical Characteristics (R8C Manual)

20

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

) gives an output of

is found in Table 3

Stuvia.com - The study-notes marketplace

Table 3) 2N222A Saturation characteristics

Figure 26) Transistor Q2 with Thevenin voltage and resistance

21

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Assume ^_Bb  6 for calculations. Therefore

^_BY 

6
 0.6
10

7f` in

Figure 26 could be found by the relation:

7f` 

1
8687
g
h 7i
87 86 X 87

7f` 

<
8f`7i
Nj

(1)

Choosing 87  1A and using KVL:

7f`  ^_BY 8f`  7]\ UZ[  0

(2)

Substituting (1) in (2)

1
8f`7i  ^_BY 8f`  7]\ UZ[  0
87
Substituting known values:

1
8f`32  0.628f`  1.2  0
1A
Solving for 8f`

8f` 

1.2
 500
3  0.6

Solving for 86 now that 8f` is known

86 
86 

878f`
87  8f`

1A20.5A2
1A  0.5A

86  1A
The chosen resistor 86 was 680. This choice was made by overestimating ^_BY and taking
7]\ UZ[ to be 0.6V (Table 3).
This however was not the design for the worst case as was done above.

22

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Referring to Figure 26, 7\k UZ[ from Table 1 is 7\k UZ[  0.47. Therefore the voltage on the collector

side of the transistor Q1 is 9-0.4=8.6V. The following circuit in Figure 27 is used in the calculation of
the resistor R9 for the LED. Vf is given in Table 4 for a typical current of 2mA, Vf=1.85V.
Table 4) LED Operating characteristics (LED datasheet)

Figure 27) LED circuit

Use KVL to determine R9

8.6  ^a 89  1.85  0
Choose ^a  2 (typ. Table 4)

89  3.375A
Choosing R9=3k9 (standard resistor)

^a  1.73

To determine R10 and R11 a voltage divider such as in Figure 28 are used to get Vout=5V

23

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Figure 28: Voltage Divider (adjusted figure Photoresistors, [S.a.])

7QW  8.67
Choosing 811  56A, and 810 is found by the formula in Figure 28.

810  40.32A
Choose 810  47A (standard resistor) to detect voltages higher than 8.6V (8.9V if Vbat=9300mV).

24

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Figure 29) IR diode circuit

Table 5) IR diode characteristics (TSAL5300 datasheet)

^_Eb (IF) is chosen to be 20mA, so that the radiant intensity is little less that 10mW/sr (Figure 30)
which is more than what is required for the IR Receiver to see the transmitted data at a range of
2m.

Figure 30) Radiant Power (TSAL5300 datasheet)

Therefore ^_EY  2 (design hfe=10). Taking the R8c output (Figure 29) to be 3V and 7]\lmn  1.27
again like before for the 2N222A transistor, R12 can be calculated.
25

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

3  ^_EY 812  7]\lmn  0


3  22812  1.2  0
812  900
Choose 812  830 (standard resistor)
This will increase ^_EY to 2.16mA. Therefore new ^_Eb  102.162  21.6.
R13 is calculated by taking the KVL on the path that ^_Eb and the emitter current follows. The
IR-emitter forward voltage VF=1.6 (worst case) in Table 5 and 7k\lmn from Table 2: Electrical
Characteristics (R8C Manual)
for the 2N222A transistor is 7k\lmn  0.37

8.6  7o  ^_Eb 813  7k\lmn  0


8.6  1.6  21.62813  0.3  0
813  296
Choose 813  330 (standard resistor)

26

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

4. Programs
4.1.1 Mainboard Pin Assignments











5 digital input pins for buttons


7 digital input/output pins for LCD
1 digital input pin for light sensor
2 pins for EEPROM (2 I2C ports)
2 output pins for Motor Controller (1 Pulsewidth modulator output and 1digital output pin
for direction)
1 digital output pin for buzzer
1 digital output pin for MOC3028
1 analogue input pin for A/D converter for motor current
1 digital input pin for Infrared Receiver

4.1.2 Infra-Red Pin Assignments

 2 digital input pins for the 2 buttons


 2 pins for EEPROM (2 I2C ports)
 1 digital output pin for Infra-Red diode

27

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

4.2 Software Calculation Design of Mainboard


4.2.1 U0brg, UART0 serial port bit rate:
The design required the USB interface to operate at a BAUD rate of 38400 bits/second. The selected
clock speed is the internal clock speed of p< = 20MHz. Thus,

q0rst 

p<
20y
1
 1  31.552  20z
u^f 8vfw x 16
38400 x 16

4.2.2 U1brg, UART1 serial port bit rate:


To interpret the data from the infrared receiver, a normal serial protocol is used. The UART1 is set up
so that 7 cycles could be read for a frequency of 36,6 kHz.

36600
 5228.7 { 5230rv|}
7
Therefore:

q1rst 

p<
20y
1
 1  238.006  ~~z
u^f 8vfw x 16
5230 x 16

4.2.3 Buzzer frequency


A square waveform of frequency of 2 kHz is required therefore the pF = 2.5MHz has been selected. To
calculate the primary period in this case is half of the period. Thus the primary and secondary
periods are equal thus p = m.

ws^i} 

2 X 12 X 12
p<

1/2000 

2 X 12 X 12
20 x 106

Choose n=99

  49

Thus n = 99, m = p =49. In the registers: n = TRPRE, m = TRBPR and p = TRBSC


4.2.4 PWM
Timer RC is set up so that it is in PWM mode, for controlling the motor. The specification is that the
frequency of the pwm signal must be between 35 and 45 kHz and the mark space ratio must be
adjustable in steps smaller than 2% between a nominal 0% and 100%.

28

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

The PWM period is given in Figure 31 by:

1
x  X 12
p

Choosing the period T=24us which corresponds to a frequency of 41.66kHz and selecting p  pB 
10y`,now substituting the known values in the formula to get m:

24 

1
x  X 12
10 x 106

m=239
Therefore the value of 0xEF (239 in hex) is applied to register TRCGRA.

Figure 31) PWM waveform

The value of n could then be determined by:


n=(pulsewidth*m-100)/(100+pulsewidth)

where pulsewidth is the mark space ratio (in percentage).


The value of n is then stored in register TRCGRB

29

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

4.3 Software Calculation Design of IR Remote


4.3.1 Infrared 36kHz waveform
A 36kHz waveform is required for the infrared diode, so that the infrared receiver could register the
transmitted data. From the R8C Hardware Manual (2007:166) the period, primary period and
secondary period is given. Setting m=p, the period is:

2 X 12 X 12
p<

1
2 X 12 X 12

36A
20 x 106
Choosing n = 68
From the above equation m could be found as

  3.03
Therefore

{3

Register values should be


TRBPRE=68
TRBPR=3
TRBSC=3

4.3.2 Automatic Power On/Off


For Infrared remote to power off automatically after a button was pressed, a timer is initiated, timer
RA. This timer is set up for 5230 baud.
p<
 rv|} svfw
 X 12 X 12
Choosing n=61
20 x 106
 5230
61 X 12 X 12
  60.67 { 61

30

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

4.4 Software Design of Mainboard

4.4.1 Initialization in main()


oscillator_initialise(); //Initializes the high speed on chip oscillator
timer_re_initialise(); //Initializes the real time clock
timer_b_initialise(); //Initializes a square waveform of 2kHz for the use of the buzzer
timer_a_initialise (); //Initializes timer a for the use of the accelerating the gate
ports_initialise(); //Initializes all of the needed input/output ports
serialport_0_initialise(); //Initializes UART0 for communicating to PC via USB
serialport_1_initialise(); //Initializes UART1 for receiving data from infrared remote
lcd_initialise(); //Initializes the lcd
i2c_initialise(); //Initializes the i2c port for eeprom
timer_c_pwm(); //Initializes timer c for the use of pulsewidth modulation for the motor

4.4.2 Initialized in ports_initialise()


port_3_initialise() //Initializes port p1_3 for the use of the LED
more_ports_initialise() //Function to initialise all the rest of the ports needed
ad_conv_initialise() //Initializes the A/D converter

4.4.3 Serial port


void serialport_0_byte_send (char byte); //Sends one byte to PC via USB by using UART0
void send_string(char array_str[]); //Sends a string to PC via USB by using UART0
4.4.4 LCD
void lcd_instruction_nibble_write(char nibble_in); //Function is used in initializing the LCD, 4 output
ports are controlled by the parameter.
void ms_5_delay(void); //5 ms delay, also used when initializing the LCD.
void lcd_not_busy_wait(void); // waits until the LCD busy flag resets
void lcd_instruction_write (char instruction); // writes an instruction to the LCD
31

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

void lcd_character_write (char character); // writes a charcter to the LCD and increments the cursor
position
void lcd_left_scroll (void); //scrolls the characters on the LCD one position to the left
void lcd_right_scroll(void); //scrolls the characters on the LCD one position to the right
void lcd_scrn_clear (void); //Clears the screen of the LCD and resets the cursor position to 0
void lcd_write_string(char data_str[]);//Function to write whole strings to lcd
void lcd_log_write_char(char character);//Function for writing characters to lcd with the use of an
external variable
void lcd_log_write_string(char data_str[]);//Function for writing whole strings to lcd with the use of
an external variable

4.4.5 EEPROM
void nackORcomplete(void); //Includes a 6 instructions that has to happen in eeprom_write and
eeprom_read.
char eeprom_write(char eeprom_address,unsigned int data_adress, char data); //Writes one byte
(data) to a specific address (data_adress) in the eeprom.
char eeprom_read(char eeprom_address,unsigned int data_adress, char *data); //Reads one byte
(*data) from a specific address (data_adress) in the eeprom.
void eeprom_read_all(void);//Reads all the eeprom addresses that are used and sends the data to
the PC.
void eeprom_erase_all(void);//Erase all the eeprom addresses that are used (by writing FFH to all of
them).
char eeprom_determine_empty(char log_address);//Determines if a certain address is empty
4.4.6 PWM
void pwm_generate(char direction, unsigned int pulsewidth); //Calculates the number that should
be written in the trcgrb register and writes it to the trcgrb register. The parameter pulsewidth, is the
mark space ratio and direction is either 1 for forward or 0 for reverse.
4.4.7 Triac
void triac_on(void);//Triac is activated by setting a pin to 0
void triac_off(void); //Triac is deactivated by setting a pin to 1
char night_time(int evening_time[],int morning_time[]); //Function to determine if the real time falls
between the evening time and the morning time.
32

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

4.4.8 Light sensor


char lightsensor_state(void); //Function that determines if the lightsensor is interrupted

4.4.9 Real Time Clock


void setTime (int hour, int min, int sec);//Function to set the real time clock
int* getTime (void);//Reads the relevant registers for determining the current real time
void Time_display(void);//Function used to write the time to LCD
char* get_mor_eve_time(void);// Fetch morning and evening times saved on the eeprom
void write_mor_eve_time(int time_array[], char mor_eve);// save the morning and evening time
information to the eeprom

4.4.10 Infrared functions


char msb_check(char ir_first_byte); //check for the most significant bit of ir_first_byte, returns 0 if
the MSB is 0.
char controller_check(char ir_first_byte); //Function to determine the controller number
char alarm_check(char ir_first_byte); //Determines if alarm button is pressed on IR-remote.
Alarm_check will return with zero if alarm is activated
char battery_voltage(char ir_first_byte);//Converts the 5 bits determined by the AD converter on the
IR-remote to a numerical value.
void write_remote_cntrl_eeprom (char remote_byte1, char codes[]); // writes access codes for
remote to allocated space in eeprom
char* read_remote_cntrl_eeprom (char remote_byte1);// reads remote access codes for the
corrosponding eeprom remote location

4.4.11 Menu
void menu_initialise(void);//Initializes the menu. This is a very big function and calls quite a few
functions as well.
void main_menu(char main_menu_sel);//Case statements are used to determine what is to be
displayed on the LCD.
void reset_alarm(void);//Resets the alarm and exit the menu
33

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

char enter(void);//Function to determine if the enter button is pressed (returns 1 if pressed)


char down(void); //Function to determine if the down button is pressed (returns 1 if pressed)
char up(void); //Function to determine if the up button is pressed (returns 1 if pressed)
char left(void); //Function to determine if the left button is pressed (returns 1 if pressed)
char right(void); //Function to determine if the right button is pressed (returns 1 if pressed)
void dummy_time_display(int time_array[]); //Displays the time on the LCD for the user to edit from
the menu.

4.4.12 Display Log


char current_log_address(void); //current_log_address will return an int in the range of 0 to 9 (for
the 10 logs). This is the number of the last recorded log
void write_log(char log_write_address, char ir_byte1,char invalid);
to certain addresses in the eeprom

//Function to write the log

void read_log_lcd(char log_read_address);


//Function to read the log to certain addresses in
the eeprom and display one log at a time on the LCD
void log_time_display(int time_array[]); //Similar to Time_display(), only implements an external
variable so that a whole log could be written on the LCD.
void serial_time_display(char time_array[]);//Similar to Time_display(), only instead the output is
send via the serial port to PC.
void read_log_serial(char log_read_address); //Function to read the log to certain addresses in the
eeprom and sends all the last logs via the serial port to PC to be displayed on hyperterminal.

4.4.13 Motor Current


char motor_current(void); // determine the current the motor is using by reading the A/D converter
register and converting the byte to a numerical value.
void serial_port_motor_current(char current); //converts numerical motor current value to ascii and
send the value via serial port to the PC.

34

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

4.5 Software Design of Infrared Remote

4.5.1 Initialization in main()


oscillator_initialise(); //Initializes the high speed on chip oscillator
timer_b_initialise(); //Initializes a square waveform of 2kHz for the use of the buzzer
timer_a_initialise (); //Initializes timer a for the use of the accelerating the gate
ports_initialise(); //Initializes all of the needed input/output ports
i2c_initialise(); //Initializes the i2c port for eeprom

4.5.2 Initialized in ports_initialise()


void port_0_initialise (void); //Initialize port p0_3 that is used for the automatic power on/off circuit
void port_3_initialise (void); //Initializes port p1_3
void ad_conv_initialise (void); //Initializes the A/D converter pin

4.5.3 Serial port


void byte_send (char byte);//Infrared function that transmits one byte
void send_bit(int bit); //Function to check the bit and activates the 36kHz signal or deactivates it
void Button_Pressed (char Bat_Alarm, char code1, char code2, char Checksum);//Transmit 4 bytes
needed to control the gate or activate the alarm.
ms_5_delay(); //5 ms delay used in between transmitting bytes via infrared

35

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

4.6 System Flow Diagram

36

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

4.7 Interrupt Flow Diagram for Mainboard


Each of the following 4 processes in the figure below causes an interrupt. What the
processes does follows
ws in the figures thereafter.

Uart0_receive

Uart1_receive

Timer RE

Timer Ra

Interrupt

Timer RE

sec++

Time display on LCD


each second if not in
menu

Triac 10 second on
timer if gate is opened
at a certain time
interval

37

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Controller number
display on LCD if
remote is used

Stuvia.com - The study-notes marketplace

Uart0_receive

command=u0rb

If @

If !

Normal mode

Test mode

Doesn't accept any


commands except
for '!'

Accept certain
commands, to test
certain function

38

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Uart1_receive

ir_command=u1rb

store ir_command in a
buffer array

ir_receive_index++

Check if first element


of array's MSB=0

If it's not, reset


ir_receive_index to 0

If it is

Check if 4 bytes are


received

If it's not, wait for next


byte

If it is

Check if checksum
equals that of the
checksum from IRRemote

If it is, ir_flag=1, to
execute ir commands
in main

If it's not, reset


ir_receive_index=0

39

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Timer RA

Control the gate speed, by


incrementing a variable
gate_speed at a certain
time when interrupt occurs

40

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

4.8 Interrupt Flow Diagram for IR Remote

The only interrupt on the remote is Timer RA.

Timer
Ra

Interrupt

Timer RA

ra_flag++ (used for


determining the
power on time)

Check if the two


buttons are held in
for 2 seconds

41

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

5. Measurements and Results

Both of the designed boards were identical in terms of resistance values and other components.
Therefore the measurement didnt deviate from one another on a noticeable level. The inclusion of
one set of measurements is submitted in the report to avoid redundancy. Although both
measurements were done, the data could not be captured by the oscilloscope due to storage issues
(did not have a small enough flash drive) on the day of obtaining the results of the one board. The
measurements that follow were taken on the 13th of May where a small enough flash drive was
borrowed. On that day only one board was present.
5.1 Supply Voltage

The Supply voltage to the Main Board is 12V DC(Direct Current). The 12V DC supply is
downscaled by the 5V voltage regulator to the microprocessor and rest of the board
components.

5.2 Buzzer

The buzzer was designed to function at a frequency of 2kHz. The figure below shows the
output response for the buzzer signal waveform, which is slightly more than 2kHz.

42

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

5.3 Pulse Width Modulation

The pulse width modulation signal was designed to function at a frequency of 41.6kHz. The
figure below demonstrates the output response of a fully generated output signal to the
motor controller and the figure that follows, shows the signal that goes from the mot
controller to the DC motor.

43

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

5.4 The IR remote control Signal output

The remote control generates a sequence of 4 bytes as the output signal which was sent to
the IR receiver located on the Main Board. The figure below demonstrates what the first byte
appeared like for the specific remote control and battery voltage. The IR receiver inverts and
decodes the the IR transmitted signal from the remote control. Therefore the IR receiver
signal will be the inverse of the figure below.

The figure below demonstrates the inversed signal at the IR receiver side located on the
Main Board.

44

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

6. Conclusion

The objectives of the project were achieved. The Remote control operated Security Gate
System was a fully operational prototype model which demonstrated the full functionality of
the user requirements.
The Main Board operated in a manner that was user friendly with the addition of an onboard
menu controlled system. The Menu system user interface allowed the user to experience a
two directional communication channel. The user could input information via the menu keys
and at the same time receives feedback via the LCD screen. This gave the user the feeling
of sophisticated interaction between machine and human.
The additional USB communication channel was well structured and easy to use for testing
and debugging purposes. This feature allowed the user to connect and control the Main
Board via a computer. All of the functionality customer requirements were achieved in this
section.
The Infrared Remote Control user interface acquired a feeling of quick response times and
good communication to the Main Board. The random code generation function was
successful and the switches sent the correct information.
The Motor Gate driven simulation system was however flimsy and was difficult to operate.
This part of the product was however not part of our division of design. It was learnt that
calibration and integration of external designs are time consuming and difficult to achieve. It
was important to attain the necessary information about external divisional designs that are
co-dependent on our design. Our light sensor calibration response was not ideally setup. A
few minor tweaks would have ensured proper functionality. For the demonstration purposes
the light sensor worked fine.
The overall outcome of the project was very successful and educational.

45

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

7. References

[1]

R8C/26 Group, R8C/27 Group, Hardware Manual, Rev.1.30, Revision Date: Jun 01,
2007, www.renesas.com

[2]

Design(E) 414 Lecture notes, Dr. M Blanckenberg, 2011.

[3]

LM7805 3-Terminal 1A Positive Voltage Regulator, 2001 Fairchild Semiconductor


Corporation, Rev. 1.0.1.

[4]

FT232BL USB UART ( USB - Serial) I.C., DS232BL Version 1.8, Future Technology
Devices Intl. Ltd. 2005

[5]

Hitachis HD44780 dot-Matrix LCD driver and Controller.

[6]

IR Receiver Modules for Remote Control Systems, Vishay Semi-conductors,


Document Number 82006, Rev. 12, 23-Jun-03.

[7]

128 Kbit, 64 Kbit and 32 Kbit serial IC bus EEPROM, December 2007, Rev 12.

[8]

DMOS FULL-BRIDGE MOTOR DRIVERS, DRV8801, SLVS855E JULY 2008


REVISED OCTOBER 2010, Texas Instruments.

[9]

6-PIN DIP RANDOM-PHASE OPTOISOLATORS TRIAC DRIVER OUTPUT (250/400


VOLT PEAK), 2003 Fairchild Semiconductor Corporation

[10]

LM2931 Series Low Dropout Regulators, 2006 National Semiconductor Corporation.

[11]

Photoresistors, [S.a.]. [Online]. Available:


http://web.mit.edu/rec/www/workshop/photoresistors.html [2011,May 14]

46

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Appendix A

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

USER MANUAL
THE MENU

UP

ENTER
LEFT

RIGHT
DOWN

Figure 1) The user interface (LCD screen & Main board control keys)

Normal mode:
Time display (Hours: Minutes: Seconds)
To enter the menu press the ENTER button on the user interface while in normal mode.
Example:
( Hours : Minutes : Seconds)

Menu Mode:
1)
2)
3)
4)
5)
6)

Reset Alarm/Err
Time Settings
Open Close gate
Accept Codes
Display Log
Exit Menu

To exit the menu scroll down the menu options, and press the ENTER button on the
option.

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

THE MENU
MENU

FUNCTION

CONTROL

1) Reset
Alarm/Err

Reset the buzzer after alarm has sounded.


Alarm is triggered by the remote alarm button
or invalid codes received from the remote.

1) ENTER (Alarm reset, returns to


Normal mode)

2) Time Settings

Time Settings Sub-Menus:


2.1) Set Time
2.2) Set Evening
2.3) Set Morning
2.4) Back to Menu

2.1) Set Time

Set the clock. Set hours, minutes and seconds


of clock.

2.2) Set Evening

Used to control courteous gate light (triaclamp) on time. Controls when the lamp must
be switched on when the gate is opened via the
remote or the main board. The Evening time is
stored in the eeprom.

2.3) Set Morning

Used to control courteous gate light (triaclamp) off time. Controls when the lamp must
be switched off when the gate is opened via
the remote or the main board. The Morning
time is stored in the eeprom.

2.4) Back to Menu

Returns to the Main Menu

1) ENTER (enter time settings SubMenu)


2) UP/DOWN (scroll through time
settings Sub-Menu options)
3) ENTER (select Sub-Menu time
settings option, follow
sections 2.1 - 2.4)
1) UP/DOWN (Hours set)
2) RIGHT/LEFT
(Minutes/Seconds/Hours select)
3) UP/DOWN (Minutes/Seconds/
Hours set)
4) Repeat steps 3-4 until finished
5) ENTER ( New time set, & Exits to
Normal mode)
1) UP/DOWN (Hours set)
2) RIGHT/LEFT (Hours/Minutes
select)
3) UP/DOWN (Hours/Minutes set)
4) Repeat Steps 2-3 until finished
5) ENTER (Evening time set, and exit
to Normal Mode)
1) UP/DOWN (Hours set)
2) RIGHT/LEFT (Hours/Minutes
select)
3) UP/DOWN (Hours/Minutes set)
4) Repeat Steps 2-3 until finished
ENTER (Evening time set, and exit
to Normal Mode)
1) ENTER (Returns to Main Menu)

3) Open Close
Gate

Controls the opening and closing of the gate.


The state of the gate will change depending on
whether the gate is open or is close.

1) ENTER (Opens/Close Gate & Exits


to Normal Mode)

4) Accept Codes

Main board receives new access codes from the


remote controller. Used to synchronise new
access codes of the Remote with the Main
board. The new remote codes are saved on the
main board.

1) ENTER ( Saves the latest remote


control access code to main
board authorisation eeprom
data)

5) Display Log

The remote log data is displayed on the LCD


screen. The 10 most recent logs are displayed.

1) ENTER (Log displayed)


2) RIGHT/LEFT (scroll through
current log information)
3) UP/DOWN (scroll through logs 0
to 10)
4) ENTER (Exit to Normal Mode)

Example:

6) Exit Menu

To exit the Menu and return to Normal Mode.

1) ENTER (Exit to Normal Mode)

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

USB COMMANDS
CODE
@
!
#
$
%
^
&
*
(
+
-

ACTION
Normal Mode.
Test Mode. The commands below are valid during the test mode
Open/Close/Stop the gate
Transmit motor current to PC (e.g. 100 mA)
Alarm on
Alarm off
Triac on (courteous light on)
Triac off (courteous light off)
Transmit log information to PC
Erase all logs
Display allocated saved eeprom data

REMOTE COMMANDS
COMMAND

ACTION

Switch 1 (S1)
Switch 3 (S3)
Switch 1 & Switch 3

Open/Close Gate
Trigger Alarm
Generate new access code for remote
(Press Switch 1 & Switch 3 simultaneously for 2 seconds)

Reset

R8C/27

S3

S1

IR-Diode

Infra-Red Remote Signal

Figure 2) Remote control user interface

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Appendix B

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Technical Specifications
Power Supply:
Input voltage:
Min Current:
Max Current:
Max Power consumption:
Triac Current

12V (typical)
0.5A (Idle state)
0.7A (motor activated)
11W
1.8A

Computer Communication:
Universal Serial Bus
Bit Rate: 38400 baud
Clock Frequencies:
Chip internal clock:
Buzzer Frequency:
PWM

20MHz max
2.2kHz
41.66kHz

IR Remote Control
Communication distance

2.8m

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Appendix C

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Mainboard
Main.c
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

"sfr_r827.h"
"oscillator_timers.h"
"ports.h"
"lcd.h"
"serial_port.h"
"i2c.h"
"eeprom.h"
"PWM.h"
"rtclock.h"
"menu.h"
"triac.h"
"lightsensor.h"
"display_log.h"
"motor_current.h"
"ir_funcs.h"

//special function registers

extern volatile char sec;


//globale veranderlike in 'n ander
ler verklaar / global variable declared in another file
//note: "volatile" as it can be
changed as a result of an interrupt
volatile char gate_control = 0;
// acceleration of gate motor initialy
zero
volatile char open_close = 0;
//Initially closed
char gate_location = 1;
//The first gap in gate (Starting
position)
char current;
// motor A/D
converter current variable
extern volatile char ir_flag;
extern volatile char ir_command_buffer[4]; // receive buffer for remote signal,
Bat/Alarm, code1, code2, checksum
char correct_code_flag = 0;
char wrong_code_counter = 0;
//Variables for accepting new codes
char new_codes[2]; // new code generation array variable
char remote_byte_one;
main()
{
int i;
int k;

//Initializes all of the written functions


oscillator_initialise();
timer_re_initialise();
timer_b_initialise();
timer_a_initialise ();
ports_initialise();

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

serialport_0_initialise();
serialport_1_initialise();
lcd_initialise();
i2c_initialise();
timer_c_pwm();
//initial time allocation 14:00:00
setTime (14,00,00);
(hours:minutes:seconds)
log_index = current_log_address(); //Retrieve the next address for writing the log
from the eeprom
for(i=0;i<=2;i++) //Get saved morning and evening time from eeprom
{
mor_time_arr[i] = (get_mor_eve_time())[i]; // morning time saved in eeprom
eve_time_arr[i] = (get_mor_eve_time())[i+3]; // evening time saved in
eeprom
}
//WHERE EVERYTHING IS DONE
while (1)
{
//LED FLASH
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if (sec%2 == 0)
//Flits die LED een keer per
sekonde. Flashes the LED once per sec
{
p1_3 = 0;
}
else
{
p1_3 = 1;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

/******************************************************************************/
/*
MENU
*/
/******************************************************************************/
menu_initialise();

/******************************************************************************/
/*
Open/Close Gate
*/
/******************************************************************************/

if (gate_flag == 1)
{

//Gate Control
//*****************************************************************************
if (gate_control == 0) //If gate is in stop position

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

{
//Acceleration control
gate_control = 1; //Accelarates from zero to full speed (This
activates the speed ramp)
//Direction control
if (open_close == 0)
{
open_close = 1;
//Sets the direction into the
opposite direction as initially stated
}
else if (open_close == 1) // the direction changes once more,
everytime the function gets called
{
open_close = 0;
}
}
if (gate_speed != 0 && gate_control == 1) // Stops when given a
command if the gate is still moving
{
gate_control = 0; //Stop Accelerating
gate_speed = 0;
}
//*******************************************************************************

//Triac Automatic On/Off


//*******************************************************************************
if(night_time(eve_time_arr,mor_time_arr)==1) // checks if the
current time is night time, returns 1 if night time
{
triac_auto_on_off_flag = 1; //switch curteous lights on if the
above function returns a 1 for night time
}
//*******************************************************************************
gate_flag = 0;
} //end if (gate_flag == 1)
pwm_generate(open_close,gate_speed*10); // function to used to read
direction of motor rotation, and speed of motor
//********************************************************************************
//End of Open/Close Gate

/****************************************************************************/
/*
Light sensor
/****************************************************************************/

*/

if (lightsensor_state() == 1) //Checks the state of the light sensor


{

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

if(open_close == 1 && gate_control == 1)//Check to see if gate is


opening and moving
{
gate_location++;
if(gate_location == 10) //End of gate
{
//Stop the control of gate
gate_control = 0;
gate_speed = 0;
//Stops the gate
} //end if (gate_location == 10)
}//end if (open_close == 1)
if (open_close == 0 && gate_control == 1) // check see if gate is
moving in opposite direction and open
{
gate_location--;
if(gate_location == 1) //End of gate
{
gate_speed = 0;
//Stops the gate
gate_control = 0;
//Stop the control of gate
} //end if (gate_location == 1)
}//end if (open_close == 0)
}

//End of Light Sensor


/****************************************************************************/
/*
IR REMOTE
/****************************************************************************/

*/

if (ir_flag==1) //True if first byte's MSB = 0 , correct 4 bytes are


received and correct checksum is received
{
for (i=0;i<=1;i++)
{
if (ir_command_buffer[i+1] ==
(read_remote_cntrl_eeprom(ir_command_buffer[0]))[i]) // check if the remote control codes
correspond to the saved codes on the eeprom on the main-board for the specific remote
control
{
correct_code_flag = 1; // if codes check out, then
access granted
}
else
{
correct_code_flag = 0; //access not granted
break;
}
} //end for
if (alarm_check(ir_command_buffer[0]) != 0 && correct_code_flag ==
1) //Alarm not activated, Usual open/close gate command
{
gate_flag = 1;

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

//Writing to log
write_log(log_index,ir_command_buffer[0],0); //2nd parameter
of function is if the code was valid (0, if valid code)
log_index++;
if (log_index >9) //if log_index==9, set back to 0
{
log_index = 0;
}
} //end of if (bat_voltage_check != 0)
else if (alarm_check(ir_command_buffer[0]) == 0 && correct_code_flag
== 1) //Alarm activated
{
buzzeron(); // sound alarm
} //end of if (bat_voltage_check == 0)
else if (correct_code_flag == 0) //Not correct code
{
//Writing to log
write_log(log_index,ir_command_buffer[0],1); //2nd parameter
is if the code was valid (1, if invalid code)
log_index++;
if (log_index >9) //if log_index==9, set back to 0
{
log_index = 0;
}
//Saving codes just received to external variable
for (i=0;i<=1;i++)
{
new_codes[i] = ir_command_buffer[i+1]; //store remote
codes in new variable that is to be used in menu.c to accept new codes.
}
remote_byte_one = ir_command_buffer[0];
if(wrong_code_counter++ >=4) // if the codes of the remote
don't check out 5 times then sound alarm
{
buzzeron(); // sound alarm
wrong_code_counter = 0; // reset counter for wrong
codes
}// end if (wrong_code_counter++ >=5)
}// end else if
ir_flag = 0; //Sets flag to zero again.
} //end if (ir_flag==1)
//End of IR REMOTE
/****************************************************************************/
/*
SERIAL COMMANDS
/****************************************************************************/
if (command_flag==1)
{

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

*/

Stuvia.com - The study-notes marketplace

command_flag=0;
switch (command)
{
case '#':
gate_flag = 1; // open/close the gate, refer to
break; //end of case '#'
case '$':
current = motor_current(); // read the current drawn by
the motor
serial_port_motor_current(current); // send the current
drawn by the motor via serial communication
break;
//EEPROM ERASE
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%
case '+':
eeprom_erase_all(); // erase all the stored information
on the eeprom , logs, remote codes etc.
while (eeprom_write(0xA0,40,0)==0); //Writes 0 to
address 40 of eeprom
log_index = 0;
break;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%
case '-':
eeprom_read_all(); //Read first 57 addresses of eeprom
break;

case '(':
//Send Log to PC via USB in chronological order,
from newest first to oldest last
//The current read address is
k = log_index-1;
log_index(the next write address) - 1
//Set i = k
i = k;
for (k;k>=0;k--)
//Send logs to usb from newest to
oldest
{
read_log_serial(k);//log read function for
sending it to pc
}
if (k<=0) //if k<=0 set k = 9 and check if eeprom
address is not empty and send to PC
{
k = 9;
while(k>i && eeprom_determine_empty(k)==0)
//while not empty
{
read_log_serial(k);
k--;
}
}

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

break;
//BUZZER COMMANDS
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%
case '%':
buzzeron();
//switch buzzer on
break;
case '^':
buzzeroff(); //switch buzzer off
break;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%

//TRIAC COMMANDS
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%
case '&':
triac_on(); //Triac on
break;
case '*':
triac_off(); //Triac off
break;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%
} //End of switch
} //End of command_flag if
//End of SERIAL COMMANDS
}
}

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Display_log.c
#include
#include
#include
#include
#include
#include
#include

"eeprom.h"
"lcd.h"
"menu.h"
"display_log.h"
"ir_funcs.h"
"rtclock.h"
"serial_port.h"

volatile int lcd_address_counter = 0;

char current_log_address(void)
//current_log_address will return an int in the range
of 0 to 9 (for the 10 logs). This is the number of the last recorded log
{
char eeprom_data;
char *eeprom_data_ptr = &eeprom_data;
char address;
while (eeprom_read(0xA0,40,eeprom_data_ptr)==0); //Last written address is stored
in address 40
address = eeprom_data;
return address;
//address
which is a char
}

void write_log(char log_write_address, char ir_byte1,char invalid) //log_write_address is


the next address to be written on
{
int eeprom_address = log_write_address * 4; //This is the address range to be
written to
int time_integer[3];
char controller_nr;
char write_four_bytes[4];
int i;
//Write the next addresses to write to, to a specific address in the eeprom
if ((log_write_address+1)>9)
{
while (eeprom_write(0xA0,40,0)==0);
}
else
{
while (eeprom_write(0xA0,40,(log_write_address+1))==0); //Write the address
(From 0 to 9) to address 40 in eeprom so that if board loses power, function
current_log_address() could recover the last written to address
}
for (i=0;i<=2;i++)
{
time_integer[i] = (getTime ())[i];
//receive time from timer RE register (must be int)

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

}
for (i=0;i<=2;i++)
{
write_four_bytes[i] = (char)time_integer[i];
int to char
}

//Converting

if (invalid==1)
{
write_four_bytes[3] = 0xFF;
//Indicates invalid code
}
else
{
write_four_bytes[3] = ir_byte1;
//Stores the first byte received from remote, that indicates battery voltage and
controller number to the 4th element of array
}
for (i=0;i<=3;i++)

//Write all four elements of array to specific addresses in

eeprom
{
while (eeprom_write(0xA0,eeprom_address,write_four_bytes[i])==0);
eeprom_address++;
}
}
void read_log_lcd(char log_read_address)
{
char eeprom_data;
char *eeprom_data_ptr = &eeprom_data;
int eeprom_address = log_read_address*4; //Address of log
int log_array[4]; //array for temporary storing eeprom data
char time_byte[3];
int time_integer[3];
int lcd_address_counter = 0;
//Sets the global variable to 0 everytime
function is called
int i;
char control_number;
char voltage;
char volt_ascii[2];
lcd_scrn_clear(); //Clear the screen and sets DDRAM address of LCD to zero
for (i=0;i<=3;i++)
{
while (eeprom_read(0xA0,eeprom_address,eeprom_data_ptr)==0);
log_array[i] = eeprom_data; //Reads the data in eeprom and store it in
array
eeprom_address++;
}
for (i=0;i<=2;i++)
{
time_byte[i] = log_array[i]; //Time array
}

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

for (i=0;i<=2;i++)
{
time_integer[i] = time_byte[i]; //Converts char to integer to display on
lcd
}
lcd_log_write_string("Time=");
log_time_display(time_integer);
lcd_log_write_string(" Controller=");

//Displays a string Time =


//Displays the time
//Displays a string Controller=

if (log_array[3] == 0xFF)
{
lcd_log_write_string(" invalid"); //Writes invalid as controller 5 invalid
codes with valid checksums received
}
else //Code for dispaying controller number and battery voltage
{
control_number = (controller_check(log_array[3])+'0'); //Check the last 2
bits of the 1st byte received from the infrared controller to determine the controller
number
lcd_log_write_char(control_number);
voltage = battery_voltage(log_array[3]);
volt_ascii[0] = (voltage/10) + '0';
//converting decimal to ascii (first digit)
//converting decimal
volt_ascii[1] = voltage-(voltage/10)*10 + '0';
to ascii (second digit)
lcd_log_write_string(" Volt=");
for (i=0;i<=1;i++)
{
lcd_log_write_char(volt_ascii[i]);
voltage characters to lcd
}

//write two

lcd_log_write_string("00 mV");
//writes 00mV after previously written characters
} //end else
//example: Time = 09:30:50 Controller = 1 Battery voltage = 8700 mV
}
void read_log_serial(char log_read_address)
{
char eeprom_data;
char *eeprom_data_ptr = &eeprom_data;
int eeprom_address = log_read_address*4; //Address of previous log
int log_array[4]; //array for temporary storing eeprom data
char time_byte[3];
int lcd_address_counter = 0;
//Sets the global variable to 0 everytime
function is called
int i;
char control_number;
char voltage;
char volt_ascii[2];
for (i=0;i<=3;i++)
{
while (eeprom_read(0xA0,eeprom_address,eeprom_data_ptr)==0);

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

log_array[i] = eeprom_data; //Reads the 4 byte data stored in the eeprom at


the specific address eeprom_address
eeprom_address++;
}
for (i=0;i<=2;i++)
{
time_byte[i] = log_array[i]; //Time array
}

send_string(" Time = ");


//Displays a string Time =
serial_time_display(time_byte); //Displays the time
send_string(" Controller= ");
//Displays a string Controller=
if (log_array[3] == 0xFF)
{
send_string("invalid"); //Writes invalid when controller with invalid codes
with valid checksums received
}
else //Code for dispaying controller number and battery voltage
{
control_number = (controller_check(log_array[3])+'0'); //Check the last 2
bits of the 1st byte received from the infrared controller to determine the controller
number (+'0' is 30H)
serialport_0_byte_send(control_number);
//sends ascii value of the controller number to PC
voltage = battery_voltage(log_array[3]);
//receives
battery voltage, refer to battery_voltage function in ir_funcs.c
volt_ascii[0] = (voltage/10) + '0';
//converting decimal to ascii (first digit)
volt_ascii[1] = voltage-(voltage/10)*10 + '0';
//converting
decimal to ascii (second digit)
send_string(" Battery Voltage = ");
//Sends string
for (i=0;i<=1;i++)
{
serialport_0_byte_send(volt_ascii[i]);
//Sends the two characters to PC in ASCII
}
send_string("00mV");
} //end else
}

void log_time_display(int time_array[])


//Similar to time_display function in
rtclock.c, refer for more comments if neccessary
{
int a=0; //counter for clock read
int time;
for (a = 0; a < 3; a++)
{
time = time_array[a]; //receive time forom timer RE register
//integer to character conversion
//write individual characters to lcd

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

if (time <10)
//check if integer is less than 10
{
//write zero before character
lcd_log_write_char('0');
lcd_log_write_char(time +'0'); //write actual character
}
else
{
if (time < 20 & time > 9)
//check if integer lies in 10's
range
{
//integer split into
time = time-10;
two characters statement, eg. '15' becomes '5' only
lcd_log_write_char('1');
//write 10's range character
first, eg. '1'
lcd_log_write_char(time+'0'); //write second character, eg.
'5'
//the above two lcd write functions combined gives you for
example: '1'+'5' = "15".
}
if (time < 30 & time > 19)
{
time = time-20;
lcd_log_write_char('2');
lcd_log_write_char(time+'0');
}
if (time < 40 & time > 29)
{
time = time-30;
lcd_log_write_char('3');
lcd_log_write_char(time+'0');
}
if (time < 50 & time > 39)
{
time = time-40;
lcd_log_write_char('4');
lcd_log_write_char(time+'0');
}
if (time < 60 & time > 49)
{
time = time-50;
lcd_log_write_char('5');
lcd_log_write_char(time+'0');
}
if (time == 60)
{
time = time-60;
lcd_log_write_char('6');
lcd_log_write_char(time+'0');
}
} // end else
if (a==0 || a==1)
{

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

lcd_log_write_char(':');

//writes a colon between hours,minutes

,and seconds
}
}
}

void serial_time_display(char time_array[])


{
char a=0; //counter for clock read
char time;
for (a = 0; a < 3; a++)
{
time = time_array[a]; //receive time forom timer RE register
//integer to character conversion
//write individual characters to lcd
if (time <10)
//check if integer is less than 10
{
serialport_0_byte_send('0');
//write zero before
character
serialport_0_byte_send(time +'0'); //write actual character
}
else
{
if (time < 20 & time > 9)

//check if integer lies in 10's

range
{
time = time-10;
//integer split into
two characters statement, eg. '15' becomes '5' only
serialport_0_byte_send('1');
//write 10's range
character first, eg. '1'
serialport_0_byte_send(time+'0'); //write second character,
eg. '5'
}
if (time < 30 & time > 19)
{
time = time-20;
serialport_0_byte_send('2');
serialport_0_byte_send(time+'0');
}
if (time < 40 & time > 29)
{
time = time-30;
serialport_0_byte_send('3');
serialport_0_byte_send(time+'0');
}
if (time < 50 & time > 39)
{
time = time-40;
serialport_0_byte_send('4');
serialport_0_byte_send(time+'0');

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

}
if (time < 60 & time > 49)
{
time = time-50;
serialport_0_byte_send('5');
serialport_0_byte_send(time+'0');
}
if (time == 60)
{
time = time-60;
serialport_0_byte_send('6');
serialport_0_byte_send(time+'0');
}
}
if (a==0 || a==1)
{
serialport_0_byte_send(':');
hours,minutes ,and seconds
}
}

//writes a colon between

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Eeprom.c
#include
#include
#include
#include

"sfr_r827.h"
"i2c.h"
"lcd.h"
"serial_port.h"

char dummy;
void nackORcomplete(void);
void nackORcomplete(void)
{
//Step 11
tend_icsr = 0; //transmit end, set to zero, in i2c bus status register
//Step 12
stop_icsr = 0; //stop condition detection flag, set to zero, in in i2c bus status
register

//Step 13
iccr2 = (iccr2&0x3F); //SCP (start/stop condition generation diable bit) and BBSY
(busy bit) set to zero,in i2c bus control register ICCR2,
//Step 14
while (stop_icsr==0); //Reads STOP bit in ICSR register and continues when STOP
bit is equal to 1
//Step 15
iccr1 = (iccr1&0xCF); //TRS bit and MST bit in ICCR1 register is set to 0
tdre_icsr = 0; // transmit data empty set to zero, in i2c bus status register
}

/* WRITE ONE CHAR TO AN ADDRESS IN THE EEPROM*/


char eeprom_write(char eeprom_address,unsigned int data_adress, char data)
{
char return_char;
unsigned char mem_add1;
unsigned char mem_add2;
mem_add1 = (data_adress>>8)&0xFF; //Most significant byte of int
mem_add2 = data_adress&0xFF;
//Least significant byte of int
//Step 1
while (bbsy_iccr2==1); //Read BBSY byte in ICCR2 register
//Step 2
iccr1 = (iccr1&0xFF)|0x30; //TRS bit and MST bit in ICCR1 register is set to 1
//Step 3
iccr2 = (iccr2&0x3F)|0x80;//Write BBSY bit (Set SCP=0 and BBSY =1), Generate start
condition

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

//Step 4
icdrt = (eeprom_address)|0x00; //Device select: Slave address + R/nW
//Step 5
while (tend_icsr==0);//Read TEND bit in ICSR register, wait till TEND bit equals 1
to continue

/****************************************************************************/
/*
MASTER TRANSMIT MODE
*/
/****************************************************************************/
//Step 6
if (ackbr_icier==0) //check if receive acknowledge bit is zero, yeas, then steps 7
to end, otherwise go to step 11
{
//Step 7 & 8
icdrt = mem_add1; //transmit data register receives value of most
significant byte of address in eeprom
while (tdre_icsr == 0); //check if transmit data is empty, makes sure data
is received
//Step 7 & 8
icdrt = mem_add2; //transmit data register receives value of least
significant byte of address in eeprom
while (tdre_icsr == 0); //check if transmit data is empty, makes sure data
is received
//Step 9
icdrt = data; // transmit data register recieves the actual data to be
written to eeprom
//Step 10
while (tend_icsr == 0); // wait for end of transmission of the last byte
return_char = 1; // acknowledgement flag sent, transmission successful
}
else return_char = 0; // not acknowledgement flag sent, transmission unsuccessful
nackORcomplete(); // steps 11 through to 15
return return_char; // send acknowledgement flag, function output
}

/*READ ONE CHAR FROM AN ADDRESS IN THE EEPROM*/


char eeprom_read(char eeprom_address,unsigned int data_adress, char *data)
{
char return_char;
//USE????
unsigned char mem_add1;
unsigned char mem_add2;
mem_add1 = (data_adress>>8)&0xFF;
mem_add2 = data_adress&0xFF;

//Most significant byte of int


//Least significant byte of int

//WRITE THE ADDRESS WHERE THE DATA MUST BE ACCESSED

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

//Step 1
while (bbsy_iccr2==1); //judge the state of the SCL and SDA lines
//Step 2
iccr1 = (iccr1&0xFF)|0x30; //TRS bit and MST bit in ICCR1 register is set to 1
//Step 3
iccr2 = (iccr2&0x3F)|0x80; //Write BBSY bit (Set SCP=0 and BBSY =1), Generate
start condition
//Step 4
icdrt = (eeprom_address)|0x00; //Device select
//Step 5
while (tend_icsr==0); //Read TEND bit in ICSR register, wait till TEND bit equals
1 to continue
//Step 6
if (ackbr_icier == 0) //check if receive acknowledge bit is zero, yeas, then steps
7 to end, otherwise go to step 11
{
//Step 7 & 8
//The address of the data, transmit data
icdrt = mem_add1;
register receives value of most significant byte of address in eeprom to be read from
while (tdre_icsr == 0); //check if transmit data is empty, makes sure data
is received
//Step 9 & 10
icdrt = mem_add2;
//The address of the data, The address of
the data, transmit data register receives value of least significant byte of address in
eeprom to be read from
while (tend_icsr == 0); //check if transmit data is empty, makes sure data
is received
}
else
{
nackORcomplete();
return 0; //not acknowledgement flag sent as output of function
}
//Step 11
tend_icsr = 0; //transmit end, set to zero, in i2c bus status register
//READ DATA FROM THE ADDRESS IN EEPROM
//Step 2
iccr1 = (iccr1&0xFF)|0x30; //TRS bit and MST bit in ICCR1 register is set to 1
//Step 3
iccr2 = (iccr2&0x3F)|0x80; //Generate start condition
//Step 4
icdrt = (eeprom_address)|0x01; //Device select and sets to read mode
//Step 5
while (tend_icsr == 0); //Read TEND bit in ICSR register, wait till TEND bit
equals 1 to continue

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

/****************************************************************************/
/*
MASTER RECEIVE MODE
*/
/****************************************************************************/
//Step 6
if (ackbr_icier == 0) //check if receive acknowledge bit is zero, yeas, then steps
1 & 7-end to end of master recieve mode, otherwise go to step 11 onwards in master
transmit mode
{
//Step 1
tend_icsr = 0; //Set transmit end to zero, in i2c bus status register
trs_iccr1 = 0; //Set transfer/receive select bit, in i2c bus control
register to zero
tdre_icsr = 0; //Set transmit data empty, in i2c bus status register to
zero
//Step 7 (Step 2 to 6 skipped)
ackbt_icier = 1; // transmit acknowledgement select bit set to 1, in i2c
bus interrupt enable register, in receive mode
rcvd_iccr1 = 1; // Receive disable bit set to 1, in i2c bus control
register 1, disables next receive operation
//Step 8
dummy = icdrr;

//Dummy read ICDRR register

//Step 9
while (rdrf_icsr == 0); //wait until the last byte is received
//Step 10
stop_icsr = 0; // set stop condition detection flag back to zero, in i2c
bus status register
//Step 11
iccr2 = (iccr2&0x3F); // set SCP (start/stop condition generation diable
bit) and BBSY (bus busy bit) to zero, in i2c bus control register 2
//Step 12
while (stop_icsr == 0); // Checks the stop bit in the ICSR register
//Step 13
*data = icdrr;

//Read ICDRR register

//Step 14
rcvd_iccr1 = 0;
//Step 15
mst_iccr1 = 0;
return 1; // acknowledgment flag, successful
}
else
{
nackORcomplete();
return 0; // not acknowledgement flag, unsuccessful
}
}

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

int eeprom_det_start_address(void) // determine the start address for the data in the
eeprom
{
char eeprom_data;
char *eeprom_data_ptr = &eeprom_data;
int i=0;
//THE STARTING ADDRESS OF THE EEPROM
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
while (1)
//While loop to determine the starting address (The first adress of eeprom without
data)
{
while (eeprom_read(0xA0,i,eeprom_data_ptr)==0); // execute until an
acknowledgement flag is succesful, therefore read has occured
if (eeprom_data==0xFF)
// if
eeprom is empty
{
break; // exit
}
i++;
} // end while(1)
//Sets the
eeprom_index that is called in interrupt equal to variable i determined above
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return i;
} // end function
char eeprom_initial_cond_zero(void) //Test if first address is written to
{
char eeprom_data;
char *eeprom_data_ptr = &eeprom_data;
char address_zero = 0;
while (eeprom_read(0xA0,0,eeprom_data_ptr)==0); //If address holds data, send data
to PC via USB, execute until an acknowledgement flag is succesful, therefore read has
occured
if (eeprom_data==0xFF)
{
address_zero = 1; //returns with 1 if adress 0 is empty
}
return address_zero;
}

void eeprom_read_all(void) // read all the data in the eeprom


{
char eeprom_data;
char *eeprom_data_ptr = &eeprom_data;
int i=0;

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

for (i=0;i<=57;i++) //Read first 57 addresses


{
while (eeprom_read(0xA0,i,eeprom_data_ptr)==0); //If address holds data,
send data to PC via USB, execute until an acknowledgement flag is succesful, therefore
read has occured
serialport_0_byte_send(eeprom_data);
// send data
from eeprom via serial port
}

void eeprom_erase_all(void) // erase all the saved data in the eeprom, log information
and remote control codes
{
char eeprom_data;
char *eeprom_data_ptr = &eeprom_data;
int i=0;
for (i=0;i<=100;i++)
{
while (eeprom_write(0xA0,i,0xFF)==0); // write 0xFF to all the addresses,
0xFF reads as empty addresses.
}
} // end eeprom_erase_all function

char eeprom_determine_empty(char log_address)


{
char eeprom_data;
char *eeprom_data_ptr = &eeprom_data;
char first_byte;
char is_empty = 0; //not empty
int i;
int eeprom_address = log_address*4;
while (eeprom_read(0xA0,eeprom_address,eeprom_data_ptr)==0);
first_byte = eeprom_data;
if (first_byte == 0xFF)
{
is_empty = 1;
}
return is_empty;
} //end eeprom_determine_empty function

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

I2c.c
#include "sfr_r827.h"
#include "i2c.h"

/**********************************************************************************/
/* Initialize the i2c
*/
/**********************************************************************************/
void i2c_initialise(void) // intitialise the i2c port
{
sar=0x10; //slave address of the controller
iicsel=1; //i2c choosen
ice_iccr1 = 1;
iccr1=(iccr1 & 0xf0)|(0x0D); //100 kHz
} // end i2c_initialise

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Intprg.c
/***********************************************************************/
/*
*/
/* FILE
:intprg.c
*/
/* DATE
:Mon, Feb 18, 2008
*/
/* DESCRIPTION :define the top address of the interrupt vectors.
*/
/* CPU GROUP
:27
*/
/*
*/
/* This file is generated by Renesas Project Generator (Ver.4.8).
*/
/*
*/
/***********************************************************************/
/***************************************************************************
* COMPILER for M16C/60,R8C/Tiny
* Copyright(c) 2004 Renesas Technology Corp.
* And Renesas Solutions Corp.,All Rights Reserved.
* intprg.c : define variable vector table
*
for R8C/27,26
*
*
* $Date: 2006/09/13 05:29:23 $
* $Revision: 1.3 $
**************************************************************************/
#include "sfr_r827.h"
#include "cstartdef.h"
#include "serial_port.h"
#include "lcd.h"
#include "eeprom.h"
#include "rtclock.h"
#include "menu.h"
#include "PWM.h"
#include "triac.h"
#include "ir_funcs.h"
#include "display_log.h"
#include "motor_current.h"
volatile char sec = 0;
volatile char command_flag;
volatile int command;
volatile char test_mode;
volatile char ir_command;
//infra red signal command
volatile char ir_command_buffer[4];
//infra red signal command buffer
volatile char ir_receive_index;
volatile unsigned int speed_counter;
volatile unsigned int gate_speed = 0;
//Gate speed initially zero
volatile char triac_auto_on_off_flag = 0;
//Triac initially off
volatile char triac_on_timer = 0;
//Traic on time starts at zero seconds
volatile char checksum;
volatile char gate_flag = 0;
volatile char log_index = 0;
volatile char ir_flag = 0;
//Set to one if correct 4 bytes
are received
volatile char lcd_msg_flag = 0;//Still pending
volatile char lcd_msg_timer = 0;//Still pending
volatile long int gate_timer = 0; //CHECK!!!!!!!!!!!

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

volatile int motor_high_current_timer = 0;

// When you want to use BANK1 registers


// please define interrupt using /B swtich as follows.
//
// #pragma interrupt/B xxxx
//
// BRK
#pragma interrupt
void _brk(void){}
//
//
//
//
//
//

vector
vector
vector
vector
vector
vector

1
2
3
4
5
6

(software int 0)
_brk(vect=0)

reserved
reserved
reserved
reserved
reserved
reserved

// timer RC (channel 0)
(software int 7)
#pragma interrupt
_timer_rc(vect=7)
void _timer_rc(void){}
// vector 8 reserved
// vector 9 reserved
// timer RE
(software int 10)
#pragma interrupt
_timer_re(vect=10)
void _timer_re(void)
{
sec++;
if(menu_branch==0 && lcd_msg_flag == 0)
{
Time_display(); //send time to LCD
}
if(triac_auto_on_off_flag == 1)
{
triac_on(); // switch curteous lights on
if(triac_on_timer++ == 10) // keep the triac curteous light on for 10
seconds
{
triac_on_timer = 0;
triac_auto_on_off_flag = 0 ;
triac_off(); // switch curteous light off
}
}//end of if triac_auto_on_off_flag == 1
if(lcd_msg_flag == 1)
{
//Set message here
if(lcd_msg_timer++ == 10)
{
lcd_msg_timer = 0;
lcd_msg_flag = 0 ;

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

}
}//end of if (lcd_msg_flag == 1)
} // end timer re interrupt
// vector 11 reserved
// vector 12 reserved
// input_key
(software int 13)
#pragma interrupt
_input_key(vect=13)
void _input_key(void){}
// A-D converter
(software int 14)
#pragma interrupt
_ad_converter(vect=14)
void _ad_converter(void){}
// SSU IIC
#pragma interrupt
void _ssu(void){}

(software int 15)


_ssu(vect=15)

// vector 16 reserved
#if defined (__STANDARD_IO__) && (defined(__FOUSB__) ||
// uart0 can't be used
#else
// uart0 trance
(software int 17)
#pragma interrupt
_uart0_trance(vect=17)
void _uart0_trance(void){}
#endif

defined(__E8__))

// uart0 receive
(software int 18)
#pragma interrupt
_uart0_receive(vect=18)
void _uart0_receive(void)
{
command = u0rb;
if (command == '!')
{
test_mode = 1;
//Test mode, can run all USB commands
}
else if (command == '@')
{
test_mode = 0; //Normal mode, can;t run the USB commands
}
if(test_mode == 1) // USB commands can be used in test mode = true
{
//Creates an interrupt when one of these characters are received, goes back
to main and follows the statement in the appropriate command
if (command == '#' || command == '$' || command == '%' || command == '^' ||
command == '&' || command == '*' || command == '+' || command == '-' || command == '(')
{
command_flag = 1 ;
}
}// end of if(test_mode == 1)
// eie seriepoort kode / own serial port code here
} // end uart0_receive interrupt
#if defined(__STANDARD_IO__) || defined(__FOUSB__) || defined(__E8__)

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

// uart1 can't be used


#else
// uart1 trance
(software int 19)
#pragma interrupt
_uart1_trance(vect=19)
void _uart1_trance(void){}
#endif
// uart1 receive
(software int 20)
#pragma interrupt
_uart1_receive(vect=20)
void _uart1_receive(void)
{
ir_command = u1rb;
//Signal from remote
set to UART1 Receive Buffer Register
ir_command_buffer[ir_receive_index] = ir_command; //read remote signal byte for
byte. save in the remote buffer
ir_receive_index++; // shift the remote control buffer index flag/pointer
if (msb_check(ir_command_buffer[0]) == 1) //If MSB of first byte is zero
{
if (ir_receive_index==4) //When 4 bytes are received
{
checksum = 0; // reset checksum
for (ir_receive_index = 0; ir_receive_index < 3; ir_receive_index++)
// run throught the ir-remote signal buffer
{
checksum = checksum + ir_command_buffer[ir_receive_index];
//Calculate checksum
}
checksum = checksum | 0x80;

//Make checksum same as it is

calculated on remote
if (checksum == ir_command_buffer[3]) //Check if checksum is the
same as the checksum from remote
{
ir_flag = 1; //Set flag to 1, to execute operations in main()
} //end if (checksum == ir_command_buffer[3])
ir_receive_index = 0; //resets the index after 4 bytes was received
}// end if (ir_receive_index==4)
}// end (msb_check(ir_command_buffer[0]) == 1)
else
{
ir_receive_index = 0; // reset remote receive pointer flag
}

} //end uart1 intterupt

// vector 21 reserved
// timer RA
(software int 22)
#pragma interrupt
_timer_ra(vect=22)
void _timer_ra(void)
{

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

if ( speed_counter++ == 2000) //Stel di tyd hier vir acceleration


{
speed_counter=0; //Resets counter
if (gate_control == 1)
{
gate_speed++;
if (gate_speed > 9)

//Accelerate the gate


//If gate reaches maximum, keep it at

maximum
{
gate_speed = 10;
}
}
}
if (motor_current()>=40) //If motor_current too high for a small amount of time,
stop the gate
{
if ( motor_high_current_timer++ == 15) //Motor current fluctuates, so look
for a few instance when current is above a certain range.
{
gate_control = 0; //Stop Accelerating
gate_speed = 0;
}
}
else
{
motor_high_current_timer = 0;
}
} //end timer RA interrupt
// vector 23 reserved
// timer RB
(software int 24)
#pragma interrupt
_timer_rb(vect=24)
void _timer_rb(void){}
// int1
#pragma interrupt
void _int1(void)
{

(software int 25)


_int1(vect=25)

}
// int3
#pragma interrupt
void _int3(void){}

(software int 26)


_int3(vect=26)

// vector 27 reserved
// vector 28 reserved
// int0
#pragma interrupt
void _int0(void){}

(software int 29)


_int0(vect=29)

// vector 30 reserved

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

// vector 31 reserved
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//

vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Ir_funcs.c
#include "sfr_r827.h"
#include "eeprom.h"
char msb_check(char ir_first_byte) //check for the most significant bit first, 0 for
first byte
{
char msb_zero = 0; //Assume Most significant byte is not zero
union byte_def nib;
nib.byte=ir_first_byte;
if (nib.bit.b7==0) // check MSB for 0, if true, then it is the first byte, ie.
Alarm or gate open/close
{
msb_zero = 1; // set MSB flag to 1 if MSB was 0
}
return msb_zero; // return MSB indication flag, 1 for MSB of 0, and 0 otherwise
} // end MSB_check function

char controller_check(char ir_first_byte) //Function to determine the controller number


WORKING
{
char controller_number;
union byte_def nib;
nib.byte=ir_first_byte;
//Checks last 2 bits to determine which controller
if (nib.bit.b1==0 && nib.bit.b0==0)
{
controller_number = 0;
}
else if (nib.bit.b1==0 && nib.bit.b0==1)
{
controller_number = 1;
}
else if (nib.bit.b1==1 && nib.bit.b0==0)
{
controller_number = 2;
}
else if (nib.bit.b1==1 && nib.bit.b0==1)
{
controller_number = 3;
}
return controller_number;
} // end controller_check function

char alarm_check(char ir_first_byte)


{

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

char alarm;
alarm = ir_first_byte & 0x7C; // AND's with 0b01111100
return alarm; //alarm_check will return with zero if alarm is activated
} // end alarm_check function

char battery_voltage(char ir_first_byte)


{
char voltage = 0;
union byte_def
nib;
nib.byte=ir_first_byte;
//Converts 5 bits, received from 1st byte of ir_remote to voltage
if (nib.bit.b6==1)
{
voltage = voltage + 48;
}
if (nib.bit.b5==1)
{
voltage = voltage + 24;
}
if (nib.bit.b4==1)
{
voltage = voltage + 12;
}
if (nib.bit.b3==1)
{
voltage = voltage + 6;
}
if (nib.bit.b2==1)
{
voltage = voltage + 3;
}
return voltage;
} //end battery_voltage function

void write_remote_cntrl_eeprom (char remote_byte1, char codes[]) // writes access codes


for remote to allocated space in eeprom
{
char controller;
char code1 = codes[0];
char code2 = codes[1];
controller = controller_check(remote_byte1);
// test for remote 0x00, remote 1
if (controller == 0)
{

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

//write remote 1's codes to alloocated space in eeprom


while (eeprom_write(0xA0,50,code1)==0);
while (eeprom_write(0xA0,51,code2)==0);
}
//test for remote 0x01, remote 2
if (controller == 1)
{
//write remote 2's codes to alloocated space in eeprom
while (eeprom_write(0xA0,52,code1)==0);
while (eeprom_write(0xA0,53,code2)==0);
}
//test for remote 0x02, remote 3
if (controller == 2)
{
//write remote 3's codes to alloocated space in eeprom
while (eeprom_write(0xA0,54,code1)==0);
while (eeprom_write(0xA0,55,code2)==0);
}
//test for remote 0x03. remote 4
if (controller == 3)
{
//write remote 4's codes to alloocated space in eeprom
while (eeprom_write(0xA0,56,code1)==0);
while (eeprom_write(0xA0,57,code2)==0);
}
} //end write_remote_cntrl_eeprom function
char* read_remote_cntrl_eeprom (char remote_byte1) // reads remote access codes for the
corrosponding eeprom remote location
{
char eeprom_data;
char *eeprom_data_ptr = &eeprom_data;
char codes[2];
char controller;
controller = controller_check(remote_byte1);
// read codes for remote 1
if (controller == 0)
{
while (eeprom_read(0xA0,50,eeprom_data_ptr)==0);
codes[0] = eeprom_data;
while (eeprom_read(0xA0,51,eeprom_data_ptr)==0);
codes[1] = eeprom_data;
}
// read codes for remote 2
if (controller == 1)
{
while (eeprom_read(0xA0,52,eeprom_data_ptr)==0);
codes[0] = eeprom_data;
while (eeprom_read(0xA0,53,eeprom_data_ptr)==0);
codes[1] = eeprom_data;
}

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

// read codes for remote 3


if (controller == 2)
{
while (eeprom_read(0xA0,54,eeprom_data_ptr)==0);
codes[0] = eeprom_data;
while (eeprom_read(0xA0,55,eeprom_data_ptr)==0);
codes[1] = eeprom_data;
}
// read codes for remote 4
if (controller == 3)
{
while (eeprom_read(0xA0,56,eeprom_data_ptr)==0);
codes[0] = eeprom_data;
while (eeprom_read(0xA0,57,eeprom_data_ptr)==0);
codes[1] = eeprom_data;
}
return codes;
} // end read_remote_cntrl_eeprom function

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Lcd.c
#include "sfr_r827.h"
#include "lcd.h"
#define
#define
#define
#define
#define
#define
#define

LCD_RS p0_4 //nie toeganklik in ander modules /


LCD_RNW p0_5
LCD_E p0_6
LCD_D0 p0_0
LCD_D1 p0_1
LCD_D2 p0_2
LCD_D3 p0_3

Not accessible in other modules

void ms_5_delay(void); //nie toeganklik in ander modules / Not accessible in other


modules
void lcd_not_busy_wait(void); //nie toeganklik in ander modules / Not accessible in
other modules
/* skryf die laagste 4 bisse van greep nibble_in na die LCD met RS=0*/
/* writes the least significant 4 bits of byte nibble_in to the LCD with RS=0 */
void lcd_instruction_nibble_write(char nibble_in)
{
union byte_def
nibble;
nibble.byte=nibble_in;
LCD_E=0;
LCD_RS=0;
LCD_RNW=0;
LCD_E=1;
LCD_D3=nibble.bit.b3;
LCD_D2=nibble.bit.b2;
LCD_D1=nibble.bit.b1;
LCD_D0=nibble.bit.b0;
LCD_E=0;
} // end lcd_instruction_nibble_write function

/* 5 ms vertraging */
/* 5 ms delay */
void ms_5_delay(void)
{
int k;
int N=5000;
//N is worked out by measuring a for loop with the led output
pin with the oscilloscope.
for (k=0;k<N;k++);
} // end ms_5_delay function

/****************************************************************************/
/* See Lecture 2
*/
/* not all delays need be 5 ms - but function only called once, thus of
*/
/* little consequence.
*/
/****************************************************************************/

void lcd_initialise(void)
{

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

prc2=1;
// autoset to zero after next write to memory
// low 7 bits are output
pd0=pd0|0x7f;
ms_5_delay();
ms_5_delay();
ms_5_delay();
lcd_instruction_nibble_write(3);
ms_5_delay();
lcd_instruction_nibble_write(3);
ms_5_delay();
lcd_instruction_nibble_write(3);
ms_5_delay();
lcd_instruction_nibble_write(2);
ms_5_delay();
lcd_instruction_nibble_write(2);
// now in 4-bit mode
lcd_instruction_nibble_write(8);
ms_5_delay();
lcd_instruction_nibble_write(0x0);
lcd_instruction_nibble_write(0x0c);
ms_5_delay();
lcd_instruction_nibble_write(0x0);
lcd_instruction_nibble_write(0x1);
ms_5_delay();
lcd_instruction_nibble_write(0x0);
lcd_instruction_nibble_write(0x06);
} // end lcd_initialise function
/* skryf 'n instuksie na die LCD */
/* writes an instuctioon to the LCD */
void lcd_instruction_write(char instruction)
{
union byte_def
nib;
nib.byte=instruction;
lcd_not_busy_wait();
prc2 = 1;
is enable to pd0
pd0 = 0x7f;

//protection register set to 1, so that writing


//Set direction port to write mode

LCD_RS = 0;
LCD_RNW = 0;
LCD_E = 1;
an byte
LCD_D3 = nib.bit.b7;
LCD_D2 = nib.bit.b6;
LCD_D1 = nib.bit.b5;
LCD_D0 = nib.bit.b4;
LCD_E = 0;

//4 bit data has to be sent twice, to represent

LCD_E = 1;
LCD_D3 = nib.bit.b3;
LCD_D2 = nib.bit.b2;
LCD_D1 = nib.bit.b1;
LCD_D0 = nib.bit.b0;
LCD_E = 0;
}
/* skuif die karakters van die LCD een plek na links */

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

/* scrolls the chatacters on the LCD one position to the left */


void lcd_left_scroll(void) //Used in menu.c in display log
{
lcd_instruction_write(0x18);
}
/* skuif die karakters van die LCD een plek na regs */
/* scrolls the chatacters on the LCD one position to the right */
void lcd_right_scroll(void)//Used in menu.c in display log
{
lcd_instruction_write(0x1c);
}
/* Wis die LCD en skuif die loper na posisie zero */
/* clears the LCD and moves the cursor to the zero position */
void lcd_scrn_clear(void)
{
//Clears the display
lcd_instruction_write(0x01);
lcd_instruction_write(0x02);
//Sets the DDRAM address to 0
}
/* wag tot die LCD "busy flag" herstel */
/* waits until the LCD busy flag resets */
void lcd_not_busy_wait(void)
{
char busy = 1;
//Sets a variable to 1, variable busy is to be
used to check busyflag in while loop
prc2 = 1;
//Enable writing to pd0
pd0_3 = 0;
//Sets the direction of p0_3 to reading, so that busy
flag could be read
while(busy)
//While busy=1, loop will repeat itself until busy=0, which
corresponds to the busy flag(LCD_D3)=0
{
LCD_RS = 0;
LCD_RNW = 1; //Reading is enabled
LCD_E = 1;
busy = LCD_D3;
//Reads busy flag p0_3
LCD_E = 0;
LCD_E = 1;
while(0);
//while(0) just to waste a bit of time
LCD_E = 0;
}
prc2 = 1;
pd0_3 = 1;
} // end lcd_not_busy_wait

//Enable writing to pd0


//Set p0_3 so that it could be written on again

/* skryf 'n kakter na die LCD en inkrementeer die loper posisie */


/* writes a charcter to the LCD and increments the cursor position */
void lcd_character_write(char character)
{
//own code
union byte_def
nib;
nib.byte=character;
lcd_not_busy_wait();
prc2 = 1;

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

pd0 = 0x7f;

//Set direction port to write mode

LCD_RS = 1;
LCD_RNW = 0;
LCD_E = 1;
LCD_D3 = nib.bit.b7;
LCD_D2 = nib.bit.b6;
LCD_D1 = nib.bit.b5;
LCD_D0 = nib.bit.b4;
LCD_E = 0;
LCD_E = 1;
LCD_D3 = nib.bit.b3;
LCD_D2 = nib.bit.b2;
LCD_D1 = nib.bit.b1;
LCD_D0 = nib.bit.b0;
LCD_E = 0;
} // end lcd_character_write function

//The improved character write function of LCD for log.c


void lcd_log_write_char(char character)
{
lcd_character_write(character);
if(lcd_address_counter>7) //When lcd_address_counter>7 two addresses gets data
written on it. 40H, which is the first address of the second line and the previous
statement writes on DDRAM addresses 0 and up
{
lcd_instruction_write((0xC0 + (lcd_address_counter-8)));
lcd_character_write(character);
lcd_instruction_write((0x80 + lcd_address_counter+1)); //Sets the DDRAM
address to the next address of the first line of the lcd
}
lcd_address_counter++;
function is runned in intrprg.c
}

//lcd_address_counter gets incremented each time

//Function for writing whole strings to lcd with external variable


void lcd_log_write_string(char data_str[])
{
int i = 0;
while(data_str[i] != '\0')
{
lcd_character_write(data_str[i]);
if(lcd_address_counter>7) //When i>7 two addresses gets data written on it.
40H, which is the first address of the second line and the previous statement writes on
DDRAM addresses 0 and up
{
lcd_instruction_write((0xC0 + (lcd_address_counter-8)));
lcd_character_write(data_str[i]);
lcd_instruction_write((0x80 + lcd_address_counter+1)); //Sets the
DDRAM address to the next address of the first line of the lcd
}
i++;

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

lcd_address_counter++;
}
} //end lcd_log_write_string function

//Function for writing whole strings to lcd


void lcd_write_string(char data_str[])
{
int i = 0;
lcd_scrn_clear();
while(data_str[i] != '\0')
{
lcd_character_write(data_str[i]);
if(i>7) //When i>7 two addresses gets data written on it. 40H, which is the
first address of the second line and the previous statement writes on DDRAM addresses 0
and up
{
lcd_instruction_write((0xC0 + (i-8)));
lcd_character_write(data_str[i]);
//Sets the DDRAM address to
lcd_instruction_write((0x80 + i+1));
the next address of the first line of the lcd
}
i++;
} //end while
} //end lcd_write_string finction

//Function to make scrolling messages


char lcd_write_error_string(char data_str[])
{
int i = 0;
int scroll_count = 0;
lcd_scrn_clear();
while(data_str[i] != '\0')
{
lcd_character_write(data_str[i]);
if(i>7) //When i>7 two addresses gets data written on it. 40H, which is the
first address of the second line and the previous statement writes on DDRAM addresses 0
and up
{
lcd_instruction_write((0xC0 + (i-8)));
lcd_character_write(data_str[i]);
lcd_instruction_write((0x80 + i+1));
//Sets the DDRAM address to
the next address of the first line of the lcd
}
i++;
if(i>16)
{
scroll_count++;
}
}
return scroll_count;
} //end lcd_write_error_string function

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Lightsensor.c
#include "sfr_r827.h"
char lightsensor_flag = 0; // set light sensor flag to 0 intially, no obstruction
char lightsensor_state(void)
{
char state;
if(p1_7 == 0 && lightsensor_flag==0) //Light is not interrupted
{
lightsensor_flag=1;
//Indicates that light is on, no
obstruction
state=1;
}
else if(p1_7 == 1 && lightsensor_flag==1)//Light is interrupted
{
//Light is not on,
lightsensor_flag=0;
obstruction occurs
state=0;
}
else
{
state=0;
}
return state;
} //end lightsensor_state function

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Menu.c
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

"sfr_r827.h"
"menu.h"
"lcd.h"
"serial_port.h"
"i2c.h"
"eeprom.h"
"rtclock.h"
"oscillator_timers.h"
"PWM.h"
"triac.h"
"display_log.h"
"ir_funcs.h"

//Definitions for the MENU buttons


#define ENTER p3_7
#define UP p1_1
#define DOWN p3_3
#define RIGHT p3_6
#define LEFT p5_4
char
char
char
char
char

enter(void);
down(void);
up(void);
left(void);
right(void);

//Flags used to test if switch is pressed, Used to avoid sending a signal repeatedly,
s_flag = 0 if switch is not pressed
char enter_flag = 0;
char up_flag = 0;
char down_flag = 0;
char left_flag = 0;
char right_flag = 0;

volatile int menu_branch=0;


char set_time_flag = 0;
int h_m_s_select = 0;
int rt_time_arr[3];
clock
int mor_time_arr[3];
int eve_time_arr[3]
time

//Array for hours,minutes,seconds for setting real time

// Array for hours,minutes,seconds for setting morning time


//Array for hours,minutes,seconds for setting evening

signed char menu_log_index; //Variable for the LCD log

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

void menu_initialise(void)
{

if(set_time_flag==0)
{
switch(menu_branch)
{
//Activates Menu
case 0: if (enter()==1)
{
menu_branch++;
main_menu(menu_branch);
display messages on LCD
}

//This function only

break;

//In Reset Alarm Menu


case 1: if (enter()==1) // check if enter key is pressed, enters the
current menu option
{
reset_alarm();

//Resets the buzzer and exit menu

}
if (down()==1) // check if down key is pressed
{
menu_branch++; // increment menu position, and points to next
menu option
main_menu(menu_branch); // display current menu option
}

if (up()==1) // check if up key is pressed


{
menu_branch = 9; // menu index pointer starts moves to last
menu option
main_menu(menu_branch); // display last menu option
}
break;
//In Time Settings Menu
case 2:

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

if (enter()==1) // check if enter key is pressed, enter time


settings menu option
{
menu_branch = 6; // set the menu pointer to the sub-menu
option in time settings
main_menu(menu_branch); // display current menu option
}

if (down()==1) // check if down key is pressed


{
menu_branch++; // increment menu pointer
main_menu(menu_branch); // display next sub-menu option
}

if (up()==1) // check if up key is pressed


{
menu_branch--; // decrement menu pointer, moves pointer to
previous position in sub-menu
main_menu(menu_branch); // display the current time settings
sub-menu option
}
break;
//In Open/Close Gate Menu
case 3:
if (enter()==1) //Activates the gate
{
gate_flag = 1;
operations can be run in main()
menu_branch = 0;

//gate_flag is set to 1, so that


//Exits the menu and display time again

} //End of enter

if (down()==1) // check if down key is pressed, move to next


menu option
{
menu_branch++; // points to "accept new codes" menu option
main_menu(menu_branch); // display "accept new codes" menu
option
}

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

if (up()==1) // check if up key is pressed, move to previous


menu option, time settings menu option
{
menu_branch--; // decrement menu pointer, points to "time
settings" menu option
main_menu(menu_branch); // display the "time settings" menu
option
}
break;

//In Accept New Codes Menu


case 4:
if (down()==1) // check for down key pressed, points to
"display log" menu option
{
menu_branch++; // increment menu pointer, points to "display
log" menu option
main_menu(menu_branch); // display the "display log" menu
option
}

if (up()==1) // check for up key pressed


{
menu_branch--; // decrement menu pointer, points to
"Open/Close Gate" menu option
main_menu(menu_branch); // display "Open/Close Gate" menu
option
}

if (enter()==1) // check for enter key pressed, enter "accept


new codes" menu option
{
write_remote_cntrl_eeprom(remote_byte_one,new_codes); // write
the new acces codes to the pre-allocated space on the eeprom for the specific remote
menu_branch = 0; // exit the menu
}

break;
//In Display Log Menu
case 5:
if (down()==1) // check for down key pressed
{

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

menu_branch = 9; //Skip to Exit Menu


main_menu(menu_branch); // display the "Exit Menu" menu option
}

if (up()==1) // check for up key pressed


{
menu_branch--; // decrement menu pointer, points to "Accept
new codes"
main_menu(menu_branch); // display "Accept new codes" menu
option
}

if (enter()==1) // check for enter key pressed, enter "display


log" menu option
{
lcd_address_counter = 0; // reset the LCD address pointer
menu_log_index = log_index - 1;
if (menu_log_index<0)
{
menu_log_index = 9;
}
//Display last log here first
if (eeprom_determine_empty(menu_log_index)==0)
{
read_log_lcd(menu_log_index);
menu_branch = 11; //Go to case 10 where all of the logs are
called from eeprom, all lcd instructions are given in display_log.c
}

else
{
menu_branch = 0; //if logs is empty return to time
display
}

}
break;
//In Set Time Menu (After enter in Time settings)
case 6:
if (enter()==1) // check for enter key pressed, enter "new
time settings" sub-menu option
{

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

dummy_time_display(rt_time_arr); //Displays the time to be


edit on the lcd
set_time_flag = 1; // This flag indicates that a new sub menu
is going to be accessed until the sub menu is left by setting the set_time_flag to zero
again, therefore the menu_branch remains the same
h_m_s_select = 0; //Selects hours to be edited first
}

if (down()==1) // check for down key pressed,


{
menu_branch++; // increment menu pointer, points to "Evening
time" sub-menu
main_menu(menu_branch); // display the "Evening time" sub-menu
option
}
if (up()==1) // check for up key pressed,
{
menu_branch = 10; // set the menu pointer, points to "Back to
Main Menu" option
main_menu(menu_branch); // display "Back to main menu" option
}
break;
//In Set Evening Menu
case 7:
if (enter()==1) // check for enter key pressed
{
dummy_time_display(eve_time_arr); //Displays the time to be
edit on the lcd
set_time_flag = 1; // This flag indicates that a new sub menu
is going to be accessed until the sub menu is left by setting the set_time_flag to zero
again, therefore the menu_branch remains the same
h_m_s_select = 0;
}
if (down()==1) // check for down key pressed, move to "set
morning time" sub-menu option
{
menu_branch++; // increment sub-menu pointer, points to "set
morning time" sub-menu option
main_menu(menu_branch); // display "Set morning time" sub-menu
option
}

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

if (up()==1) // check for up key pressed, move to "set time"


sub-menu option
{
menu_branch--; // decrement sub-menu pointer, points to "set
time" sub-menu option
main_menu(menu_branch); // display "set time" sub-menu option
}
break;
//In Set Morning Menu
case 8:
if (enter()==1) // check for eneter key pressed
{
dummy_time_display(mor_time_arr); // display a dummy time
set_time_flag = 1; // This flag indicates that a new sub menu
is going to be accessed until the sub menu is left by setting the set_time_flag to zero
again, therefore the menu_branch remains the same
h_m_s_select = 0; //Selects hours to be edited first
}

if (down()==1) // check for down key pressed


{
menu_branch=10; // menu pointer set, points to "back to main
menu" sub-menu option
main_menu(menu_branch); // display "back to menu" option
}
if (up()==1) // check for up key pressed
{
menu_branch--; // decrement menu pointer, points to "set
evening time"
main_menu(menu_branch); // display "set evening time" option
}
break;
case 9: //Exit Menu, Menu
if (down()==1) // check for down key pressed
{
menu_branch=1; // set menu pointer, points to "reset alarm"
menu
main_menu(menu_branch); // display "reset alarm menu"
}

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

if (up()==1)
{
menu_branch=5; // set mnu pointer, points to "display log"
menu
main_menu(menu_branch); // display "display log" menu
}
if (enter()==1)
{
menu_branch = 0;

//Exit menu

}
break;

case 10: //Back to Main Menu


if (enter()==1)
{
menu_branch = 2;
//back to Time Settings
main_menu(menu_branch);
}
if (down()==1)
{
menu_branch = 6;
//Set Time again, menu pointer
main_menu(menu_branch); // display "set time" option
}

if (up()==1)
{
menu_branch = 8;
//Set Morning again, menu pointer
main_menu(menu_branch); // display "set Morning" menu option
}
break;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DISPLAYING LOGS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 11: //Displaying logs WORKING!!!!

if (enter()==1)
{

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

menu_branch = 0;
//Exit menu
menu_log_index = 0; //Resets menu_log_index
}

if (down()==1)
{
lcd_address_counter = 0; //Resets global variable
lcd_address_counter
menu_log_index--;

//decrements menu_log_index

when down button is pressed


if(menu_log_index<0)
{
menu_log_index = 9; //set menu_log_index = 9 if
menu_log_index goes under 0
}
if (eeprom_determine_empty(menu_log_index)==0) //If not empty
then read
{
read_log_lcd(menu_log_index); //Reads the eeprom data and
output to LCD, refer ro function
}
else if (eeprom_determine_empty(menu_log_index)==1) //If empty
dont output to lcd
{
menu_log_index++;

//increments menu_log_index

when up button is pressed


if(menu_log_index>9)
{
menu_log_index = 0; //set menu_log_index = 0 if
menu_log_index goes over 9
}
} // end else if

if (up()==1)
{
lcd_address_counter = 0; //Resets global variable
lcd_address_counter
menu_log_index++;

//increments menu_log_index when

up button is pressed
if(menu_log_index>9)
{
menu_log_index = 0; //set menu_log_index = 0 if
menu_log_index goes over 9
}

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

if (eeprom_determine_empty(menu_log_index)==0) //If not empty


then read
{
read_log_lcd(menu_log_index); //Reads the eeprom data and
output to LCD, refer ro function
}
else if (eeprom_determine_empty(menu_log_index)==1) //If empty
{
menu_log_index--;
//decrements menu_log_index
when down button is pressed
if(menu_log_index<0)
{
menu_log_index = 9;

//set menu_log_index = 9 if

menu_log_index goes under 0


}
} // end else if

if (right()==1)
{
lcd_left_scroll();

//Scrolls lcd to left, making the

screen move to the right

}
if (left()==1)
{
lcd_right_scroll();

//Scrolls lcd to right, making the

screen move to the left


}
break; //End of displaying the logs
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%

} //End of switch
}// End of if statement checking if set_time_flag=0

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

//Now we are in the menu that offers us the ability to change time
else if (set_time_flag==1)
{
switch(menu_branch)
{
case 6: //Code for setting the real time clock
//Selecting hours/minutes
if(right()==1)
{
h_m_s_select++;

//Increments the

selection
if (h_m_s_select >2) //Prevents h_m_s_select to go over
2 (no array defined for above 2)
{
h_m_s_select = 0;
}
}
if(left()==1)
{
h_m_s_select--;

//Decrements the

selection
if (h_m_s_select < 0)
go under 0 (no array defined for under 0)
{
h_m_s_select = 2;
}

//Prevents h_m_s_select to

//To change hours/minutes/seconds


if (down()==1)
{
rt_time_arr[h_m_s_select]--;

//Decrement

selection
if (h_m_s_select==0)
//Check to
see if user wants to edit hours (in 24 hour format), this prevents hours going below 0
{
if (rt_time_arr[h_m_s_select] < 0)
{
rt_time_arr[h_m_s_select] = 23;
}
}
else
//Else minutes and seconds edit, this prevents minutes and seconds going below 0
{
if (rt_time_arr[h_m_s_select] < 0)

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

{
rt_time_arr[h_m_s_select] = 59;
}

}
dummy_time_display(rt_time_arr); //Display choice on
LCD
}
//To change hours/minutes/seconds
if (up()==1)
{
rt_time_arr[h_m_s_select]++;

//Increment

selection
if (h_m_s_select==0)
//Check to
see if user wants to edit hours (in 24 hour format), this prevents hours going over 23
{
if (rt_time_arr[h_m_s_select] > 23)
{
rt_time_arr[h_m_s_select] = 0;
}
}
else
{
if (rt_time_arr[h_m_s_select] > 59)
minutes and seconds edit, this prevents minutes and seconds going over 59
{
rt_time_arr[h_m_s_select] = 0;
}

//Else

}
dummy_time_display(rt_time_arr); //Display choice on
LCD
}

if (enter()==1)
{
setTime(rt_time_arr[0],rt_time_arr[1],rt_time_arr[2]); //Set
the actual time, to the selected user defined time
menu_branch = 0;
//Displays the time again
set_time_flag = 0; //Exit the sub menu
}
break;

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

case 7: //Code for setting the evening time


//Selecting hours/minutes/seconds
if(right()==1)
{
h_m_s_select++;

//Increments the

selection
if (h_m_s_select >1) //Prevents h_m_s_select to go over
1 (Only setting the hours and the minutes)
{
h_m_s_select = 0;
}
}
if(left()==1)
{
h_m_s_select--;

//Decrements the

selection
if (h_m_s_select < 0)
go under 0 (no array defined for under 0)
{
h_m_s_select = 1;
}

//Prevents h_m_s_select to

//To change hours/minutes/seconds


if (down()==1)
{
eve_time_arr[h_m_s_select]--;

//Decrement

selection
if (h_m_s_select==0)
//Check to
see if user wants to edit hours (in 24 hour format), this prevents hours going below 0
{
if (eve_time_arr[h_m_s_select] < 0)
{
eve_time_arr[h_m_s_select] = 23;
}
}
else
//Else minutes and seconds edit, this prevents minutes and seconds going below 0
{
if (eve_time_arr[h_m_s_select] < 0)
{
eve_time_arr[h_m_s_select] = 59;
}
}

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

dummy_time_display(eve_time_arr); //Display choice on


LCD
}
//To change hours/minutes/seconds
if (up()==1)
{
eve_time_arr[h_m_s_select]++;

//Increment

selection
if (h_m_s_select==0)
//Check to
see if user wants to edit hours (in 24 hour format), this prevents hours going over 23
{
if (eve_time_arr[h_m_s_select] > 23)
{
eve_time_arr[h_m_s_select] = 0;
}
}
else
{
if (eve_time_arr[h_m_s_select] > 59)
minutes and seconds edit, this prevents minutes and seconds going over 59
{
eve_time_arr[h_m_s_select] = 0;
}

//Else

}
dummy_time_display(eve_time_arr); //Display choice on
LCD
}

if (enter()==1)
{
write_mor_eve_time(eve_time_arr,0);
menu_branch = 0;
//Displays the time again
set_time_flag = 0; //Exit the sub menu
}

break;

case 8: //Code for setting the morning time


//Selecting hours/minutes/seconds
if(right()==1)
{
h_m_s_select++;
selection

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

//Increments the

Stuvia.com - The study-notes marketplace

if (h_m_s_select >1) //Prevents h_m_s_select to go over


1 (Only setting the hours and the minutes)
{
h_m_s_select = 0;
}
}
if(left()==1)
{
h_m_s_select--;

//Decrements the

selection
if (h_m_s_select < 0)
go under 0 (no array defined for under 0)
{
h_m_s_select = 1;
}

//Prevents h_m_s_select to

//To change hours/minutes/seconds


if (down()==1)
{
mor_time_arr[h_m_s_select]--;

//Decrement

selection
if (h_m_s_select==0)
//Check to
see if user wants to edit hours (in 24 hour format), this prevents hours going below 0
{
if (mor_time_arr[h_m_s_select] < 0)
{
mor_time_arr[h_m_s_select] = 23;
}
}
else
//Else minutes and seconds edit, this prevents minutes and seconds going below 0
{
if (mor_time_arr[h_m_s_select] < 0)
{
mor_time_arr[h_m_s_select] = 59;
}
}
dummy_time_display(mor_time_arr); //Display choice on
LCD
}
//To change hours/minutes/seconds
if (up()==1)
{
mor_time_arr[h_m_s_select]++;
selection

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

//Increment

Stuvia.com - The study-notes marketplace

if (h_m_s_select==0)
//Check to
see if user wants to edit hours (in 24 hour format), this prevents hours going over 23
{
if (mor_time_arr[h_m_s_select] > 23)
{
mor_time_arr[h_m_s_select] = 0;
}
}
else
{
if (mor_time_arr[h_m_s_select] > 59)
minutes and seconds edit, this prevents minutes and seconds going over 59
{
mor_time_arr[h_m_s_select] = 0;
}

//Else

}
dummy_time_display(mor_time_arr); //Display choice on
LCD
}

if (enter()==1)
{
write_mor_eve_time(mor_time_arr,1);
menu_branch = 0;
//Displays the time again
set_time_flag = 0; //Exit the sub menu
}
break;

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

//Function for displaying the messages on the LCD for every button press
void main_menu(char main_menu_sel)
{
switch (main_menu_sel)
{
case 1: lcd_write_string("Reset Alarm/Err"); // display the "Reset
Alarm/Err" menu option on LCD
break;
case 2: lcd_write_string("Time Settings"); // display the "Time Settings"
menu option on LCD
break;
case 3: lcd_write_string("Open Close Gate"); // display the "Open Close
Gate" menu option on LCD
break;
case 4: lcd_write_string("Accept Codes"); // display the "Accept Codes"
menu option on LCD
break;
case 5: lcd_write_string("Display Log"); // display the "Display log" menu
option on LCD
break;
case 6: lcd_write_string("Set Time"); // display the "Set Time" menu option
on LCD
break;
case 7: lcd_write_string("Set Evening"); // display the "Set Evening" menu
option on LCD
break;
case 8: lcd_write_string("Set Morning"); // display the "Set Morning" time
menu option on LCD
break;
case 9: lcd_write_string("Exit Menu"); // display the "Exit Menu" menu
option on LCD
break;
case 10: lcd_write_string("Back to Menu"); // display the "Back to Menu"
menu option on LCD
break;
} //end of switch

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

void reset_alarm(void) // disables the alarm function


{
buzzeroff(); // switch alarm off
menu_branch = 0; // reset menu pointer
}

char enter(void) // Enter key pressed execution function


{
char state;
if(ENTER == 0 && enter_flag==0)
//Enter is pressed
{
enter_flag=1;
//Indicates that button is
pressed
state=1;
}
else if(ENTER == 1 && enter_flag==1)
{
enter_flag=0;
//Button not pressed
state=0;
}
else
{
state=0;
}

return state;
}

char down(void) // Down key pressed execution function


{
char state;
if(DOWN == 0 && down_flag==0)
//Down is pressed
{
down_flag=1;
//Indicates that button is pressed
state=1;
}
else if(DOWN == 1 && down_flag==1)
{
down_flag=0;
//Button not pressed
state=0;
}
else

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

{
state=0;
}

return state;
}

char up(void) // Up key pressed execution function


{
char state;
if(UP == 0 && up_flag==0)
//UP is pressed
{
//Indicates that button is pressed
up_flag=1;
state=1;
}
else if(UP == 1 && up_flag==1)
{
up_flag=0;
//Button not pressed
state=0;
}
else
{
state=0;
}

return state;
}

char left(void) // Left key pressed execution function


{
char state;
if(LEFT == 0 && left_flag==0)
//Left is pressed
{
//Indicates that button is pressed
left_flag=1;
state=1;
}
else if(LEFT == 1 && left_flag==1)
{
left_flag=0;
//Button not pressed
state=0;
}
else
{
state=0;
}

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

return state;
}
char right(void)
{
char state;
if(RIGHT == 0 && right_flag==0)
//Right is pressed
{
right_flag=1;
//Indicates that button is
pressed
state=1;
}
else if(RIGHT == 1 && right_flag==1)
{
//Button not pressed
right_flag=0;
state=0;
}
else
{
state=0;
}
return state;
}

void dummy_time_display(int time_array[]) // Dummy time display function


{
int a=0; //counter for clock read
int time;
lcd_scrn_clear();
for (a = 0; a < 3; a++)
{
time = time_array[a]; //receive time forom timer RE
register
//integer to character conversion
//write individual characters to lcd
if (time <10)
//check if integer
is less than 10
{
lcd_character_write('0');

//write zero

before character
lcd_character_write(time +'0'); //write actual
character
}
else
{
if (time < 20 & time > 9)
integer lies in 10's range

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

//check if

Stuvia.com - The study-notes marketplace

{
time = time-10;
//integer split into two characters statement, eg. '15' becomes '5' only
lcd_character_write('1'); //write 10's
range character first, eg. '1'
lcd_character_write(time+'0'); //write
second character, eg. '5'
//the above two lcd write functions
combined gives you for example: '1'+'5' = "15".
}
if (time < 30 & time > 19) // check if integer
lies in the 20's range
{
time = time-20; //integer split into two
characters statement
lcd_character_write('2'); //write 20's
range character first
lcd_character_write(time+'0'); //write
second character, convert integer to character
}
if (time < 40 & time > 29) // check if the
integer lies in the 30's range
{
time = time-30;

//integer split into

two characters statement


lcd_character_write('3'); //write 30's
range character first
lcd_character_write(time+'0'); //write
second character, convert integer to character
}
if (time < 50 & time > 39) // check if the
integer lies in the 40's range
{
time = time-40; //integer split into two
characters statement
lcd_character_write('4'); //write 40's
range character first
lcd_character_write(time+'0'); //write
second character, convert integer to character
}
if (time < 60 & time > 49) // check if the
integer lies in the 50's range
{
time = time-50; //integer split into two
characters statement
lcd_character_write('5'); //write 50's
range character first
lcd_character_write(time+'0'); //write
second character, convert integer to character
}

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

if (time == 60) // check if the intger is 60,


max
{
time = time-60; //integer split into two
characters statement
lcd_character_write('6'); //write 60's
range character first
lcd_character_write(time+'0'); //write
second character, convert integer to character
}
}
if (a==0 || a==1) // add colon between hours, minutes,
seconds
{
lcd_character_write(':');
between hours,minutes ,and seconds
}
}

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

//writes a colon

Stuvia.com - The study-notes marketplace

Motor_current.c
#include "sfr_r827.h"
#include "serial_port.h"

char motor_current(void) // determine the current the motor is pulling


{
int voltage = 0; // set to zero initialy
char current;
char vpropi = ad; // current sensing PWM output pin
union

byte_def

nib;

nib.byte=vpropi;
//The voltage is determined via the ad converter (5V reference) (5000/255 = 19.6)
rounded to nearest whole number
if (nib.bit.b7==1)
{
voltage = voltage + 2510; //2560;
}
if (nib.bit.b6==1)
{
voltage = voltage + 1255; //1280;
}
if (nib.bit.b5==1)
{
voltage = voltage + 627; //640;
}
if (nib.bit.b4==1)
{
voltage = voltage + 314; //320;
}
if (nib.bit.b3==1)
{
voltage = voltage + 157; //160;
}
if (nib.bit.b2==1)
{
voltage = voltage + 78; //80;
}
if (nib.bit.b1==1)
{
voltage = voltage + 39; //40;
}
if (nib.bit.b0==1)
{

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

voltage = voltage + 20; //20;


}
//voltage is converted back to current by Im=Voltage/(Vcc*Rsense*Op_amp_factor)
with Vcc = 5V and Rsense = 2.2 ohm Op_amp_factor = (R2+R1)/R2 chosen to be 9
current = voltage/99;
return current; // return motor current
} // end motor_current function

void serial_port_motor_current(char current) //send motor current via serial port


{
char send_current[3]; //3 bytes
int i;
send_current[0] = (current/100) + '0';
//Converts first digit to ascii
send_current[1] = (current-(current/100)*100)/10 + '0';
//Converts second digit to ascii
send_current[2] = (current-(current/100)*100)- ((current-(current/100)*100)/10)*10
+ '0';
//Converts third digit to ascii
for (i = 0; i<=2; i++)
{
serialport_0_byte_send(send_current[i]); // send motor current to terminal
via USB cable
}
send_string("mA "); // add untis of measure to the terminal serial port display
} //end serial_port_motor_current function

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Oscillator_timers.c
#include "sfr_r827.h"
/****************************************************************/
/* Mike Blanckenberg. Voeg eie kommentaar by. Add own comments */
/****************************************************************/
oscillator_initialise()
{
asm("FCLR I"); // stop all interrupts
prc0 = 1;
// enables write to certain addresses (See p126 (pdf data))
fra00=1;
// high speed on chip oscillator = on (p102)
fra01=1;
ocd2=1;
cm06 = 0;
// klokfrekwensie/1 (p111) cm06 = 1 na herstel
pd4 = 0x00;
// P4.3, P4 inputs (for external oscillator)(note 6 p99)
// (note 6 p99)
cm04 = 1;
// (note 7 p99)
cm01 = 1;
prc0 = 0;
// write disable (p126)
asm("FSET I"); // enable interrupts
}
/************************************************************************************
Name:
timer_re_init // Renesas voorbeeldprogram / example program
Parameters: None
Returns:
None
Description: Initial setting of Timer RE SFR
************************************************************************************/
timer_re_initialise()
{
asm("FCLR I");
// stop alle onderbrekngs / stop all
interrupts
// Stop Timer RE operation
tstart_trecr1 = 0;
while(tcstf_trecr1 != 0);
// Disable Timer RE Interrupt
treic = 0x00;
trerst_trecr1 = 1;
// Timer RE Register and Control Circuit Reset
trerst_trecr1 = 0;
rcs0_trecsr = 0;
// Set to "0" in real-time clock mode
rcs1_trecsr = 0;
// Set to "0" in real-time clock mode
rcs2_trecsr = 0;
// Set to "0" in real-time clock mode
rcs3_trecsr = 1;
// Set to "1" in real-time clock mode
tresec = 0x00;
// Set to "0000000"(0 second) in
Timer RE Seconds Data
tremin = 0x00;
// Set to "0000000"(0 minute) in
Timer RE Minutes Data
trehr = 0x00;
// Set to "000000"(0 hour) in Timer RE
Hours Data
trewk = 0x00;
// Set to "000"(Sunday) in Timer RE Days
of Week Data
h12_h24_trecr1 = 0;
// Select "12-hour mode" in Operating mode
pm_trecr1 = 0;
// Select "a.m." in A.m. /p.m. bit
int_trecr1 = 1;
// Set to "1" in real-time clock mode
seie_trecr2 = 1;
// Enable periodic interrupt triggered
every second
treic = 0x07;
// Enable Timer RE Interrupt,

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

tstart_trecr1 = 1;
while(tcstf_trecr1 != 1);
asm("FSET I");

// Start Timer RE operation


// steun onderbrekings / enable interrupts

}
/**************************************************************************/
/* Setup timer rb to generate signal for the buzzer
/**************************************************************************/
void timer_b_initialise(void)
{
// Buzzer output
pd3_1 = 1;
tstart_trbcr = 0;
tocnt_trbioc = 0;
tmod1_trbmr = 0;
tmod0_trbmr = 1;
twrc_trbmr = 1;
tck0_trbmr = 0;
tck1_trbmr = 0;
trbpre = 300;
trbsc = 99;
trbpr = 99;
trbpre = 300;
trbsc = 99;
trbpr = 99;
}

*/

/****************************************************************************/
/* Setup timer a to generate interrupts for the use of acceleration control */
/****************************************************************************/

timer_a_initialise ()
{
asm("FCLR I");
interrupts
tstart_tracr = 0;
while(tcstf_tracr != 0);
tramr = 0x00;
f1 as count source (20MHz)
trapre = 0x3d;
tra = 0x3d;
traic = 0x07;
tracr = 0x03;
during count
while(tcstf_tracr != 1);
status flag is 1 during count (p.144)
asm("FSET I");
}

// stop alle onderbrekngs / stop all


// Stop Timer RA operation
//Sets Timer RA mode to timer mode and selects
//m=61
//n=61 to achieve a baud rate of 5230
// Start Timer RA operation, count status flag,
//While timer RA not counting, timer RA count
// steun onderbrekings / enable interrupts

/**************************************************************************/
/* function to switch on buzzer
*/
/**************************************************************************/
void buzzeron(void)
{

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

tstart_trbcr = 1;
}
/**************************************************************************/
/**************************************************************************/
/* function to switch off buzzer
*/
/**************************************************************************/
void buzzeroff(void)
{
tstart_trbcr = 0;
}
/***************************************************************************/

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Ports.c
#include "sfr_r827.h"
#include "ports.h"
void
void
void
void

port_3_initialise (void);
more_ports_initialise(void);
int1_initialise(void);
ad_conv_initialise();

void ports_initialise()
{
port_3_initialise();
more_ports_initialise();
ad_conv_initialise();
}
void port_3_initialise()
{
pd1_3 = 1;
ki3en = 0;
trbosel = 0;
p1drr3 = 1;
}

//
//
//
//

poort 1.3 : uittree (p77) / port 1.3 : output (p77)


ditto (p85)
ditto (p85)
maksimum drywing (p81 ) / maximum drive (p81)

void more_ports_initialise() //Function to initialise all the rest of the ports needed
{
prc2 = 1;
// write enable
// port 1_0 output
pd1_0 = 1;
p1_0 =1;
//Initially set port to 1
pd5_3 = 1;
p5_3 = 1;
pd1_1 = 0;
ki1en = 0;
pu02 = 1;

// traic output pin


// traic initially off
//Menu "UP"
// ditto (p85)

pd3_3 = 0;
ssisel = 0;
pu06 = 1;

//Menu "Down"

pd3_6 = 0;
pd3_7 = 0;
ssisel = 0;
pu07 = 1;

//Menu "Right"
//Menu "Enter"

pd5_4 = 0;
pu13 = 1;

//Menu "Left"

pd1_7 = 0;

//Light sensor port

}
void int1_initialise()
{
pd1_7 = 0;

//Light sensor input pin

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

int1ic
int1en
int1pl
int1f0
int1f1

=
=
=
=
=

0x0E;
1;
1;
1;
0;

}
void ad_conv_initialise()
{
prc2=1;
pd0_7=0;
adcon0 = 0x88;
repeat mode
adcon1 = 0x30;
adst = 1;
}

//p0_7 input port for AD converter (AN0)


//Set Analog input pin to AN0, frequency select to f2, and in
//8bit mode, Vref connected, frequenct select to f2
//Start AD converter

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

PWM.c
#include
#include
#include
#include

"sfr_r827.h"
"rtclock.h"
"menu.h"
"triac.h"

/****************************************************************************/
/*
Timer C intitialization for PWM
*/
/****************************************************************************/
timer_c_pwm()
{
trccr1 = 0x9E;
//Count source f2, CCLR, Active level "L"
trcgra = 0xEF ;
//The period T (Corresponding to 24us or 41.66kHz which
is between the required range of 35 and 45kHz)
trcgrb = 0x00;
//T1
trcmr = 0x8F;
//TSTART=1, PWM2 in timer or PWM mode, TRCIOB,
TRCIOC, TRCIOD set in PWM mode
//TRCIOC pin = P5_3, TRCIOD pin = 0 : P5_4
pinsr3 = 0x27;
trcoer = 0x0D;
//TRCIOA&TRCIOB&TRCIOC output disable (The
TRCIOA pin is used as a programmable I/O port)
}
/****************************************************************************/
/*
PWM generate function
*/
/****************************************************************************/
void pwm_generate(char direction, unsigned int pulsewidth) // function to used to read
direction of motor rotation, and speed of motor
{
unsigned int n;
//trcgrb seeting
value
unsigned int m=239;
//Value in TRCGRA register
n=(pulsewidth*m-100)/(100+pulsewidth);
//relationship between T1 & T2
(m+1)=(x/10)*(m-n), where n is the subject of the formula
if (direction == 1)
signal at pin p1_0
{
p1_0 = 1;
}
else
{
p1_0 = 0;
}

//Generate fluctuating

trcgrb = (char)n;
register setting value ,where TRCGRj=trcgrb in PWM mode

//chose n to be TRCGRj

if(pulsewidth==0) //Stops PWM


{
trcgrb = 0x00;
}
} // end pwm_generate function

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Rtclock.c
#include
#include
#include
#include
#include

"sfr_r827.h"
"serial_port.h"
"rtclock.h"
"lcd.h"
"eeprom.h"

//special function registers

void setTime (int hour, int min, int sec)


{
tstart_trecr1 = 0;
tcstf_trecr1 = 0;
ms_5_delay(); // 5 millisecond delay
trewk = 0;
ms_5_delay();
tstart_trecr1 = 0;
tcstf_trecr1 = 0;
//Decimal to hexadecimal
if (sec < 60) {tresec = (sec % 10) + (sec / 10 * 16);}
else {tresec = 0;}
ms_5_delay();
tstart_trecr1 = 0;
tcstf_trecr1 = 0;
if (min < 60){tremin = (min % 10) + (min / 10 * 16);}
else {tremin = 0;}
ms_5_delay();
tstart_trecr1 = 0;
tcstf_trecr1 = 0;
if (hour < 24)
else {trehr = 0;}
ms_5_delay();

{trehr = (hour % 10) + (hour / 10 * 16);}

tstart_trecr1 = 1; // Timer RE count start bit, count starts


tcstf_trecr1 = 1; //timer RE status flag count
h12_h24_trecr1 = 1; //24 hour mode
} // end set time function
int* getTime (void)
{
int time[3];
int a = 0;
char temp;
while (bsy_tresec == 1){;}
time[0] = trehr; // save timer RE hours to time array
while (bsy_tresec == 1){;}
time[1] = tremin; // save timer RE minutes to time array

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

while (bsy_tresec == 1){;}


time[2] = tresec; // save timer RE seconds to time array
//Hexadecimal to decimal
for (a = 0; a < 3; a++)
{
temp = time[a];
time[a] = ((temp & 0x0F)) + ((temp & 0xF0) / 16 * 10);
}
//Return format: hour, min, sec
return time; // return time array: Hours, Minutes, Seconds
} //end getTime function
void Time_display(void) //function used to write the time to LCD
{
int time; //clock read variable
int a=0; //counter for clock read
lcd_scrn_clear(); // clear screen between successive second counts
for (a = 0; a < 3; a++) // used to filter throught time array
{
time = (getTime ())[a]; //receive time from timer RE register
//integer to character conversion
//write individual characters to lcd
if (time <10)
//check if integer is less than 10
{
lcd_character_write('0');
//write zero before character
lcd_character_write(time +'0'); //write actual character
}
else
{
if (time < 20 & time > 9)
//check if integer lies in 10's
range
{
time = time-10;
//integer split into
two characters statement, eg. '15' becomes '5' only
lcd_character_write('1'); //write 10's range character
first, eg. '1'
lcd_character_write(time+'0'); //write second character, eg.
'5'
//the above two lcd write functions combined gives you for
example: '1'+'5' = "15".
}
if (time < 30 & time > 19) //check if integer lies in 20's range
{
time = time-20; //integer split into two characters statement,
eg. '25' becomes '5' only
lcd_character_write('2'); //write 20's range character first,
eg. '2'
lcd_character_write(time+'0'); //write second character, eg.
'5'
//the above two lcd write functions combined gives you for
example: '2'+'5' = "25".
}
if (time < 40 & time > 29) //check if integer lies in 30's range
{

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

time = time-30; //integer split into two characters statement


lcd_character_write('3'); //write 30's range character first,
display on LCD
lcd_character_write(time+'0'); //write second character,
convert integer to character, display on LCD
}
if (time < 50 & time > 39) //check if integer lies in 40's range
{
time = time-40; //integer split into two characters statement
lcd_character_write('4'); //write 40's range character first
lcd_character_write(time+'0'); //write second character,
convert integer to character, display on LCD
}
if (time < 60 & time > 49) //check if integer lies in 50's range
{
time = time-50; //integer split into two characters statement
lcd_character_write('5'); //write 50's range character first,
display on LCD
lcd_character_write(time+'0'); //write second character,
convert integer to character, display on LCD
}
if (time == 60) //check if integer is 60, max
{
time = time-60; //integer split into two characters statement
lcd_character_write('6'); //write 60's range character first,
max, display on LCD
lcd_character_write(time+'0'); //write second character,
convert integer to character, display on LCD
}
}
if (a==0 || a==1) // check positioning of cursor
{
lcd_character_write(':'); //writes a colon between hours,minutes
,and seconds
}
} //end for loop
} //end Time_display function

char* get_mor_eve_time(void) // fetch morning and evening times saved on the eeprom
{
int i;
char time[6]; // array for morning and evening time + dummy time
char eeprom_data; // data in eeprom
char *eeprom_data_ptr = &eeprom_data; //pointer to eeprom data
for (i=0;i<=5;i++) // execute until the total of four bytes for the
morning/evening time information is done
{
while (eeprom_read(0xA0,(41+i),eeprom_data_ptr)==0); // read the
evening/morning times from the allocated eeprom addresses
time[i] = eeprom_data; // read eeprom data into time aaray
}

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

return time; //return the time array as the output to this funtion
} // end get_more_eve_time function
void write_mor_eve_time(int time_array[], char mor_eve) // save the morning and evening
time information to the eeprom
{
char time[3]; // time array for the morning/ evening time
int i;
for(i=0;i<=2;i++)
{
time[i] = (char)time_array[i];
}

//Convert to char to store in eeprom

if (mor_eve == 1) // morning time


{
for(i=0;i<=2;i++)
{
while (eeprom_write(0xA0,41+i,time[i])==0); // write the morning
time data to the eeprom
}
}
else if (mor_eve == 0)//evening time
{
for(i=0;i<=2;i++)
{
while (eeprom_write(0xA0,44+i,time[i])==0); // write the evening
time data to the eeprom
}
}
} //end write_more_eve_time function

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Serial_port.c
#include "sfr_r827.h"
#include "serial_port.h"
/* Inisialiseer die seriepoort 0: 8 bisse, geen pariteit, 1 stopbis 38400 Baud */
/* Initialises serial port 0 : 8 bits, no parity, 1 stop bit, 38400 Baud */
void serialport_0_initialise()
{
u0brg = 0x20; //(20Mhz/(38400*16)=n forbaudrate 38400)
u0mr = 0x05;
//(8 bits, no parity, 1 stop bit)
u0c0 = 0x00;
//(f1 clock choice)
u0c1 = 0x05;
//(send and receive enabled)
s0ric = 0x7; //(Interrupt priority = 7
s0tic = 0x00; //set to zero
}
void serialport_1_initialise()
{
pinsr1 = 0x05; //Selects p4_5 as RXD1
u1pinsel=1;
u1brg = 0xEE; //(20Mhz/(5230*16)=n forbaudrate 5230)
//(8 bits, no parity, 1 stop bit)
u1mr = 0x05;
u1c0 = 0x80;
//(f1 clock choice, most significant bit first)
//(receive enabled)
re_u1c1=1;
s1ric = 0x7; //(Interrupt priority = 7
s1tic = 0x00; //set to zero
}
/* stuur een greep via seriepoort 0 */
/* sends one byte via serial port 0 */
void serialport_0_byte_send(char byte)
{
while (ti_u0c1 == 0); //Check for transmit enabled
u0tb = byte;
//Send byte
}
/***********************************************/
/* Transmit an ASCCIZ string via serial port 0 */
/***********************************************/
void send_string(char data_str[])
{
int i = 0;
while(data_str[i] != '\0')
{
serialport_0_byte_send(data_str[i]);
i++;
}
} //end send_string function
void beamoff(void) // test code to see if lightsensor functions
{
// send string via USB cable displaying the state of the light sensor, see if
obstruction occurs
char beam[] = "Beam off";
send_string(beam);

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

}
void beamon(void) // test code to check the state of the light sensor, see if no
obstruction occurs
{
char beam[] = "Beam on";
send_string(beam); // send light sensor state via serial communication
}

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Triac.c
#include
#include
#include
#include

"sfr_r827.h"
"rtclock.h"
"menu.h"
"triac.h"

//special function registers

void triac_on(void) // set curteous light on function


{
p5_3 = 0; //Triac on, curteous light on
}
void triac_off(void) // set curteous light off function
{
p5_3 = 1; //Triac off, curteous light off
}
char night_time(int evening_time[],int morning_time[]) // the function determines if the
current time is during night time
{
char night = 0; //Daytime if night = 0
int h_m_s = 0;
int current_time[3]; // If current_time falls between evening time and morning
time, the function will return a 1 for night time
int i = 0;
//To make the current_time array
for (i = 0 ; i < 3; i++)
{
current_time[i] = (getTime ())[i]; // pulls the current time from the Timer
RE clock
}
//Hour check
if (current_time[h_m_s] > evening_time[h_m_s] || current_time[h_m_s] <
morning_time[h_m_s] ) //Check if the current time is more than the user defined evening
time or less than the user defined morning time, if it is, its night time
{
night = 1;
//Die minutes is die kak
}
//Minutes check
else if (current_time[h_m_s] == evening_time[h_m_s])
{
h_m_s++;
if (current_time[h_m_s] >= evening_time[h_m_s] || current_time[h_m_s] <=
morning_time[h_m_s] )
{
night = 1; // set to night time
}
}
else
{
night = 0;
//Sets to daytime

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

}
return night; // returns 1 for night time, returns 0 for daytime
} // end night time function

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

IR Remote
Main.c
#include
#include
#include
#include
#include
#include

"sfr_r827.h"
"oscillator_timers.h"
"ports.h"
"serial_port.h"
"i2c.h"
"eeprom.h"

//special function registers

extern volatile char sec;


//globale veranderlike in 'n ander ler verklaar /
global variable declared in another file
//nota: "volatile" omdat as gevolg van 'n onderbreking
kan verander
//note: "volatile" as it can be
changed as a result of an interrupt
char s1_flag=0;
//Flag used to test if switch is pushed,
Used to avoid sending a signal repeatedly (s1_flag=0 when switch 1 is not pressed)
char s3_flag=0;
// Switch 3 flag, test if switch 3 is
pushed, avoid sending a signal repeatedly
extern volatile char two_sec_hold;
// 2 second wait flag for new access codes
generation function, switch1 & switch 3 pressed simultaneously
extern volatile char random_max; // random number factor multiplyer,
char
mV
char
char
char

bat_alarm;

// initial condition batery full = 9300

checksum;
remote_data[2];
b;

//array to read remote data from eeprom


//used when reading from eeprom

main()
{
char temp_bat_volt;
oscillator_initialise();
timer_a_initialise ();
timer_b_initialise ();
ports_initialise();
i2c_initialise();

while(1)
{

//always run, always true

/*************************************
POWER ON/OFF
*******************************************************/
if (ra_flag <=52300)
(5230 baud * 10 seconds)
{

// Keep remote on for 10 seconds

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

p0_3=1;
}
if (p0_1==0||p0_2==0)
switch 3 is pushed and if true resets the timer
{
ra_flag=0;
}
else
{
p0_3=0;
}

//Test to see if switch 1 or

/****************************************************************************************
************************/
/*************************************
SWITCH 1
*******************************************************/

if(p0_1==0 && s1_flag==0)


//If switch 1 is pushed, determine
whether a switch is held in or released, test if both switches are pressed
{
temp_bat_volt = ad;
//Shift 3 bits to right
temp_bat_volt = temp_bat_volt >> 3;
temp_bat_volt = temp_bat_volt & 0x1F;
bat_alarm = temp_bat_volt<<2;
// this must be read
from A/D converter, at moment it is set at 9300 mV
bat_alarm = bat_alarm | 0x00;
//Last hex number
form remote code: 0, 1 ,2 ,3 for 4 remotes.
//switch1 read from eeprom, used to syncronize
for (b=0;b<2;b++)
{
//while (eeprom_read(0xA0,b,eeprom_data_ptr)==0);
// execute until an acknowledgement flag is succesful, therefore read has occured
remote_data[b] = (eeprom_read_codes())[b];
//eeprom_data; //save data retrieved from eeprom into array
}
checksum = bat_alarm + remote_data[0] + remote_data[1];
determine the checksum
checksum = checksum | 0x80;
// set the MSB to 1 in the checksum variable

//

//send remote data via infra-red, using array


Button_Pressed (bat_alarm, remote_data[0], remote_data[1],
checksum);
//send data via infra-red signal
s1_flag=1;
// set exit flag
}
else if (p0_1==1 && s1_flag==1)
// determine if switch 1 is released
{
s1_flag=0;
// reset exit flag
}
/****************************************************************************************
********************/

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

/************************************
***********************/

SWITCH 1 & SWITCH 3 PRESSED Simultaneously

if (two_sec_hold ==1) // check if 2 seconds has ellapsed after S1 & S3


pressed
{
for (b=0;b<2;b++)
{
remote_data[b] = (rand()%random_max + 1)|0x80;
random code and set MSB to 1
}

//Generates

//write to eeprom write


for (b=0;b<2;b++)
//Saves new code to eeprom
{
while (eeprom_write(0xA0,b,remote_data[b])==0); //Writes one
byte on eeprom, execute until an acknowledgement flag is succesful, therefore data was
written to eeprom
}
two_sec_hold = 0;
//flag set to 0 so that commands are not run again
}
/****************************************************************************************
*******************/
/*************************************
SWITCH 3
*******************************************************/
if(p0_2==0 && s3_flag==0)
//If switch 3
is pushed, determine whether a switch is held in or released, test if both switches
pressed
{
bat_alarm = 0x00 | 0x00;
// This is
set to alarm condition
//switch1 read from eeprom, used to syncronize
for (b=0;b<2;b++)
{
remote_data[b] = (eeprom_read_codes())[b];
//call saved codes on remote eeprom
}
checksum = bat_alarm + remote_data[0] + remote_data[1];
checksum = checksum | 0x80;
// Set checksum's MSB to 1
//send remote data via infra-red, using array
Button_Pressed (bat_alarm, remote_data[0], remote_data[1],
checksum);
//send data via infra-red
s3_flag=1;
//Set flag to 1 so that commands are only run once if button is pressed
}
else if (p0_2==1 && s3_flag==1)
{
s3_flag=0;

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

}
/****************************************************************************************
********************/
} //end while
} //end main

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Eeprom.c
#include "sfr_r827.h"
#include "i2c.h"
#include "serial_port.h"
char dummy;
void nackORcomplete(void);
void nackORcomplete(void)
{
//Step 11
tend_icsr = 0; //transmit end, set to zero, in i2c bus status register
//Step 12
stop_icsr = 0; //stop condition detection flag, set to zero, in in i2c bus status
register
//Step 13
iccr2 = (iccr2&0x3F); //SCP (start/stop condition generation diable bit) and BBSY
(busy bit) set to zero,in i2c bus control register ICCR2,
//Step 14
while (stop_icsr==0); //Reads STOP bit in ICSR register and continues when STOP
bit is equal to 1
//Step 15
iccr1 = (iccr1&0xCF); //TRS bit and MST bit in ICCR1 register is set to 0
tdre_icsr = 0; // transmit data empty set to zero, in i2c bus status register
}

/* WRITE ONE CHAR TO AN ADDRESS IN THE EEPROM*/


char eeprom_write(char eeprom_address,unsigned int data_adress, char data)
{
char return_char;
unsigned char mem_add1;
unsigned char mem_add2;
mem_add1 = (data_adress>>8)&0xFF;
mem_add2 = data_adress&0xFF;

//Most significant byte of int


//Least significant byte of int

//Step 1
while (bbsy_iccr2==1);
register

//Read BBSY byte in ICCR2

//Step 2
iccr1 = (iccr1&0xFF)|0x30;
register is set to 1

//TRS bit and MST bit in ICCR1

//Step 3
iccr2 = (iccr2&0x3F)|0x80;
BBSY =1), Generate start condition

//Write BBSY bit (Set SCP=0 and

//Step 4

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

icdrt = (eeprom_address)|0x00;

//Device select: Slave address +

R/nW
//Step 5
while (tend_icsr==0);
register, wait till TEND bit equals 1 to continue

//Read TEND bit in ICSR

/****************************************************************************/
/*
MASTER TRANSMIT MODE
*/
/****************************************************************************/
//Step 6
if (ackbr_icier==0)
//check if receive acknowledge bit
is zero, yeas, then steps 7 to end, otherwise go to step 11
{
//Step 7 & 8
icdrt = mem_add1;
//transmit data register
receives value of most significant byte of address in eeprom
while (tdre_icsr == 0);
//check if transmit data is empty,
makes sure data is received
//Step 7 & 8
icdrt = mem_add2;
//transmit data register
receives value of least significant byte of address in eeprom
while (tdre_icsr == 0);
//check if transmit data is empty,
makes sure data is received
//Step 9
// transmit data
icdrt = data;
register recieves the actual data to be written to eeprom
//Step 10
while (tend_icsr == 0);
// wait for end of transmission of
the last byte
return_char = 1;
sent, transmission successful
}
else return_char = 0;
sent, transmission unsuccessful
nackORcomplete();
return return_char;
function output
}

// acknowledgement flag

// not acknowledgement flag

// steps 11 through to 15
// send acknowledgement flag,

/*READ ONE CHAR FROM AN ADDRESS IN THE EEPROM*/


char eeprom_read(char eeprom_address,unsigned int data_adress, char *data)
{
char return_char;
unsigned char mem_add1;
unsigned char mem_add2;
mem_add1 = (data_adress>>8)&0xFF;
mem_add2 = data_adress&0xFF;

//Most significant byte of int


//Least significant byte of int

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

//WRITE THE ADDRESS WHERE THE DATA MUST BE ACCESSED


//Step 1
while (bbsy_iccr2==1);
SCL and SDA lines

//judge the state of the

//Step 2
iccr1 = (iccr1&0xFF)|0x30;
register is set to 1

//TRS bit and MST bit in ICCR1

//Step 3
iccr2 = (iccr2&0x3F)|0x80;
BBSY =1), Generate start condition

//Write BBSY bit (Set SCP=0 and

//Step 4
icdrt = (eeprom_address)|0x00;

//Device select

//Step 5
while (tend_icsr==0);
register, wait till TEND bit equals 1 to continue

//Read TEND bit in ICSR

//Step 6
if (ackbr_icier == 0)
//check if receive
acknowledge bit is zero, yeas, then steps 7 to end, otherwise go to step 11
{
//Step 7 & 8
//The address of the data,
icdrt = mem_add1;
transmit data register receives value of most significant byte of address in eeprom to be
read from
while (tdre_icsr == 0);
//check if transmit data is empty,
makes sure data is received
//Step 9 & 10
icdrt = mem_add2;
//The address of the data,
The address of the data, transmit data register receives value of least significant byte
of address in eeprom to be read from
while (tend_icsr == 0);
//check if transmit data is empty,
makes sure data is received
}
else
{
nackORcomplete();
return 0;
acknowledgement flag sent as output of function
}

//not

//Step 11
tend_icsr = 0;
to zero, in i2c bus status register
//READ DATA FROM THE ADDRESS IN EEPROM
//Step 2
iccr1 = (iccr1&0xFF)|0x30;
register is set to 1
//Step 3
iccr2 = (iccr2&0x3F)|0x80;

//transmit end, set

//TRS bit and MST bit in ICCR1

//Generate start condition

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

//Step 4
icdrt = (eeprom_address)|0x01;

//Device select and sets to read

mode
//Step 5
while (tend_icsr == 0);
wait till TEND bit equals 1 to continue

//Read TEND bit in ICSR register,

/****************************************************************************/
/*
MASTER RECEIVE MODE
*/
/****************************************************************************/
//Step 6
if (ackbr_icier == 0)
//check if receive
acknowledge bit is zero, yeas, then steps 1 & 7-end to end of master recieve mode,
otherwise go to step 11 onwards in master transmit mode
{
//Step 1
//Set transmit end
tend_icsr = 0;
to zero, in i2c bus status register
trs_iccr1 = 0;
//Set
transfer/receive select bit, in i2c bus control register to zero
tdre_icsr = 0;
//Set transmit data
empty, in i2c bus status register to zero
//Step 7 (Step 2 to 6 skipped)
ackbt_icier = 1;
// transmit acknowledgement
select bit set to 1, in i2c bus interrupt enable register, in receive mode
// Receive disable bit set
rcvd_iccr1 = 1;
to 1, in i2c bus control register 1, disables next receive operation
//Step 8
dummy = icdrr;

//Dummy read ICDRR

register
//Step 9
while (rdrf_icsr == 0);

//wait until the last byte is

received
//Step 10
stop_icsr = 0;
condition detection flag back to zero, in i2c bus status register

// set stop

//Step 11
iccr2 = (iccr2&0x3F);
// set SCP (start/stop
condition generation diable bit) and BBSY (bus busy bit) to zero, in i2c bus control
register 2
//Step 12
while (stop_icsr == 0);

// Checks the stop bit in the ICSR

register
//Step 13
*data = icdrr;

//Read ICDRR

register
//Step 14

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

rcvd_iccr1 = 0;
//Step 15
mst_iccr1 = 0;
return 1;
flag, successful

// acknowledgment

}
else
{
nackORcomplete();
return 0;
acknowledgement flag, unsuccessful
}
}

// not

void eeprom_remote_code_initialise (void)


{
char eeprom_code1 = 0b10001111;
char eeprom_code2 = 0b10000111;
while (eeprom_write(0xA0,0,eeprom_code1)==0);
while (eeprom_write(0xA0,1,eeprom_code2)==0);
}

char* eeprom_read_codes (void)


{
char eeprom_data;
char *eeprom_data_ptr = &eeprom_data;
char i;
char remote_data[2];
for (i=0;i<2;i++)
{
while (eeprom_read(0xA0,i,eeprom_data_ptr)==0); // execute until an
acknowledgement flag is succesful, therefore read has occured
//save
remote_data[i] = eeprom_data;
data retrieved from eeprom into array
}
return remote_data;
}

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

I2c.c
#include "sfr_r827.h"
#include "i2c.h"

/**********************************************************************************/
/* Initialize the i2c
*/
/**********************************************************************************/
void i2c_initialise(void)
{
sar=0x10;
iicsel=1;
ice_iccr1 = 1;
iccr1=(iccr1 & 0xf0)|(0x0D);
}

//slave address of the controller


//i2c choosen
//100 kHz

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Intrprg.c
/***********************************************************************/
/*
*/
/* FILE
:intprg.c
*/
/* DATE
:Mon, Feb 18, 2008
*/
/* DESCRIPTION :define the top address of the interrupt vectors.
*/
/* CPU GROUP
:27
*/
/*
*/
/* This file is generated by Renesas Project Generator (Ver.4.8).
*/
/*
*/
/***********************************************************************/
/***************************************************************************
* COMPILER for M16C/60,R8C/Tiny
* Copyright(c) 2004 Renesas Technology Corp.
* And Renesas Solutions Corp.,All Rights Reserved.
* intprg.c : define variable vector table
*
for R8C/27,26
*
*
* $Date: 2006/09/13 05:29:23 $
* $Revision: 1.3 $
**************************************************************************/
#include "sfr_r827.h"
#include "cstartdef.h"
#include "serial_port.h"
#include "eeprom.h"

volatile long int ra_flag=0;


//counter for counting the
interrupts of RA (for automatic power on/off)
volatile char two_sec_hold = 0;
//flag that's set if the both switches
are held in for 2 seconds, external variable which is set to zero in main() after an
operation has been executed
volatile char random_max = 0;
//variable to make rand() more
random (counts from 0 to 255 and repeats whole time)
volatile int multiple_button_timer = 0;
//counter that counts the time the two
buttons are held in
volatile char switch_exit_flag = 0;
//flag so that commands is only
carried out once when the two buttons is pressed.
// When you want to use BANK1 registers
// please define interrupt using /B swtich as follows.
//
// #pragma interrupt/B xxxx
//
// BRK
#pragma interrupt
void _brk(void){}
//
//
//
//

vector
vector
vector
vector

1
2
3
4

(software int 0)
_brk(vect=0)

reserved
reserved
reserved
reserved

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

// vector 5 reserved
// vector 6 reserved
// timer RC (channel 0)
(software int 7)
#pragma interrupt
_timer_rc(vect=7)
void _timer_rc(void){}
// vector 8 reserved
// vector 9 reserved
// timer RE
(software int 10)
#pragma interrupt
_timer_re(vect=10)
void _timer_re(void)
{
}
// vector 11 reserved
// vector 12 reserved
// input_key
(software int 13)
#pragma interrupt
_input_key(vect=13)
void _input_key(void){}
// A-D converter
(software int 14)
#pragma interrupt
_ad_converter(vect=14)
void _ad_converter(void){}
// SSU IIC
#pragma interrupt
void _ssu(void){}

(software int 15)


_ssu(vect=15)

// vector 16 reserved
#if defined (__STANDARD_IO__) && (defined(__FOUSB__) ||
// uart0 can't be used
#else
// uart0 trance
(software int 17)
#pragma interrupt
_uart0_trance(vect=17)
void _uart0_trance(void){}
#endif

defined(__E8__))

// uart0 receive
(software int 18)
#pragma interrupt
_uart0_receive(vect=18)
void _uart0_receive(void)
{
// eie seriepoort kode / own serial port code here
}
#if defined(__STANDARD_IO__) || defined(__FOUSB__) || defined(__E8__)
// uart1 can't be used
#else
// uart1 trance
(software int 19)
#pragma interrupt
_uart1_trance(vect=19)
void _uart1_trance(void){}
#endif
// uart1 receive
(software int 20)
#pragma interrupt
_uart1_receive(vect=20)
void _uart1_receive(void){}

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

// vector 21 reserved
// timer RA
(software int 22)
#pragma interrupt
_timer_ra(vect=22)
void _timer_ra(void)
{
ra_flag++;
random_max++;
/*************************************
***********************/

SWITCH 1 & SWITCH 3 PRESSED Simultaneously

if (p0_1==0 && p0_2==0 && switch_exit_flag == 0)


// check if switch 1 & switch 3 pressed at the same time
{
if (multiple_button_timer++ >= (2*5230))
// hold for 2 seconds, both switches pressed
{
two_sec_hold = 1;
// two second hold flag set if the switched held in for 2 seconds
switch_exit_flag = 1;
// set switch_exit flag to 1 so that commands is only carried out
once when the two buttons is pressed.
}
}
else if (p0_1==1 && p0_2==1 && switch_exit_flag == 1)
//
check if switches 1 & 3 are released
{
multiple_button_timer = 0;
//reset 2 second timer
two_sec_hold = 0;
// reset 2 second hold flag
switch_exit_flag = 0;
// reset if satement exit flag
}
/****************************************************************************************
*******************/
}
// vector 23 reserved
// timer RB
(software int 24)
#pragma interrupt
_timer_rb(vect=24)
void _timer_rb(void){}
// int1
#pragma interrupt
void _int1(void){}

(software int 25)


_int1(vect=25)

// int3
#pragma interrupt
void _int3(void){}

(software int 26)


_int3(vect=26)

// vector 27 reserved
// vector 28 reserved

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

// int0
#pragma interrupt
void _int0(void){}

(software int 29)


_int0(vect=29)

// vector 30 reserved
// vector 31 reserved
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//

vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user
for user

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Oscillator_timers.c
#include "sfr_r827.h"
/****************************************************************/
/* Mike Blanckenberg. Voeg eie kommentaar by. Add own comments */
/****************************************************************/
oscillator_initialise()
{
asm("FCLR I");
prc0 = 1;
//Set the PRC0 bit in the PRCR register to 1 (write
enable) before rew riting the FRA0 register
fra00 = 1;
//High-speed on-chip oscillator on
fra01 = 1;
//Selects high-speed on-chip oscillator
ocd2 = 1;
//Selects on-chip oscillator
cm06 = 0;
//CM 16 & CM 17 enabled
prc0 = 0;
asm("FSET I");

//write disabled in CM0 register

}
timer_a_initialise ()
{
asm("FCLR I");
all interrupts
tstart_tracr = 0;
while(tcstf_tracr != 0);
tramr = 0x00;
selects f1 as count source (20MHz)
trapre = 0x3d;
tra = 0x3d;
5230
traic = 0x07;
tracr = 0x03;
flag, during count
while(tcstf_tracr != 1);
status flag is 1 during count (p.144)
asm("FSET I");
interrupts
}

// stop alle onderbrekngs / stop


// Stop Timer RA operation
//Sets Timer RA mode to timer mode and
//m=61
//n=61 to achieve a baud rate of

// Start Timer RA operation, count status


//While timer RA not counting, timer RA count
// steun onderbrekings / enable

timer_b_initialise ()
{
tstart_trbcr = 0;
//Timer B stops
while(tcstf_trbcr != 0);
//While timer RA counting, timer RA count status
flag is 1 during count, 0 for count stop (p.144)
tocnt_trbioc = 0;
//Timer RB output switch bit set to 0,
Timer RB I/O Control Register p.161
trbmr=0x09;
//Programmable wave generation
mode, Write to reload register only, Timer RB Mode Register p.161
trbpre = 68;
//n
trbsc = 3;
//p
trbpr = 3;
//m
}
void ms_5_delay(void)

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

{
int k;
int N=5000;
with the led output pin with the oscilloscope.
for (k=0;k<N;k++);
}

//N is worked out by measuring a for loop

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Ports.c
#include "sfr_r827.h"
#include "ports.h"
void port_0_initialise (void);
void port_3_initialise (void);
void ad_conv_initialise (void);

void ports_initialise()
{
port_0_initialise();
port_3_initialise();
ad_conv_initialise();
}
void port_3_initialise()
{
pd1_3 = 1;
ki3en = 0;
trbosel = 0;
p1drr3 = 1;
}

//
//
//
//

poort 1.3 : uittree (p77) / port 1.3 : output (p77)


ditto (p85)
ditto (p85)
maksimum drywing (p81 ) / maximum drive (p81)

void port_0_initialise()
{
prc2=1;
//PRC2 bit in the PRCR register to
1 (write enable), Writing to the PD0 register is enabled p.109
//Port P0_3/AN4, set to output port p.65
pd0_3=1;
pu00=1;
//Pulled up by setting the PU00
bit in the PUR0 register to 1 p.65
}
void ad_conv_initialise()
{
prc2=1;
pd0_7=0;
adcon0 = 0x88;
adcon1 = 0x30;
adst = 1;
}

//p0_7 input port for AD converter (AN0)


// A/D Control Register 0, repeat mode,
// A/D Control Register 1,
// start condition

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Serial_port.c
#include "sfr_r827.h"
#include "serial_port.h"

volatile int ir_count=0;


//infra-red bit counter set to 0, used to
determine which bit of the signal needs to send.
void send_bit(int bit)
the 36kHz signal or deactivates it
{
if (bit==1)
is a logical 1 on transmitter side (remote)
{
tstart_trbcr = 0;
side
while(tcstf_trbcr != 0);
//wait
changes
}
else if (bit==0)
logical 0 on transmitter side (remote)
{
tstart_trbcr = 1;
side
}
}
// end send_bit function

//Function to check the bit and activates

//Execute statement if signal read

//To make a logical one on the receptive


till the timer RB counts status flag

//Execute statement if signal read is a

//To make a logical zero on the receptive

/* stuur een greep via IR */


/* sends one byte via IR */
void byte_send(char byte)
{
union byte_def
nibble;
nibble.byte=byte;
//data bit
ir_count=0;
pointer set to 0
ir_flag = 0;
//Timer RA interrupt
acknowledgement flag, set to zero, if timer RA interrupts then ir_flag is set to 1
while (ir_count<10)
//Run until the
entire byte with start and stop bits are sent, 10 bits, 1 start, 8 data bits, and 1 stop
bit.
{
if (ir_flag==1)
//test for a
Timer RA interrupt
{
switch(ir_count)
//Used to determine
which bit is looked at
{
case 0:
send_bit(0);
//Start bit sent
ir_count++;
//increment
infra-red flag which points to next bit.
break;
//exit when
bit is sent

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

case 1:
send_bit(nibble.bit.b7);

//MSB, most significant bit

send b7
ir_count++;
infra-red flag which points to next bit.
break;
bit is sent
case 2:
send_bit(nibble.bit.b6);
ir_count++;
infra-red flag which points to next bit.
break;
bit is sent
case 3:
send_bit(nibble.bit.b5);
ir_count++;
infra-red flag which points to next bit.
break;
bit is sent
case 4:
send_bit(nibble.bit.b4);
ir_count++;
infra-red flag which points to next bit.
break;
bit is sent
case 5:
send_bit(nibble.bit.b3);
ir_count++;
infra-red flag which points to next bit.
break;
bit is sent
case 6:
send_bit(nibble.bit.b2);
ir_count++;
infra-red flag which points to next bit.
break;
bit is sent
case 7:
send_bit(nibble.bit.b1);
ir_count++;
infra-red flag which points to next bit.
break;
bit is sent
case 8:
send_bit(nibble.bit.b0);

//increment
//exit when

//bit b6 send
//increment
//exit when

//bit b5 send
//increment
//exit when

//bit b4 send
//increment
//exit when

//bit b3 send
//increment
//exit when

//bit b2 send
//increment
//exit when

//bit b1 send
//increment
//exit when

//LSB, Least signigicant

bit b0 send
ir_count++;
infra-red flag which points to next bit.
break;
bit is sent

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

//increment
//exit when

Stuvia.com - The study-notes marketplace

case 9:
send_bit(1);
//Stop bit
ir_count++;
//increment
infra-red flag which points to next bit.
break;
//exit when
bit is sent
} // end switch satement
ir_flag=0;
//set timer
RA interrupt acknowledgement flag to 0, after intterupt has occured. sets to default
} // end if statement
} //end while statement
} // end function
void Button_Pressed (char Bat_Alarm, char code1, char code2, char Checksum)
{
byte_send(Bat_Alarm);
// Send remote
battery condition
//wait after byte sent, allows for succesive transmission of seqeuntial byte
sending via infra-red remote
ms_5_delay();
ms_5_delay();
ms_5_delay();
ms_5_delay();
byte_send(code1);
access code
//wait after byte sent
ms_5_delay();
ms_5_delay();
ms_5_delay();
ms_5_delay();

// send part one of

byte_send(code2);
access code
//wait after byte sent
ms_5_delay();
ms_5_delay();
ms_5_delay();
ms_5_delay();

// send part two of

byte_send(Checksum);
//wait after byte sent
ms_5_delay();
ms_5_delay();
ms_5_delay();
ms_5_delay();

// send checksum

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Appendix D

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

BRIGHT LED ELECTRONICS CORP.


SINCE 1981

Total Page: 6
Page:
1
Revision: 2.0

Customer P/N:
Device NumberBPI-3C1-05
Features:
 Non-contact switching.
 For direct PC board or dual-in-line socket mounting.
 Fast switching s peed.
 This product doesn't contain restriction substance, comply ROHS
standard.
Sheet
Date

2001.12.20 1.0 1.0 1.0 1.0 1.0 1.0


2002.01.08 1.1 1.0 1.1 1.0 1.0 1.1
2002.03.21 1.2 1.1 1.1 1.0 1.0 1.1
2002.12.12 1.3 1.0 1.2 1.1 1.0 1.2
2004.10.26 1.4 --

2004.11.26 2.0 1.0 1.2 1.1 1.0 1.3


Total Page

Contents
Initial Released
 Packaging Dimensions:
Pin Length: 9.12mm3.5mm
2. Packaging Bag Dimensions
Light Current:
IL: max 10Ma5Ma
 Packaging Dimensions:
Slit Width 1.1mm0.4mm
2.Packaging Bag Dimensions
Features
Packaging

BRIGHT LED ELECTRONICS CORP.


19 3
3F., No. 19, Ho Ping Road, Pan Chiao City,
Taipei, Taiwan, R. O. C.
Tel: 886-2-29591090
Fax: 886-2-29547006/29558809
www.brtled.com.

No.8 Gaolong eastwayLuxiprecinctGaobu


Town Dongguan city Guangdong Province
China
Tel886-0769-8730255 8731855
Fax886-0769-8733355 8738706
www.brtled.com

Approved

Checked

2004.11.26

2004.11.26

2004.11.26

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Drawn

Stuvia.com - The study-notes marketplace

BRIGHT LED ELECTRONICS


Device NumberBPI-3C1-05
Absolute Maximum Rating (Ta=25)

Page:
Version:

Item

2
1.1

Symbol

Rating

Unit

Power Dissipation

Pd

75

mW

Reverse Voltage

VR

Forward Current

IF

50

mA

(*1)

IFP

Collector Power Dissipation

PC

100

mW

Collector Current

IC

40

mA

C-E Voltage

VCEO

30

E-C Voltage

VECO

Operating Temperature

Topr

-25 ~ +85

Storage Temperature

Tstg

-40 ~ +100

Tsol

260

Input
Peak Forward Current

Output

Soldering Temperature

(*2)

(*1) tw=100 uSec.T=10 mSec.

(*2) t=5 Sec

Electrical Optical Characteristics (Ta=25)

Parameter

Input

Symbol

Condition

Min.

Typ.

Max.

Unit

Forward Voltage

VF

IF=20mA

1.2

1.5

Reverse Current

IR

VR=5V

100

Peak Wavelength

IF=10mA

ID

VCE=10V

100

nA

VCE(sat)

IC=0.25mA
IF=10mA

0.4

IL

VCE=5V
IF=10mA

0.5

5.0

mA

20

sec

20

sec

Dark Current
Output
C-E Saturation Voltage

Light Current
Rise Time

Tr

Fall Time

Tf

Speed

IFP=20mA
VCE=5V
RL=1000

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

940

nm

Stuvia.com - The study-notes marketplace

BRIGHT LED ELECTRONICS


Device NumberBPI-3C1-05
Package Dimensions

Notes:
1. All dimensions are in millimeters (inches).
2. Tolerance is &0.25mm unless otherwise specified.
3. Lead spacing is measured where the leads emerge from the package.

4. Specifications are subject to change without notice.


Downloaded by:: macylnt | macylnt@gmail.com
Distribution of this document is illegal

Page:
Version:

3
1.2

Stuvia.com - The study-notes marketplace

BRIGHT LED ELECTRONICS


Device NumberBPI-3C1-05
Typical Electrical / Optical Characteristics Curves (Ta=25)

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Page:
Version:

4
1.0

Stuvia.com - The study-notes marketplace

BRIGHT LED ELECTRONICS


Device NumberBPI-3C1-05
Typical Electric / Optical Characteristics Curves (Ta=25)

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Page:
Version:

5
1.0

Stuvia.com - The study-notes marketplace

BRIGHT LED ELECTRONICS

Device NumberBPI-3C1-05
Packaging Box Dimensions

Packaging Tube Dimensions

Notes:
1. 35pcs per tube, 2.73kpcs per box.
2. All Dimensions are in millimeters (inches).
3. Specifications are subject to change without notice.

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Page:
Version:

6
1.3

Stuvia.com - The study-notes marketplace

DRV8800
DRV8801
www.ti.com

SLVS855E JULY 2008 REVISED OCTOBER 2010

DMOS FULL-BRIDGE MOTOR DRIVERS


Check for Samples: DRV8800, DRV8801

FEATURES

Low ON-Resistance [Rds(ON)] Outputs


Overcurrent Protection
Motor Lead Short-to-Supply Protection
Short-to-Ground Protection
Low-Power Mode
Synchronous Rectification
Diagnostic Output
Internal Undervoltage Lockout (UVLO)

Crossover-Current Protection
16-Pin QFN With PowerPAD Package
xxx

APPLICATIONS

Printers
Industrial Automation

DESCRIPTION/ORDERING INFORMATION
Designed to control dc motors by using pulse width modulation (PWM), the DRV8800/DRV8801 is capable of
peak output currents up to 2.8 A and operating voltages up to 36 V.
The PHASE and ENABLE inputs provide dc motor speed and direction control by applying external pulse-width
modulation (PWM) and control signals. Internal synchronous rectification control circuitry provides lower power
dissipation during PWM operation.
Internal circuit protection includes motor lead short-to-supply/short-to-ground, thermal shutdown with hysteresis,
undervoltage monitoring of VBB and VCP, and crossover-current protection.
The DRV8800/DRV8801 is supplied in a thin-profile 16-pin QFN (RTY) PowerPAD package, providing
enhanced thermal dissipation. The devices are lead free (Pb free).
ORDERING INFORMATION
TA

PACKAGE

(1) (2)

ORDERABLE PART NUMBER

Plastic QFN 16 (S-PQFP-16) RTY


40C to 85C
TSSOP - PWP

(1)
(2)

TOP-SIDE MARKING

DRV8800RTYR

DRV8800

DRV8800RTYT

DRV8800

DRV8801RTYR

DRV8801

DRV8801RTYT

DRV8801

DRV8800PWP

DRV8800

DRV8800PWPR

DRV8800

DRV8801PWP

DRV8801

DRV8801PWPR

DRV8801

For the most current package and ordering information, see the Package Option Addendum at the end of this document, or see the TI
website at www.ti.com.
Package drawings, thermal data, and symbolization are available at www.ti.com/packaging.

Please be aware that an important notice concerning availability, standard warranty, and use in critical applications of Texas
Instruments semiconductor products and disclaimers thereto appears at the end of this data sheet.
PowerPAD is a trademark of Texas Instruments Incorporated.

PRODUCTION DATA information is current as of publication date.


Products conform to specifications per the terms of the Texas
Instruments standard warranty. Production processing does not
necessarily include testing of all parameters.

Copyright 20082010, Texas Instruments Incorporated

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

DRV8800
DRV8801
SLVS855E JULY 2008 REVISED OCTOBER 2010

www.ti.com

DRV8801
RTY PACKAGE
(TOP VIEW)

nFAULT

VPROPI

VCP

14

13

VCP
13

15

VREG
14

MODE 1

nFAULT
15

16

MODE
16

DRV8800
RTY PACKAGE
(TOP VIEW)

nSLEEP

10

CP1

nSLEEP

10

CP1

ENABLE

OUT-

ENABLE

OUT-

CP2

VBB

11

SENSE

GND

CP2

OUT+

11

MODE 2

GND

GND

VBB

12

SENSE

PHASE

GND

OUT+

12

NC

PHASE

NC Do not connect

TERMINAL FUNCTIONS
TERMINAL
NO.

NAME
DRV8800

DESCRIPTION
DRV8801

PHASE

PHASE

Phase logic input for direction control

GND

GND

Ground

nSLEEP

nSLEEP

Sleep logic input

ENABLE

ENABLE

Enable logic input

NC

MODE 2

No connect (DRV8800), Mode 2 logic input (DRV8801)

OUT+

OUT+

DMOS full-bridge output positive

SENSE

SENSE

Sense power return

VBB

VBB

Load supply voltage

OUT-

OUT-

DMOS full-bridge output negative

10

CP1

CP1

Charge-pump capacitor 1

11

CP2

CP2

Charge-pump capacitor 2

12

GND

GND

Ground

13

VCP

VCP

Reservoir capacitor

14

VREG

VPROPI

Regulated voltage (DRV8800), Winding current proportional voltage output (DRV8801)

15

nFAULT

nFAULT

Fault open-drain output

16

MODE

MODE 1

Mode logic input

PowerPAD

PowerPAD

Exposed pad for thermal dissipation connect to GND pins

Submit Documentation Feedback

Copyright 20082010, Texas Instruments Incorporated

Product Folder Link(s): DRV8800 DRV8801

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

DRV8800
DRV8801

www.ti.com

SLVS855E JULY 2008 REVISED OCTOBER 2010

DRV8800
PWP PACKAGE
(TOP VIEW)

DRV8801
PWP PACKAGE
(TOP VIEW)

nFAULT

16

NC

MODE

15

VREG

PHASE

14

VCP

GND

13

GND

nSLEEP

12

CP2

ENABLE

11

CP1

OUT+

10

OUT-

SENSE

VBB

nFAULT

16

MODE 2

MODE 1

15

VPROPI

PHASE

14

VCP

GND

13

GND

nSLEEP

12

CP2

ENABLE

11

CP1

OUT+

10

OUT-

SENSE

VBB

NC Do not connect

TERMINAL FUNCTIONS
TERMINAL
NO.

NAME
DRV8800

DESCRIPTION
DRV8801

nFAULT

nFAULT

Fault open-drain output

MODE

MODE 1

Mode logic input

PHASE

PHASE

Logic input for direction control

GND

GND

Ground

nSLEEP

nSLEEP

Sleep logic input

ENABLE

ENABLE

Enable logic input

OUT+

OUT+

DMOS full-bridge output positive

SENSE

SENSE

Sense power return

VBB

VBB

Load supply voltage

10

OUT-

OUT-

DMOS full-bridge output negative

11

CP1

CP1

Charge-pump capacitor 1

12

CP2

CP2

Charge-pump capacitor 2

13

GND

GND

Ground

14

VCP

VCP

Reservoir capacitor

15

VREG

VPROPI

Regulated voltage (DRV8800), Winding current proportional voltage output (DRV8801)

16

NC

MODE 2

No connect (DRV8800), Mode 2 logic input (DRV8801)

PowerPAD

PowerPAD

Exposed pad for thermal dissipation connect to GND pins

Submit Documentation Feedback

Copyright 20082010, Texas Instruments Incorporated

Product Folder Link(s): DRV8800 DRV8801

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

DRV8800
DRV8801
SLVS855E JULY 2008 REVISED OCTOBER 2010

www.ti.com

DRV8800 TYPICAL APPLICATION DIAGRAM

Submit Documentation Feedback

Copyright 20082010, Texas Instruments Incorporated

Product Folder Link(s): DRV8800 DRV8801

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

www.ti.com

DRV8800
DRV8801
SLVS855E JULY 2008 REVISED OCTOBER 2010

DRV8801 TYPICAL APPLICATION DIAGRAM

Submit Documentation Feedback

Copyright 20082010, Texas Instruments Incorporated

Product Folder Link(s): DRV8800 DRV8801

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

DRV8800
DRV8801
SLVS855E JULY 2008 REVISED OCTOBER 2010

www.ti.com

DRV8800 FUNCTIONAL BLOCK DIAGRAM


.1 uf

CP1

CP2

VBB

VCP

.1 uf

Charge Pump
VREG
Optional

VBB
Low-Side
Gate Supply

.22 uf

Bias
Supply

MODE

100 uf

.1 uf

PHASE
OUT+

ENABLE

VDD

Control
Logic
OUT-

3.3K

3.3K

nSLEEP
SENSE
nFAULT
UVLO
VBB

Motor lead
Protection

STB
STG
TSD

OUT+
OUTSENSE

GND

GND
PAD

Submit Documentation Feedback

Copyright 20082010, Texas Instruments Incorporated

Product Folder Link(s): DRV8800 DRV8801

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

www.ti.com

DRV8800
DRV8801
SLVS855E JULY 2008 REVISED OCTOBER 2010

DRV8801 FUNCTIONAL BLOCK DIAGRAM


.1 uf

CP1

VPROPI

CP2

VBB

VCP

SENSE

.1 uf

X5
Charge Pump
VBB

MODE 1
Bias
Supply

MODE 2

100 uf

.1 uf

PHASE
OUT+

Control
Logic
ENABLE

VDD

OUT3.3K

3.3K

nSLEEP
SENSE
nFAULT
UVLO
STB

Motor lead
Protection

STG
TSD

VBB
OUT+
OUTSENSE

GND

GND
PAD

Submit Documentation Feedback

Copyright 20082010, Texas Instruments Incorporated

Product Folder Link(s): DRV8800 DRV8801

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

DRV8800
DRV8801
SLVS855E JULY 2008 REVISED OCTOBER 2010

www.ti.com

ABSOLUTE MAXIMUM RATINGS (1)


over operating free-air temperature range (unless otherwise noted)
MIN

VSense

VDD

2.8

Sense voltage

500

V
A
mV

VBB to OUTx

36

OUTx to SENSE

36

(2)

0.3

Human-Body Model (HBM)


Charged-Device Model (CDM)
Continuous total power dissipation

TA

Operating free-air temperature range

TJ

Maximum junction temperature

Tstg

Storage temperature range

(2)

UNIT

40

Output current

Logic input voltage

ESD rating

(1)

MAX

Load supply voltage (2)

VBB

kV

500

See Dissipation Ratings Table


40
40

85

190

125

Stresses beyond those listed under absolute maximum ratings may cause permanent damage to the device. These are stress ratings
only, and functional operation of the device at these or any other conditions beyond those indicated under recommended operating
conditions is not implied. Exposure to absolute-maximum-rated conditions for extended periods may affect device reliability.
All voltage values are with respect to network ground terminal.

DISSIPATION RATINGS
TA = 25C
POWER RATING

DERATING FACTOR
ABOVE TA = 25C

41.6

3W

24 mW/C

32.6

3.8 W

31 mW/C

PACKAGE

qJA

RTY
PWP

RECOMMENDED OPERATING CONDITIONS


VIN

Input voltage, VBB

TA

Operating free-air temperature

MIN

NOM

MAX

32

38

85

40

Submit Documentation Feedback

UNIT

Copyright 20082010, Texas Instruments Incorporated

Product Folder Link(s): DRV8800 DRV8801

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

www.ti.com

DRV8800
DRV8801
SLVS855E JULY 2008 REVISED OCTOBER 2010

ELECTRICAL CHARACTERISTICS
over recommended operating conditions (unless otherwise noted)
PARAMETER

TEST CONDITIONS

MIN

fPWM < 50 kHz


IBB

Motor supply current

TYP

Charge pump on, Outputs disabled

VIL
VIH
VIL
IIH
IIL
IIH
IIL
IIH
IIL

0.8
2.7

nSLEEP input voltage

0.8
VIN = 2 V

PHASE, MODE input current

nSLEEP input current

20

VIN = 2 V

40

100

VIN = 0.8 V

16

40

VIN = 2.7 V

27

50

VIN = 0.8 V

<1

10
0.4

12

13.8

500

800

mV

nFAULT output voltage

Isink = 1 mA

VBB nFAULT release

8 V < VBB < 40 V

VIHys

Input hysteresis, except nSLEEP

VTRP

RSENSE/ISense voltage trip

Vf

Body diode forward voltage

tpd

Propagation delay time

tCOD

Crossover delay

DAGain

Differential AMP gain

2.0

VBBNFR

20

100

Output ON resistance

20

VIN = 0.8 V

ENABLE input current

mA

<1.0

VOL

Rds(ON)

10
2

PHASE, ENABLE,
MODE input voltage

UNIT
mA

3.2

Sleep mode
VIH

MAX

Source driver, IOUT = 2.8 A, TJ = 25C

0.48

Source driver, IOUT = 2.8 A, TJ = 125C

0.74

Sink driver, IOUT = 2.8 A, TJ = 25C

0.35

Sink driver, IOUT = 2.8 A, TJ = 125C

0.52

SENSE connected to ground through some


resistance

500

0.85

1.4
1.4

PWM, Change to source or sink OFF

100

Sense = 0.1 V to 0.4 V

mA

mV

Sink diode, If = 2.8 A


600

mA

0.7

Source diode, If = 2.8 A


PWM, Change to source or sink ON

mA

V
ns

500

ns

V/V

Protection Circuitry
VUV

UVLO threshold

IOCP

Overcurrent threshold

VBB increasing

tOCP

Overcurrent protection period

TJW

Thermal warning temperature

Temperature increasing

TJWHys

Thermal warning hysteresis

Recovery = TJW TJWHys

TJTSD

Thermal shutdown temperature

Temperature increasing

6.5

7.5

TJTSDHys Thermal shutdown hysteresis

Recovery = TJTSD TJTSDHys

A
1.2

ms

160

15

175

15

Submit Documentation Feedback

Copyright 20082010, Texas Instruments Incorporated

Product Folder Link(s): DRV8800 DRV8801

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

DRV8800
DRV8801
SLVS855E JULY 2008 REVISED OCTOBER 2010

www.ti.com

SLEEP
ENABLE
PHASE
MODE

VBB

VOUT+
0

VBB
VOUT-

IOUTX

VIN
1

VIN

5
6
7

OUT+

OUT2

OUT+

OUT-

3
9

Charge Pump and VREG power on delay (~200 us)

Figure 1. PWM Control Timing

10

Submit Documentation Feedback

Copyright 20082010, Texas Instruments Incorporated

Product Folder Link(s): DRV8800 DRV8801

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

www.ti.com

DRV8800
DRV8801
SLVS855E JULY 2008 REVISED OCTOBER 2010

VOUT+
VOUT- High-Z

IPEAK
IOUTx

IOCP

Enable,
Source
or Sink
BLANK
Charge Pump
Counter

tBLANK

tOCP

NFAULT
Motor Lead
Short Condition

Normal DC
Motor Capacitance

Figure 2. Overcurrent Control Timing

FUNCTIONAL DESCRIPTION
Device Operation
The DRV8800/DRV8801 is designed to drive one dc motor. The current through the output full-bridge switches
and all N-channel DMOS are regulated with a fixed off-time PWM control circuit.

Logic Inputs
It is recommended to use a high-value pullup resistor when logic inputs are pulled up to VDD. This resistor limits
the current to the input in case an overvoltage event occurs. Logic inputs are nSLEEP, MODE, PHASE, and
ENABLE. Voltages higher than 7 V on any logic input can cause damage to the input structure.

VREG (DRV8800 Only)


This output represents a measurement of the internal regulator voltage. This pin should be left disconnected. A
voltage of approximately 7.5 V can be measured at this pin.

VPROPI (DRV8801 Only)


This output offers an analog voltage proportional to the winding current. Voltage at this terminal is five times
greater than the motor winding current (VPROPI = 5I). VPROPI is meaningful only if there is a resistor
connected to the SENSE pin. If SENSE is connected to ground, VPROPI measures 0 V. During slow decay,
VPROPI outputs 0 V. VPROPI can output a maximum of 2.5 V, since at 500 mV on SENSE, the H-bridge is
disabled.

Submit Documentation Feedback

Copyright 20082010, Texas Instruments Incorporated

Product Folder Link(s): DRV8800 DRV8801

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

11

Stuvia.com - The study-notes marketplace

DRV8800
DRV8801
SLVS855E JULY 2008 REVISED OCTOBER 2010

www.ti.com

Charge Pump
The charge pump is used to generate a supply above VBB to drive the source-side DMOS gates. A 0.1-mF
ceramic monolithic capacitor should be connected between CP1 and CP2 for pumping purposes. A 0.1-mF
ceramic monolithic capacitor, CStorage, should be connected between VCP and VBB to act as a reservoir to run
the high-side DMOS devices. The VCP voltage level is internally monitored and, in the case of a fault condition,
the outputs of the device are disabled.

Shutdown
As a measure to protect the device, faults caused by very high junction temperatures or low voltage on VCP
disable the outputs of the device until the fault condition is removed. At power on, the UVLO circuit disables the
drivers.

Low-Power Mode
Control input nSLEEP is used to minimize power consumption when the DRV8800/DRV8801 is not in use. This
disables much of the internal circuitry, including the internal voltage rails and charge pump. nSLEEP is asserted
low. A logic high on this input pin results in normal operation. When switching from low to high, the user should
allow a 1-ms delay before applying PWM signals. This time is needed for the charge pump to stabilize.
MODE 1 (MODE on the DRV8800)
Input MODE 1 is used to toggle between fast-decay mode and slow-decay mode. A logic high puts the device
in slow-decay mode.
MODE 2 (DRV8801 only)
MODE 2 is used to select which set of drivers (high side versus low side) is used during the slow-decay
recirculation. MODE 2 is meaningful only when MODE 1 is asserted high. A logic high on MODE 2 has
current recirculation through the high-side drivers. A logic low has current recirculation through the low-side
drivers.

Braking
The braking function is implemented by driving the device in slow-decay mode (MODE 1 pin is high) and
deasserting the enable to low. Because it is possible to drive current in both directions through the DMOS
switches, this configuration effectively shorts out the motor-generated BEMF as long as the ENABLE chop mode
is asserted. The maximum current can be approximated by VBEMF/RL. Care should be taken to ensure that the
maximum ratings of the device are not exceeded in worse-case braking situations high-speed and high-inertia
loads.

Diagnostic Output
The nFAULT pin signals a problem with the chip via an open-drain output. A motor fault, undervoltage condition,
or TJ > 160C drives the pin active low. This output is not valid when nSLEEP puts the device into minimum
power dissipation mode (i.e., nSLEEP is low). nFAULT stays asserted (nFAULT = L) until VBB reaches VBBNFR
to give the charge pump headroom to reach its undervoltage threshold. nFAULT is a status-only signal and does
not affect any device functionality. The H-bridge portion still operates normally down to VBB = 8 V with nFAULT
asserted.

Thermal Shutdown (TSD)


Two die-temperature monitors are integrated on the chip. As die temperature increases toward the maximum, a
thermal warning signal is triggered at 160C. This fault drives the nFAULT low, but does not disable the
operation of the chip. If the die temperature increases further, to approximately 175C, the full-bridge outputs are
disabled until the internal temperature falls below a hysteresis of 15C.

12

Submit Documentation Feedback

Copyright 20082010, Texas Instruments Incorporated

Product Folder Link(s): DRV8800 DRV8801

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

www.ti.com

DRV8800
DRV8801
SLVS855E JULY 2008 REVISED OCTOBER 2010

Control Logic Table (1)


PINS

(1)
(2)

OPERATION

PHASE

ENABLE

MODE 1

MODE 2

nSLEEP

OUT+

OUT-

Forward

Reverse

Brake (slow decay)

Fast-decay synchronous
rectification (2)

Fast-decay synchronous
rectification (2)

Sleep mode

X = Dont care, Z = high impedance


To prevent reversal of current during fast-decay synchronous rectification, outputs go to the high-impedance state as the current
approaches 0 A.

Overcurrent Protection
The current flowing through the high-side and low-side drivers is monitored to ensure that the motor lead is not
shorted to supply or ground. If a short is detected, the full-bridge outputs are turned off, flag nFAULT is driven
low, and a 1.2-ms fault timer is started. After this 1.2-ms period, tOCP , the device is then allowed to follow the
input commands and another turnon is attempted (nFAULT becomes high again during this attempt). If there is
still a fault condition, the cycle repeats. If after tOCP expires it is determined the short condition is not present,
normal operation resumes and nFAULT is deasserted.

Submit Documentation Feedback

Copyright 20082010, Texas Instruments Incorporated

Product Folder Link(s): DRV8800 DRV8801

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

13

Stuvia.com - The study-notes marketplace

DRV8800
DRV8801
SLVS855E JULY 2008 REVISED OCTOBER 2010

www.ti.com

APPLICATION INFORMATION
Power Dissipation
First-order approximation of power dissipation in the DRV8800/DRV8801 can be calculated by examining the
power dissipation in the full-bridge during each of the operation modes. DRV8800/DRV8801 utilize synchronous
rectification. During the decay cycle, the body diode is shorted by the low-Rds(ON) driver, which in turn reduces
power dissipation in the full-bridge. In order to prevent shoot through (high-side and low-side drivers on the same
side are ON at the same time), DRV8800/DRV8801 implement a 500-ns typical crossover delay time. During this
period, the body diode in the decay current path conducts the current until the DMOS driver turns on. High
current and high ambient temperature applications should take this into consideration. In addition, motor
parameters and switching losses can add power dissipation that could affect critical applications.

Drive Current
This current path is through the high-side sourcing DMOS driver, motor winding, and low-side sinking DMOS
driver. Power dissipation I2R loses in one source and one sink DMOS driver, as shown in Equation 1.
2

PD = I (RDS(on)Source + RDS(onSink))

(1)
DRV8800
VBB

3
2

1 Drive Current
2 Fast decay with synchronous rectification (reverse)
3 Slow decay with synchronous rectification (brake)

14

Submit Documentation Feedback

Copyright 20082010, Texas Instruments Incorporated

Product Folder Link(s): DRV8800 DRV8801

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

www.ti.com

DRV8800
DRV8801
SLVS855E JULY 2008 REVISED OCTOBER 2010

DRV8801
VBB

3
2

Drive Current

Fast decay with synchronous rectification (reverse)

Slow decay with synchronous rectification (brake) Low Side

Slow decay with synchronous rectification (brake) High Side

Figure 3. Current Path

Fast Decay With Synchronous Rectification


This decay mode is equivalent to a phase change where the opposite drivers are switched on. When in fast
decay, the motor current is not allowed to go negative (direction change). Instead, as the current approaches
zero, the drivers turn off. The power calculation is the same as the drive current calculation (see Equation 1).

Submit Documentation Feedback

Copyright 20082010, Texas Instruments Incorporated

Product Folder Link(s): DRV8800 DRV8801

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

15

Stuvia.com - The study-notes marketplace

DRV8800
DRV8801
SLVS855E JULY 2008 REVISED OCTOBER 2010

www.ti.com

Slow-Decay SR (Brake Mode)


In slow-decay mode, both low-side sinking drivers turn on, allowing the current to circulate through the H-bridges
low side (two sink drivers) and the load. Power dissipation I2R loses in the two sink DMOS drivers:
2

PD = I (2 RDS(on)Sink)

(2)

SENSE
A low-value resistor can be placed between the SENSE pin and ground for current-sensing purposes. To
minimize ground-trace IR drops in sensing the output current level, the current-sensing resistor should have an
independent ground return to the star ground point. This trace should be as short as possible. For low-value
sense resistors, the IR drops in the PCB can be significant, and should be taken into account.
NOTE
When selecting a value for the sense resistor, SENSE does not exceed the maximum
voltage of 500 mV. The H-bridge is disabled and enters recirculation while motor winding
current is above a SENSE voltage equal or greater than 500 mV.

Ground
A ground power plane should be located as close to the DRV8800/DRV8801 as possible. The copper ground
plane directly under the PowerPAD package makes a good location. This pad can then be connected to ground
for this purpose.

Layout
The printed circuit board (PCB) should use a heavy ground plane. For optimum electrical and thermal
performance, the DRV8800/DRV8801 must be soldered directly onto the board. On the underside of the
DRV8800/DRV8801 is a PowerPAD package, which provides a path for enhanced thermal dissipation. The
thermal pad should be soldered directly to an exposed surface on the PCB. Thermal vias are used to transfer
heat to other layers of the PCB. For more information on this technique, please refer to document SLMA002.
The load supply pin, VBB, should be decoupled with an electrolytic capacitor (typically 100 mF) in parallel with a
ceramic capacitor placed as close as possible to the device. The ceramic capacitors between VCP and VBB,
connected to VREG, and between CP1 and CP2 should be as close to the pins of the device as possible, in
order to minimize lead inductance.

16

Submit Documentation Feedback

Copyright 20082010, Texas Instruments Incorporated

Product Folder Link(s): DRV8800 DRV8801

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

PACKAGE OPTION ADDENDUM

www.ti.com

23-Oct-2010

PACKAGING INFORMATION
Orderable Device

Status

(1)

Package Type Package


Drawing

Pins

Package Qty

Eco Plan

(2)

Lead/
Ball Finish

MSL Peak Temp

(3)

Samples
(Requires Login)

DRV8800PWP

ACTIVE

HTSSOP

PWP

16

90

Green (RoHS
& no Sb/Br)

CU NIPDAU Level-2-260C-1 YEAR

Purchase Samples

DRV8800PWPR

ACTIVE

HTSSOP

PWP

16

2000

Green (RoHS
& no Sb/Br)

CU NIPDAU Level-2-260C-1 YEAR

Request Free Samples

DRV8800RTYR

ACTIVE

QFN

RTY

16

3000

Green (RoHS
& no Sb/Br)

CU NIPDAU Level-3-260C-168 HR

Request Free Samples

DRV8800RTYT

ACTIVE

QFN

RTY

16

250

Green (RoHS
& no Sb/Br)

CU NIPDAU Level-3-260C-168 HR

Purchase Samples

DRV8801PWP

ACTIVE

HTSSOP

PWP

16

90

Green (RoHS
& no Sb/Br)

CU NIPDAU Level-2-260C-1 YEAR

Purchase Samples

DRV8801PWPR

ACTIVE

HTSSOP

PWP

16

2000

Green (RoHS
& no Sb/Br)

CU NIPDAU Level-2-260C-1 YEAR

Request Free Samples

DRV8801RTYR

ACTIVE

QFN

RTY

16

3000

Green (RoHS
& no Sb/Br)

CU NIPDAU Level-3-260C-168 HR

Request Free Samples

DRV8801RTYT

ACTIVE

QFN

RTY

16

250

Green (RoHS
& no Sb/Br)

CU NIPDAU Level-3-260C-168 HR

Purchase Samples

(1)

The marketing status values are defined as follows:


ACTIVE: Product device recommended for new designs.
LIFEBUY: TI has announced that the device will be discontinued, and a lifetime-buy period is in effect.
NRND: Not recommended for new designs. Device is in production to support existing customers, but TI does not recommend using this part in a new design.
PREVIEW: Device has been announced but is not in production. Samples may or may not be available.
OBSOLETE: TI has discontinued the production of the device.
(2)

Eco Plan - The planned eco-friendly classification: Pb-Free (RoHS), Pb-Free (RoHS Exempt), or Green (RoHS & no Sb/Br) - please check http://www.ti.com/productcontent for the latest availability
information and additional product content details.
TBD: The Pb-Free/Green conversion plan has not been defined.
Pb-Free (RoHS): TI's terms "Lead-Free" or "Pb-Free" mean semiconductor products that are compatible with the current RoHS requirements for all 6 substances, including the requirement that
lead not exceed 0.1% by weight in homogeneous materials. Where designed to be soldered at high temperatures, TI Pb-Free products are suitable for use in specified lead-free processes.
Pb-Free (RoHS Exempt): This component has a RoHS exemption for either 1) lead-based flip-chip solder bumps used between the die and package, or 2) lead-based die adhesive used between
the die and leadframe. The component is otherwise considered Pb-Free (RoHS compatible) as defined above.
Green (RoHS & no Sb/Br): TI defines "Green" to mean Pb-Free (RoHS compatible), and free of Bromine (Br) and Antimony (Sb) based flame retardants (Br or Sb do not exceed 0.1% by weight
in homogeneous material)
(3)

MSL, Peak Temp. -- The Moisture Sensitivity Level rating according to the JEDEC industry standard classifications, and peak solder temperature.

Downloaded by:: macylnt | macylnt@gmail.com


Addendum-Page 1
Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

PACKAGE OPTION ADDENDUM

www.ti.com

23-Oct-2010

Important Information and Disclaimer:The information provided on this page represents TI's knowledge and belief as of the date that it is provided. TI bases its knowledge and belief on information
provided by third parties, and makes no representation or warranty as to the accuracy of such information. Efforts are underway to better integrate information from third parties. TI has taken and
continues to take reasonable steps to provide representative and accurate information but may not have conducted destructive testing or chemical analysis on incoming materials and chemicals.
TI and TI suppliers consider certain information to be proprietary, and thus CAS numbers and other limited information may not be available for release.
In no event shall TI's liability arising out of such information exceed the total purchase price of the TI part(s) at issue in this document sold by TI to Customer on an annual basis.

Downloaded by:: macylnt | macylnt@gmail.com


Addendum-Page 2
Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

PACKAGE MATERIALS INFORMATION


www.ti.com

22-Oct-2010

TAPE AND REEL INFORMATION

*All dimensions are nominal

Device

Package Package Pins


Type Drawing

SPQ

Reel
Reel
A0
Diameter Width (mm)
(mm) W1 (mm)

B0
(mm)

K0
(mm)

P1
(mm)

DRV8800PWPR

HTSSOP

PWP

16

2000

330.0

12.4

DRV8800RTYR

QFN

RTY

16

3000

330.0

DRV8800RTYT

QFN

RTY

16

250

180.0

DRV8801PWPR

HTSSOP

PWP

16

2000

DRV8801RTYR

QFN

RTY

16

DRV8801RTYT

QFN

RTY

16

6.9

5.6

1.6

8.0

12.0

Q1

12.4

4.25

4.25

1.15

8.0

12.0

Q2

12.4

4.25

4.25

1.15

8.0

12.0

Q2

330.0

12.4

6.9

5.6

1.6

8.0

12.0

Q1

3000

330.0

12.4

4.25

4.25

1.15

8.0

12.0

Q2

250

180.0

12.4

4.25

4.25

1.15

8.0

12.0

Q2

Pack Materials-Page 1

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

W
Pin1
(mm) Quadrant

Stuvia.com - The study-notes marketplace

PACKAGE MATERIALS INFORMATION


www.ti.com

22-Oct-2010

*All dimensions are nominal

Device

Package Type

Package Drawing

Pins

SPQ

Length (mm)

Width (mm)

Height (mm)

DRV8800PWPR

HTSSOP

PWP

16

2000

346.0

346.0

29.0

DRV8800RTYR

QFN

RTY

16

3000

346.0

346.0

29.0

DRV8800RTYT

QFN

RTY

16

250

190.5

212.7

31.8

DRV8801PWPR

HTSSOP

PWP

16

2000

346.0

346.0

29.0

DRV8801RTYR

QFN

RTY

16

3000

346.0

346.0

29.0

DRV8801RTYT

QFN

RTY

16

250

190.5

212.7

31.8

Pack Materials-Page 2

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

IMPORTANT NOTICE
Texas Instruments Incorporated and its subsidiaries (TI) reserve the right to make corrections, modifications, enhancements, improvements,
and other changes to its products and services at any time and to discontinue any product or service without notice. Customers should
obtain the latest relevant information before placing orders and should verify that such information is current and complete. All products are
sold subject to TIs terms and conditions of sale supplied at the time of order acknowledgment.
TI warrants performance of its hardware products to the specifications applicable at the time of sale in accordance with TIs standard
warranty. Testing and other quality control techniques are used to the extent TI deems necessary to support this warranty. Except where
mandated by government requirements, testing of all parameters of each product is not necessarily performed.
TI assumes no liability for applications assistance or customer product design. Customers are responsible for their products and
applications using TI components. To minimize the risks associated with customer products and applications, customers should provide
adequate design and operating safeguards.
TI does not warrant or represent that any license, either express or implied, is granted under any TI patent right, copyright, mask work right,
or other TI intellectual property right relating to any combination, machine, or process in which TI products or services are used. Information
published by TI regarding third-party products or services does not constitute a license from TI to use such products or services or a
warranty or endorsement thereof. Use of such information may require a license from a third party under the patents or other intellectual
property of the third party, or a license from TI under the patents or other intellectual property of TI.
Reproduction of TI information in TI data books or data sheets is permissible only if reproduction is without alteration and is accompanied
by all associated warranties, conditions, limitations, and notices. Reproduction of this information with alteration is an unfair and deceptive
business practice. TI is not responsible or liable for such altered documentation. Information of third parties may be subject to additional
restrictions.
Resale of TI products or services with statements different from or beyond the parameters stated by TI for that product or service voids all
express and any implied warranties for the associated TI product or service and is an unfair and deceptive business practice. TI is not
responsible or liable for any such statements.
TI products are not authorized for use in safety-critical applications (such as life support) where a failure of the TI product would reasonably
be expected to cause severe personal injury or death, unless officers of the parties have executed an agreement specifically governing
such use. Buyers represent that they have all necessary expertise in the safety and regulatory ramifications of their applications, and
acknowledge and agree that they are solely responsible for all legal, regulatory and safety-related requirements concerning their products
and any use of TI products in such safety-critical applications, notwithstanding any applications-related information or support that may be
provided by TI. Further, Buyers must fully indemnify TI and its representatives against any damages arising out of the use of TI products in
such safety-critical applications.
TI products are neither designed nor intended for use in military/aerospace applications or environments unless the TI products are
specifically designated by TI as military-grade or "enhanced plastic." Only products designated by TI as military-grade meet military
specifications. Buyers acknowledge and agree that any such use of TI products which TI has not designated as military-grade is solely at
the Buyer's risk, and that they are solely responsible for compliance with all legal and regulatory requirements in connection with such use.
TI products are neither designed nor intended for use in automotive applications or environments unless the specific TI products are
designated by TI as compliant with ISO/TS 16949 requirements. Buyers acknowledge and agree that, if they use any non-designated
products in automotive applications, TI will not be responsible for any failure to meet such requirements.
Following are URLs where you can obtain information on other Texas Instruments products and application solutions:
Products

Applications

Audio

www.ti.com/audio

Communications and Telecom www.ti.com/communications

Amplifiers

amplifier.ti.com

Computers and Peripherals

www.ti.com/computers

Data Converters

dataconverter.ti.com

Consumer Electronics

www.ti.com/consumer-apps

DLP Products

www.dlp.com

Energy and Lighting

www.ti.com/energy

DSP

dsp.ti.com

Industrial

www.ti.com/industrial

Clocks and Timers

www.ti.com/clocks

Medical

www.ti.com/medical

Interface

interface.ti.com

Security

www.ti.com/security

Logic

logic.ti.com

Space, Avionics and Defense

www.ti.com/space-avionics-defense

Power Mgmt

power.ti.com

Transportation and
Automotive

www.ti.com/automotive

Microcontrollers

microcontroller.ti.com

Video and Imaging

www.ti.com/video

RFID

www.ti-rfid.com

Wireless

www.ti.com/wireless-apps

RF/IF and ZigBee Solutions

www.ti.com/lprf
TI E2E Community Home Page

e2e.ti.com

Mailing Address: Texas Instruments, Post Office Box 655303, Dallas, Texas 75265
Copyright 2011, Texas Instruments Incorporated

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

6-PIN DIP RANDOM-PHASE


OPTOISOLATORS TRIAC DRIVER OUTPUT
(250/400 VOLT PEAK)
MOC3010M MOC3011M

MOC3012M

MOC3020M

MOC3021M

MOC3022M

PACKAGE

MOC3023M

SCHEMATIC

ANODE 1

6 MAIN TERM.

6
6

5 NC*

CATHODE 2

1
N/C 3

4 MAIN TERM.

1
*DO NOT CONNECT
(TRIAC SUBSTRATE)

DESCRIPTION
The MOC301XM and MOC302XM series are optically isolated triac driver devices. These devices contain a GaAs infrared
emitting diode and a light activated silicon bilateral switch, which functions like a triac. They are designed for interfacing between
electronic controls and power triacs to control resistive and inductive loads for 115 VAC operations.

FEATURES

Excellent IFT stabilityIR emitting diode has low degradation


High isolation voltageminimum 5300 VAC RMS
Underwriters Laboratory (UL) recognizedFile #E90700
Peak blocking voltage
250V-MOC301XM
400V-MOC302XM
VDE recognized (File #94766)
Ordering option V (e.g. MOC3023VM)

APPLICATIONS

Industrial controls
Traffic lights
Vending machines
Solid state relay
Lamp ballasts

Solenoid/valve controls
Static AC power switch
Incandescent lamp dimmers
Motor control

2003 Fairchild Semiconductor Corporation

Page 1 of 10

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

4/30/03

Stuvia.com - The study-notes marketplace

6-PIN DIP RANDOM-PHASE


OPTOISOLATORS TRIAC DRIVER OUTPUT
(250/400 VOLT PEAK)
MOC3010M MOC3011M

MOC3012M

MOC3020M

MOC3021M

MOC3022M

MOC3023M

ABSOLUTE MAXIMUM RATINGS (TA = 25C unless otherwise noted)


Parameters

Symbol

Device

Value

Units

Storage Temperature

TSTG

All

-40 to +150

Operating Temperature

TOPR

All

-40 to +85

Lead Solder Temperature

TSOL

All

260 for 10 sec

TJ

All

-40 to +100

VISO

All

7500

Vac(pk)

PD

All

Continuous Forward Current

IF

All

Reverse Voltage

VR

All

TOTAL DEVICE

Junction Temperature Range


Isolation Surge Voltage(1)
(peak AC voltage, 60Hz, 1 sec duration)
Total Device Power Dissipation @ 25C
Derate above 25C

330

mW

4.4

mW/C

60

mA

EMITTER

Total Power Dissipation 25C Ambient

100

mW

1.33

mW/C

PD

All

Off-State Output Terminal Voltage

VDRM

MOC3010M/1M/2M
MOC3020M/1M/2M/3M

250
400

Peak Repetitive Surge Current (PW = 1 ms, 120 pps)

ITSM

All

PD

All

300

mW

mW/C

Derate above 25C


DETECTOR

Total Power Dissipation @ 25C Ambient


Derate above 25C
Note

1. Isolation surge voltage, VISO, is an internal device dielectric breakdown rating. For this test, Pins 1 and 2 are common, and
Pins 4, 5 and 6 are common.

2003 Fairchild Semiconductor Corporation

Page 2 of 10

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

4/30/03

Stuvia.com - The study-notes marketplace

6-PIN DIP RANDOM-PHASE


OPTOISOLATORS TRIAC DRIVER OUTPUT
(250/400 VOLT PEAK)
MOC3010M MOC3011M

MOC3012M

MOC3020M

MOC3021M

MOC3022M

MOC3023M

ELECTRICAL CHARACTERISTICS (TA = 25C Unless otherwise specified)


INDIVIDUAL COMPONENT CHARACTERISTICS
Parameters

Test Conditions

Symbol

Device

IF = 10 mA

VF

VR = 3 V, TA = 25C

Peak Blocking Current,Either Direction


Peak On-State Voltage,Either Direction

Min

Typ

Max

Units

All

1.15

1.5

IR

All

0.01

100

Rated VDRM, IF = 0 (note 1)

IDRM

All

10

100

nA

ITM = 100 mA peak, IF = 0

VTM

All

1.8

EMITTER
Input Forward Voltage
Reverse Leakage Current
DETECTOR

TRANSFER CHARACTERISTICS (TA = 25C Unless otherwise specified.)


DC Characteristics

Test Conditions

Symbol

Device

Min

Typ

MOC3020M

15

MOC3021M
Voltage = 3V (note 3)

IFT

MOC3011M

10

MOC3022M
MOC3012M
IH

All

mA

MOC3023M
Holding Current, Either Direction

Units

30

MOC3010M
LED Trigger Current

Max

100

Note
1. Test voltage must be applied within dv/dt rating.
2. This is static dv/dt. See Figure 5 for test circuit. Commutating dv/dt is a function of the load-driving thyristor(s) only.
3. All devices are guaranteed to trigger at an IF value less than or equal to max IFT. Therefore, recommended operating IF lies
between max IFT (30 mA for MOC3020M, 15 mA for MOC3010M and MOC3021M, 10 mA for MOC3011M and MOC3022M,
5 mA for MOC3012M and MOC3023M) and absolute max IF (60 mA).

2003 Fairchild Semiconductor Corporation

Page 3 of 10

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

4/30/03

Stuvia.com - The study-notes marketplace

6-PIN DIP RANDOM-PHASE


OPTOISOLATORS TRIAC DRIVER OUTPUT
(250/400 VOLT PEAK)
MOC3010M MOC3011M

MOC3012M

MOC3020M

MOC3021M

1.7

600

ON-STATE CURRENT - I TM (mA)

VF - FORWARD VOLTAGE (V)

800

1.6

1.5

TA = -55oC

1.3

TA = 25oC

1.2

MOC3023M

Fig. 2 On-State Characteristics

Fig. 1 LED Forward Voltage vs. Forward Current


1.8

1.4

MOC3022M

400

200

-200

-400

TA = 100oC

-600
1.1

-800
-3

1.0
1

10

-2

100

-1

ON-STATE VOLTAGE - V

2
TM

(V)

IF - LED FORWARD CURRENT (mA)

Fig. 4 LED Current Required to Trigger vs. LED Pulse Width

Fig. 3 Trigger Current vs. Ambient Temperature


1.4

TRIGGER CURRENT - I FT (NORMALIZED)

25

TRIGGER CURRENT - I FT (NORMALIZED)

1.3

1.2

1.1

1.0

0.9

0.8

NORMALIZED TO:
PWin 100 s

20

15

10

0
0.7

10

20

50

100

NORMALIZED TO T A = 25C

LED TRIGGER WIDTH - PWin (s)

0.6
-40

-20

20

40

60

80

100

AMBIENT TEMPERATURE - TA (oC)

Fig. 6 Leakage Current, IDRM vs. Temperature


10000

Fig. 5 dv/dt vs. Temperature


12

1000

STATIC - dv/dt (V/s)

IDRM, LEAKAGE CURRENT (nA)

STATIC dv/dt
CIRCUIT IN FIGURE 5

10

100

10

1
0

25

30

40

50

60

70

80

Ambient Temperature - TA (oC)

90

100

0.1
-40

-20

20

40

60

80

100

TA, AMBIENT TEMPERATURE ( oC)

2003 Fairchild Semiconductor Corporation

Page 4 of 10

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

4/30/03

Stuvia.com - The study-notes marketplace

6-PIN DIP RANDOM-PHASE


OPTOISOLATORS TRIAC DRIVER OUTPUT
(250/400 VOLT PEAK)
MOC3010M MOC3011M

MOC3012M

MOC3020M

MOC3021M

MOC3022M

MOC3023M

1. The mercury wetted relay provides a high speed repeated


pulse to the D.U.T.

400V (MOC302X)
250V (MOC301X)
Vdc

RTEST

2. 100x scope probes are used, to allow high speeds and


voltages.

R = 10 k
CTEST

PULSE
INPUT

MERCURY
WETTED
RELAY

3. The worst-case condition for static dv/dt is established by


triggering the D.U.T. with a normal LED input current, then
removing the current. The variable RTEST allows the dv/dt
to be gradually increased until the D.U.T. continues to
trigger in response to the applied voltage pulse, even
after the LED current has been removed. The dv/dt is
then decreased until the D.U.T. stops triggering. RC is
measured at this point and recorded.

X100
SCOPE
PROBE

D.U.T.

Vmax = 400 V (MOC302X)


= 250 V (MOC301X)

APPLIED VOLTAGE
WAVEFORM

252 V (MOC302X)
158 V (MOC301X)
dv/dt =

0 VOLTS

0.63 Vmax

RC

RC

252
=
(MOC302X)
RC
158
=
(MOC301X)
RC

Figure 5. Static dv/dt Test Circuit

Note: This optoisolator should not be used to drive a load directly.


It is intended to be a trigger device only.

RL
Rin

180

VCC
2

MOC3010M
MOC3011M
MOC3012M

120 V
60 Hz

Figure 6. Resistive Load

ZL
Rin

180

2.4k

VCC
2

MOC3010M
MOC3011M
MOC3012M

0.1 F

120 V
60 Hz
C1

Figure 7. Inductive Load with Sensitive Gate Triac (IGT 15 mA)

2003 Fairchild Semiconductor Corporation

Page 5 of 10

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

4/30/03

Stuvia.com - The study-notes marketplace

6-PIN DIP RANDOM-PHASE


OPTOISOLATORS TRIAC DRIVER OUTPUT
(250/400 VOLT PEAK)
MOC3010M MOC3011M

MOC3012M

MOC3020M

MOC3021M

MOC3022M

MOC3023M

ZL
Rin

VCC

180

6
MOC3010M
MOC3011M
MOC3012M

0.2 F

1.2 k
120 V
60 Hz
C1

Figure 8. Inductive Load with Sensitive Gate Triac (IGT 15 mA)

Rin

360

470
HOT

VCC
2

MOC3020M
MOC3021M
MOC3022M
MOC3023M

0.05 F

39
240
VAC

4
0.01 F
LOAD

GROUND

In this circuit the hot side of the line is switched and the load connected to the cold or ground side.
The 39 ohm resistor and 0.01F capacitor are for snubbing of the triac, and the 470 ohm resistor and
0.05 F capacitor are for snubbing the coupler. These components may or may not be necessary
depending upon the particular and load used.

Figure 9. Typical Application Circuit

2003 Fairchild Semiconductor Corporation

Page 6 of 10

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

4/30/03

Stuvia.com - The study-notes marketplace

6-PIN DIP RANDOM-PHASE


OPTOISOLATORS TRIAC DRIVER OUTPUT
(250/400 VOLT PEAK)
MOC3010M MOC3011M

MOC3012M

MOC3020M

Package Dimensions (Through Hole)

MOC3021M

MOC3022M

Package Dimensions (Surface Mount)


0.350 (8.89)
0.320 (8.13)

0.350 (8.89)
0.320 (8.13)

0.260 (6.60)
0.240 (6.10)

0.070 (1.77)
0.040 (1.02)

MOC3023M

0.260 (6.60)
0.240 (6.10)

0.390 (9.90)
0.332 (8.43)

0.070 (1.77)
0.040 (1.02)

0.320 (8.13)

0.320 (8.13)

0.014 (0.36)
0.010 (0.25)

0.014 (0.36)
0.010 (0.25)

0.200 (5.08)
0.115 (2.93)

0.200 (5.08)
0.115 (2.93)

0.100 (2.54)
0.015 (0.38)

0.012 (0.30)
0.008 (0.20)

0.025 (0.63)
0.020 (0.51)

0.020 (0.50)
0.016 (0.41)

0.100 (2.54)

0.100 [2.54]

15

0.035 (0.88)
0.006 (0.16)

0.020 (0.50)
0.016 (0.41)

0.012 (0.30)

Package Dimensions (0.4 Lead Spacing)

Recommended Pad Layout for


Surface Mount Leadform

0.350 (8.89)
0.320 (8.13)

0.070 (1.78)

0.260 (6.60)
0.240 (6.10)

0.060 (1.52)
0.070 (1.77)
0.040 (1.02)

0.014 (0.36)
0.010 (0.25)

0.425 (10.79)

0.100 (2.54)
0.305 (7.75)

0.200 (5.08)
0.115 (2.93)

0.030 (0.76)

0.100 (2.54)
0.015 (0.38)
0.020 (0.50)
0.016 (0.41)

0.100 [2.54]

0.012 (0.30)
0.008 (0.21)
0.425 (10.80)
0.400 (10.16)

NOTE
All dimensions are in inches (millimeters)

2003 Fairchild Semiconductor Corporation

Page 7 of 10

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

4/30/03

Stuvia.com - The study-notes marketplace

6-PIN DIP RANDOM-PHASE


OPTOISOLATORS TRIAC DRIVER OUTPUT
(250/400 VOLT PEAK)
MOC3010M MOC3011M

MOC3012M

MOC3020M

MOC3021M

MOC3022M

MOC3023M

ORDERING INFORMATION
Option
S
SR2

Order Entry Identifier

Description

Surface Mount Lead Bend

SR2

Surface Mount; Tape and reel

0.4" Lead Spacing

VDE 0884

TV

VDE 0884, 0.4" Lead Spacing

TV
SV
SR2V

SV

VDE 0884, Surface Mount

SR2V

VDE 0884, Surface Mount, Tape & Reel

MARKING INFORMATION

MOC3010

X YY Q

V
3

Definitions
1

Fairchild logo

Device number

VDE mark (Note: Only appears on parts ordered with VDE


option See order entry table)

One digit year code, e.g., 3

Two digit work week ranging from 01 to 53

Assembly package code

*Note Parts that do not have the V option (see definition 3 above) that are marked with
date code 325 or earlier are marked in portrait format.

2003 Fairchild Semiconductor Corporation

Page 8 of 10

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

4/30/03

Stuvia.com - The study-notes marketplace

6-PIN DIP RANDOM-PHASE


OPTOISOLATORS TRIAC DRIVER OUTPUT
(250/400 VOLT PEAK)
MOC3010M MOC3011M

MOC3012M

MOC3020M

MOC3021M

MOC3022M

MOC3023M

Carrier Tape Specifications


12.0 0.1
4.5 0.20
2.0 0.05

1.5 MIN

4.0 0.1

0.30 0.05

1.75 0.10

11.5 1.0
21.0 0.1

9.1 0.20

1.5 0.1/-0

10.1 0.20

0.1 MAX

24.0 0.3

User Direction of Feed

NOTE
All dimensions are in inches (millimeters)

Reflow Profile (White Package, -M Suffix)

Temperature (C)

300

230C, 1030 s

250

245C peak

200
150
Time above 183C, 120180 sec

100

Ramp up = 210C/sec

50

Peak reflow temperature: 245C (package surface temperature)


Time of temperature higher than 183C for 120180 seconds
One time soldering reflow is recommended

0
0

0.5

1.5

2.5

3.5

4.5

Time (Minute)

2003 Fairchild Semiconductor Corporation

Page 9 of 10

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

4/30/03

Stuvia.com - The study-notes marketplace

6-PIN DIP RANDOM-PHASE


OPTOISOLATORS TRIAC DRIVER OUTPUT
(250/400 VOLT PEAK)
MOC3010M MOC3011M

MOC3012M

MOC3020M

MOC3021M

MOC3022M

MOC3023M

DISCLAIMER
FAIRCHILD SEMICONDUCTOR RESERVES THE RIGHT TO MAKE CHANGES WITHOUT FURTHER NOTICE TO
ANY PRODUCTS HEREIN TO IMPROVE RELIABILITY, FUNCTION OR DESIGN. FAIRCHILD DOES NOT ASSUME
ANY LIABILITY ARISING OUT OF THE APPLICATION OR USE OF ANY PRODUCT OR CIRCUIT DESCRIBED HEREIN;
NEITHER DOES IT CONVEY ANY LICENSE UNDER ITS PATENT RIGHTS, NOR THE RIGHTS OF OTHERS.
LIFE SUPPORT POLICY
FAIRCHILDS PRODUCTS ARE NOT AUTHORIZED FOR USE AS CRITICAL COMPONENTS IN LIFE SUPPORT DEVICES
OR SYSTEMS WITHOUT THE EXPRESS WRITTEN APPROVAL OF THE PRESIDENT OF FAIRCHILD SEMICONDUCTOR
CORPORATION. As used herein:
1. Life support devices or systems are devices or systems
which, (a) are intended for surgical implant into the body, or
(b) support or sustain life, and (c) whose failure to perform
when properly used in accordance with instructions for use
provided in the labeling, can be reasonably expected to
result in a significant injury of the user.

2003 Fairchild Semiconductor Corporation

2. A critical component in any component of a life support


device or system whose failure to perform can be
reasonably expected to cause the failure of the life support
device or system, or to affect its safety or effectiveness.

Page 10 of 10

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

4/30/03

Stuvia.com - The study-notes marketplace

Appendix E

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal

Stuvia.com - The study-notes marketplace

Date: May 14, 2011

Design (E) 414 Circuit diagram


R3 470 ohm

C2

C1
0.1 uF

33nF
JP6
FT232BM

V USB

R5 1.5 kilo ohm


R5 21ohm
R6 21ohm

CN1
1
2
3
4

C5

C8

47pF

47pF

c4 10nF

CN-USB

Project: Design

C6
27pF
C7
27pF

0.1uF

Box Header 7X2

2 4 6 8 10 12 14

C3

R1

32

31

30

29

28

27

26

25

24

10

23

11

22

12

21

13

20

14

19

15

18

16

17

SW SPST
S6

C11
100nF

18k

R2

820 ohm

P8C27

1 3 5 7 9 11 13

4k7

R4
R8

4k7
EMX-2T01P42

BUZZER

P3_5

P0_0 32

P3_7

P0_1 31

Reset

P0_2 30

P4_7

P0_3 29

Vss/Avss

P0_4 28

P4_6

P0_5 27

Vcc/AVcc

P0_6 26

Mode

P0_7 25

P4_5

P3_4 24

10

P1_7

P3_3 23

11

P3_6

P1_0 22

12

P3_1

P1_1 21

13

P5_4

VRff/P4_2 20

14

P5_3

P1_2 19

15

P1_6

P1_3 18

16

P1_5

10

11

12

13

14

LCD

P1_4 17
JP7

Y2
xtal

LED
680 ohm

Up

C9
C10
27pF 27pF

390 ohm

Left

1n4148

Enter

Right

Down

D1
1

Power 12V DC

Vind

Vout

Vcc

1N4007
C12

100nF

C13

C14

C15

100nF

22uF

Gnd

22uF

JP8

4.7 uF

Circuit

C.Smith 18 ohm

100 ohm

4.7 ohm
Las
Power 30V Ac
2

12 ohm
39 ohm

MOC3023M

C.Smith - 560 ohm

TSOP IR Receiver

1 Kilo ohm
6

3
1

10 nF

1 STF16A60

2
U3

JP 2

Eeprom M24C64
E0
E1

VCC
WC

3,3 kilo ohm


1 uF
1 nFault

DRV8801

Mode2

16

VPropi

15

100 Kilo ohm


2 Mode1

VCP 14

SCL

VSS

SDA

1000 pF
12 Kilo ohm

3 Phase

E2

Gnd

Vcc

rooi roii rooi kilo ohm

1,5 Kilo ohm


-

rooi rooi goud kilo 3,3


ohmkilo ohm

4 Gnd

Gnd

13

5 nSleep

Cp2

12

6 Enable

Motor

7 Out +

bruin grys oranje kilo ohm

MCP6244 OP AMP
1 uF

Oranje wit Bruin kilo ohm

rooi rooi rooi kilo ohm

10x10^(-5)F

CP1 11

Out - 10

2,2ohm
8 Sense

VBB

Light Sensor

9
1000 pF

100 x 10^(-6)F

Page 1 of 1

Downloaded by:: macylnt | macylnt@gmail.com


Distribution of this document is illegal
Powered by TCPDF (www.tcpdf.org)

Revision: Design

Anda mungkin juga menyukai