written by
Jacques
www.stuvia.co.uk
PRESENTED BY
Jacques du Preez (15063518)
Campbell Smith (14818264)
16 MAY 2011
Signature
___________________
______________________
J du Preez
C.M. Smith
Date
_________________
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
Table of Contents
Summary ................................................................................................................................................. ii
1.
Introduction .................................................................................................................................... 1
2.
3.
3.2
4.
iii
4.7
4.8
5.
Conclusion ..................................................................................................................................... 45
7.
References .................................................................................................................................... 46
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
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
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.
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
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
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
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.
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.
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.
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]
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 10) DRV8801 PWM Full-Bridge Motor Driver Circuit Diagram [8] & Illustration
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 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
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.
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
IR remote control because they functioned on the same principles by using the same
microprocessors and programming language.
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
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
13
3.1.1.1 MOC
Refer to Appendix D, datasheet MOC3023M.
= 0.45V
Recommended operating
= 5mA for
(Choose
14
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
15
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
We used 8B 390
5 1,2
I 9,7mA
390
(Acceptable)
16
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
17
Choose
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.
18
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:
`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
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
&
Q2
A
is:
Assuming both buttons are not pressed and that the R8C (with
20
) gives an output of
is found in Table 3
21
^_BY
6
0.6
10
7f` in
7f`
1
8687
g
h 7i
87 86 X 87
7f`
<
8f`7i
Nj
(1)
(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
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
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)
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
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
^_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.
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
26
4. Programs
4.1.1 Mainboard Pin Assignments
27
q0rst
p<
20y
1
1 31.552 20z
u^f 8vfw x 16
38400 x 16
36600
5228.7 { 5230rv|}
7
Therefore:
q1rst
p<
20y
1
1 238.006 ~~z
u^f 8vfw x 16
5230 x 16
ws^i}
2 X 12 X 12
p<
1/2000
2 X 12 X 12
20 x 106
Choose n=99
49
28
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.
29
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
30
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
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
34
35
36
Uart0_receive
Uart1_receive
Timer RE
Timer Ra
Interrupt
Timer RE
sec++
Triac 10 second on
timer if gate is opened
at a certain time
interval
37
Controller number
display on LCD if
remote is used
Uart0_receive
command=u0rb
If @
If !
Normal mode
Test mode
Accept certain
commands, to test
certain function
38
Uart1_receive
ir_command=u1rb
store ir_command in a
buffer array
ir_receive_index++
If it is
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
39
Timer RA
40
Timer
Ra
Interrupt
Timer RA
41
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
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
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
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
7. References
[1]
R8C/26 Group, R8C/27 Group, Hardware Manual, Rev.1.30, Revision Date: Jun 01,
2007, www.renesas.com
[2]
[3]
[4]
FT232BL USB UART ( USB - Serial) I.C., DS232BL Version 1.8, Future Technology
Devices Intl. Ltd. 2005
[5]
[6]
[7]
128 Kbit, 64 Kbit and 32 Kbit serial IC bus EEPROM, December 2007, Rev 12.
[8]
[9]
[10]
[11]
46
Appendix A
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.
THE MENU
MENU
FUNCTION
CONTROL
1) Reset
Alarm/Err
2) Time Settings
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.
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.
3) Open Close
Gate
4) Accept Codes
5) Display Log
Example:
6) Exit Menu
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
Appendix B
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
Appendix C
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"
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
{
//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;
}
//*******************************************************************************
/****************************************************************************/
/*
Light sensor
/****************************************************************************/
*/
*/
//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)
{
*/
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--;
}
}
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
}
}
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"
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
}
}
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++)
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
}
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=");
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);
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)
{
lcd_log_write_char(':');
,and seconds
}
}
}
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');
}
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
}
}
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
}
//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
}
//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
/****************************************************************************/
/*
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;
//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;
//Step 14
rcvd_iccr1 = 0;
//Step 15
mst_iccr1 = 0;
return 1; // acknowledgment flag, successful
}
else
{
nackORcomplete();
return 0; // not acknowledgement flag, unsuccessful
}
}
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_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
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
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!!!!!!!!!!!
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 ;
}
}//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){}
// 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__)
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
}
// vector 21 reserved
// timer RA
(software int 22)
#pragma interrupt
_timer_ra(vect=22)
void _timer_ra(void)
{
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)
{
}
// int3
#pragma interrupt
void _int3(void){}
// vector 27 reserved
// vector 28 reserved
// int0
#pragma interrupt
void _int0(void){}
// 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
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 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
Lcd.c
#include "sfr_r827.h"
#include "lcd.h"
#define
#define
#define
#define
#define
#define
#define
/* 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)
{
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;
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;
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 */
pd0 = 0x7f;
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
lcd_address_counter++;
}
} //end lcd_log_write_string function
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
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"
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;
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
}
break;
}
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
}
} //End of enter
break;
//In Display Log Menu
case 5:
if (down()==1) // check for down key pressed
{
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
{
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;
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)
{
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
//increments menu_log_index
if (up()==1)
{
lcd_address_counter = 0; //Resets global variable
lcd_address_counter
menu_log_index++;
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
}
//set menu_log_index = 9 if
if (right()==1)
{
lcd_left_scroll();
}
if (left()==1)
{
lcd_right_scroll();
} //End of switch
}// End of if statement checking if set_time_flag=0
//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
//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)
{
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;
//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
//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;
}
}
//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;
//Increments the
//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
//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
//Increment
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;
//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
return state;
}
{
state=0;
}
return state;
}
return state;
}
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;
}
//write zero
before character
lcd_character_write(time +'0'); //write actual
character
}
else
{
if (time < 20 & time > 9)
integer lies in 10's range
//check if
{
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;
//writes a colon
Motor_current.c
#include "sfr_r827.h"
#include "serial_port.h"
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)
{
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,
tstart_trecr1 = 1;
while(tcstf_trecr1 != 1);
asm("FSET I");
}
/**************************************************************************/
/* 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");
}
/**************************************************************************/
/* function to switch on buzzer
*/
/**************************************************************************/
void buzzeron(void)
{
tstart_trbcr = 1;
}
/**************************************************************************/
/**************************************************************************/
/* function to switch off buzzer
*/
/**************************************************************************/
void buzzeroff(void)
{
tstart_trbcr = 0;
}
/***************************************************************************/
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;
}
//
//
//
//
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;
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;
}
void int1_initialise()
{
pd1_7 = 0;
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;
}
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
Rtclock.c
#include
#include
#include
#include
#include
"sfr_r827.h"
"serial_port.h"
"rtclock.h"
"lcd.h"
"eeprom.h"
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
}
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];
}
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);
}
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
}
Triac.c
#include
#include
#include
#include
"sfr_r827.h"
"rtclock.h"
"menu.h"
"triac.h"
}
return night; // returns 1 for night time, returns 0 for daytime
} // end night time function
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"
bat_alarm;
checksum;
remote_data[2];
b;
main()
{
char temp_bat_volt;
oscillator_initialise();
timer_a_initialise ();
timer_b_initialise ();
ports_initialise();
i2c_initialise();
while(1)
{
/*************************************
POWER ON/OFF
*******************************************************/
if (ra_flag <=52300)
(5230 baud * 10 seconds)
{
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;
}
/****************************************************************************************
************************/
/*************************************
SWITCH 1
*******************************************************/
//
/************************************
***********************/
//Generates
}
/****************************************************************************************
********************/
} //end while
} //end main
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
}
//Step 1
while (bbsy_iccr2==1);
register
//Step 2
iccr1 = (iccr1&0xFF)|0x30;
register is set to 1
//Step 3
iccr2 = (iccr2&0x3F)|0x80;
BBSY =1), Generate start condition
//Step 4
icdrt = (eeprom_address)|0x00;
R/nW
//Step 5
while (tend_icsr==0);
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
// 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
// steps 11 through to 15
// send acknowledgement flag,
//Step 2
iccr1 = (iccr1&0xFF)|0x30;
register is set to 1
//Step 3
iccr2 = (iccr2&0x3F)|0x80;
BBSY =1), Generate start condition
//Step 4
icdrt = (eeprom_address)|0x00;
//Device select
//Step 5
while (tend_icsr==0);
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,
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;
//Step 4
icdrt = (eeprom_address)|0x01;
mode
//Step 5
while (tend_icsr == 0);
wait till TEND bit equals 1 to continue
/****************************************************************************/
/*
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;
register
//Step 9
while (rdrf_icsr == 0);
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);
register
//Step 13
*data = icdrr;
//Read ICDRR
register
//Step 14
rcvd_iccr1 = 0;
//Step 15
mst_iccr1 = 0;
return 1;
flag, successful
// acknowledgment
}
else
{
nackORcomplete();
return 0;
acknowledgement flag, unsuccessful
}
}
// not
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);
}
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"
vector
vector
vector
vector
1
2
3
4
(software int 0)
_brk(vect=0)
reserved
reserved
reserved
reserved
// 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){}
// 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){}
// vector 21 reserved
// timer RA
(software int 22)
#pragma interrupt
_timer_ra(vect=22)
void _timer_ra(void)
{
ra_flag++;
random_max++;
/*************************************
***********************/
// int3
#pragma interrupt
void _int3(void){}
// vector 27 reserved
// vector 28 reserved
// int0
#pragma interrupt
void _int0(void){}
// 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
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");
}
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
}
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)
{
int k;
int N=5000;
with the led output pin with the oscilloscope.
for (k=0;k<N;k++);
}
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;
}
//
//
//
//
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;
}
Serial_port.c
#include "sfr_r827.h"
#include "serial_port.h"
case 1:
send_bit(nibble.bit.b7);
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
bit b0 send
ir_count++;
infra-red flag which points to next bit.
break;
bit is sent
//increment
//exit when
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();
byte_send(code2);
access code
//wait after byte sent
ms_5_delay();
ms_5_delay();
ms_5_delay();
ms_5_delay();
byte_send(Checksum);
//wait after byte sent
ms_5_delay();
ms_5_delay();
ms_5_delay();
ms_5_delay();
// send checksum
Appendix D
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
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
Approved
Checked
2004.11.26
2004.11.26
2004.11.26
Drawn
Page:
Version:
Item
2
1.1
Symbol
Rating
Unit
Power Dissipation
Pd
75
mW
Reverse Voltage
VR
Forward Current
IF
50
mA
(*1)
IFP
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)
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
940
nm
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.
Page:
Version:
3
1.2
Page:
Version:
4
1.0
Page:
Version:
5
1.0
Device NumberBPI-3C1-05
Packaging Box 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.
Page:
Version:
6
1.3
DRV8800
DRV8801
www.ti.com
FEATURES
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)
(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.
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
GND
GND
Ground
nSLEEP
nSLEEP
ENABLE
ENABLE
NC
MODE 2
OUT+
OUT+
SENSE
SENSE
VBB
VBB
OUT-
OUT-
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
15
nFAULT
nFAULT
16
MODE
MODE 1
PowerPAD
PowerPAD
DRV8800
DRV8801
www.ti.com
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
MODE
MODE 1
PHASE
PHASE
GND
GND
Ground
nSLEEP
nSLEEP
ENABLE
ENABLE
OUT+
OUT+
SENSE
SENSE
VBB
VBB
10
OUT-
OUT-
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
16
NC
MODE 2
PowerPAD
PowerPAD
DRV8800
DRV8801
SLVS855E JULY 2008 REVISED OCTOBER 2010
www.ti.com
www.ti.com
DRV8800
DRV8801
SLVS855E JULY 2008 REVISED OCTOBER 2010
DRV8800
DRV8801
SLVS855E JULY 2008 REVISED OCTOBER 2010
www.ti.com
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
www.ti.com
DRV8800
DRV8801
SLVS855E JULY 2008 REVISED OCTOBER 2010
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
DRV8800
DRV8801
SLVS855E JULY 2008 REVISED OCTOBER 2010
www.ti.com
VSense
VDD
2.8
Sense voltage
500
V
A
mV
VBB to OUTx
36
OUTx to SENSE
36
(2)
0.3
TA
TJ
Tstg
(2)
UNIT
40
Output current
ESD rating
(1)
MAX
VBB
kV
500
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
TA
MIN
NOM
MAX
32
38
85
40
UNIT
www.ti.com
DRV8800
DRV8801
SLVS855E JULY 2008 REVISED OCTOBER 2010
ELECTRICAL CHARACTERISTICS
over recommended operating conditions (unless otherwise noted)
PARAMETER
TEST CONDITIONS
MIN
TYP
VIL
VIH
VIL
IIH
IIL
IIH
IIL
IIH
IIL
0.8
2.7
0.8
VIN = 2 V
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
Isink = 1 mA
VIHys
VTRP
Vf
tpd
tCOD
Crossover delay
DAGain
2.0
VBBNFR
20
100
Output ON resistance
20
VIN = 0.8 V
mA
<1.0
VOL
Rds(ON)
10
2
PHASE, ENABLE,
MODE input voltage
UNIT
mA
3.2
Sleep mode
VIH
MAX
0.48
0.74
0.35
0.52
500
0.85
1.4
1.4
100
mA
mV
mA
0.7
mA
V
ns
500
ns
V/V
Protection Circuitry
VUV
UVLO threshold
IOCP
Overcurrent threshold
VBB increasing
tOCP
TJW
Temperature increasing
TJWHys
TJTSD
Temperature increasing
6.5
7.5
A
1.2
ms
160
15
175
15
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
10
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
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.
11
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.
12
www.ti.com
DRV8800
DRV8801
SLVS855E JULY 2008 REVISED OCTOBER 2010
(1)
(2)
OPERATION
PHASE
ENABLE
MODE 1
MODE 2
nSLEEP
OUT+
OUT-
Forward
Reverse
Fast-decay synchronous
rectification (2)
Fast-decay synchronous
rectification (2)
Sleep mode
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.
13
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
www.ti.com
DRV8800
DRV8801
SLVS855E JULY 2008 REVISED OCTOBER 2010
DRV8801
VBB
3
2
Drive Current
15
DRV8800
DRV8801
SLVS855E JULY 2008 REVISED OCTOBER 2010
www.ti.com
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
www.ti.com
23-Oct-2010
PACKAGING INFORMATION
Orderable Device
Status
(1)
Pins
Package Qty
Eco Plan
(2)
Lead/
Ball Finish
(3)
Samples
(Requires Login)
DRV8800PWP
ACTIVE
HTSSOP
PWP
16
90
Green (RoHS
& no Sb/Br)
Purchase Samples
DRV8800PWPR
ACTIVE
HTSSOP
PWP
16
2000
Green (RoHS
& no Sb/Br)
DRV8800RTYR
ACTIVE
QFN
RTY
16
3000
Green (RoHS
& no Sb/Br)
CU NIPDAU Level-3-260C-168 HR
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)
Purchase Samples
DRV8801PWPR
ACTIVE
HTSSOP
PWP
16
2000
Green (RoHS
& no Sb/Br)
DRV8801RTYR
ACTIVE
QFN
RTY
16
3000
Green (RoHS
& no Sb/Br)
CU NIPDAU Level-3-260C-168 HR
DRV8801RTYT
ACTIVE
QFN
RTY
16
250
Green (RoHS
& no Sb/Br)
CU NIPDAU Level-3-260C-168 HR
Purchase Samples
(1)
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.
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.
22-Oct-2010
Device
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
W
Pin1
(mm) Quadrant
22-Oct-2010
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
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
Amplifiers
amplifier.ti.com
www.ti.com/computers
Data Converters
dataconverter.ti.com
Consumer Electronics
www.ti.com/consumer-apps
DLP Products
www.dlp.com
www.ti.com/energy
DSP
dsp.ti.com
Industrial
www.ti.com/industrial
www.ti.com/clocks
Medical
www.ti.com/medical
Interface
interface.ti.com
Security
www.ti.com/security
Logic
logic.ti.com
www.ti.com/space-avionics-defense
Power Mgmt
power.ti.com
Transportation and
Automotive
www.ti.com/automotive
Microcontrollers
microcontroller.ti.com
www.ti.com/video
RFID
www.ti-rfid.com
Wireless
www.ti.com/wireless-apps
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
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
APPLICATIONS
Industrial controls
Traffic lights
Vending machines
Solid state relay
Lamp ballasts
Solenoid/valve controls
Static AC power switch
Incandescent lamp dimmers
Motor control
Page 1 of 10
4/30/03
MOC3012M
MOC3020M
MOC3021M
MOC3022M
MOC3023M
Symbol
Device
Value
Units
Storage Temperature
TSTG
All
-40 to +150
Operating Temperature
TOPR
All
-40 to +85
TSOL
All
TJ
All
-40 to +100
VISO
All
7500
Vac(pk)
PD
All
IF
All
Reverse Voltage
VR
All
TOTAL DEVICE
330
mW
4.4
mW/C
60
mA
EMITTER
100
mW
1.33
mW/C
PD
All
VDRM
MOC3010M/1M/2M
MOC3020M/1M/2M/3M
250
400
ITSM
All
PD
All
300
mW
mW/C
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.
Page 2 of 10
4/30/03
MOC3012M
MOC3020M
MOC3021M
MOC3022M
MOC3023M
Test Conditions
Symbol
Device
IF = 10 mA
VF
VR = 3 V, TA = 25C
Min
Typ
Max
Units
All
1.15
1.5
IR
All
0.01
100
IDRM
All
10
100
nA
VTM
All
1.8
EMITTER
Input Forward Voltage
Reverse Leakage Current
DETECTOR
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).
Page 3 of 10
4/30/03
MOC3012M
MOC3020M
MOC3021M
1.7
600
800
1.6
1.5
TA = -55oC
1.3
TA = 25oC
1.2
MOC3023M
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)
25
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
0.6
-40
-20
20
40
60
80
100
1000
STATIC dv/dt
CIRCUIT IN FIGURE 5
10
100
10
1
0
25
30
40
50
60
70
80
90
100
0.1
-40
-20
20
40
60
80
100
Page 4 of 10
4/30/03
MOC3012M
MOC3020M
MOC3021M
MOC3022M
MOC3023M
400V (MOC302X)
250V (MOC301X)
Vdc
RTEST
R = 10 k
CTEST
PULSE
INPUT
MERCURY
WETTED
RELAY
X100
SCOPE
PROBE
D.U.T.
APPLIED VOLTAGE
WAVEFORM
252 V (MOC302X)
158 V (MOC301X)
dv/dt =
0 VOLTS
0.63 Vmax
RC
RC
252
=
(MOC302X)
RC
158
=
(MOC301X)
RC
RL
Rin
180
VCC
2
MOC3010M
MOC3011M
MOC3012M
120 V
60 Hz
ZL
Rin
180
2.4k
VCC
2
MOC3010M
MOC3011M
MOC3012M
0.1 F
120 V
60 Hz
C1
Page 5 of 10
4/30/03
MOC3012M
MOC3020M
MOC3021M
MOC3022M
MOC3023M
ZL
Rin
VCC
180
6
MOC3010M
MOC3011M
MOC3012M
0.2 F
1.2 k
120 V
60 Hz
C1
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.
Page 6 of 10
4/30/03
MOC3012M
MOC3020M
MOC3021M
MOC3022M
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)
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)
Page 7 of 10
4/30/03
MOC3012M
MOC3020M
MOC3021M
MOC3022M
MOC3023M
ORDERING INFORMATION
Option
S
SR2
Description
SR2
VDE 0884
TV
TV
SV
SR2V
SV
SR2V
MARKING INFORMATION
MOC3010
X YY Q
V
3
Definitions
1
Fairchild logo
Device number
*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.
Page 8 of 10
4/30/03
MOC3012M
MOC3020M
MOC3021M
MOC3022M
MOC3023M
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
NOTE
All dimensions are in inches (millimeters)
Temperature (C)
300
230C, 1030 s
250
245C peak
200
150
Time above 183C, 120180 sec
100
Ramp up = 210C/sec
50
0
0
0.5
1.5
2.5
3.5
4.5
Time (Minute)
Page 9 of 10
4/30/03
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.
Page 10 of 10
4/30/03
Appendix E
C2
C1
0.1 uF
33nF
JP6
FT232BM
V USB
CN1
1
2
3
4
C5
C8
47pF
47pF
c4 10nF
CN-USB
Project: Design
C6
27pF
C7
27pF
0.1uF
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
TSOP IR Receiver
1 Kilo ohm
6
3
1
10 nF
1 STF16A60
2
U3
JP 2
Eeprom M24C64
E0
E1
VCC
WC
DRV8801
Mode2
16
VPropi
15
VCP 14
SCL
VSS
SDA
1000 pF
12 Kilo ohm
3 Phase
E2
Gnd
Vcc
4 Gnd
Gnd
13
5 nSleep
Cp2
12
6 Enable
Motor
7 Out +
MCP6244 OP AMP
1 uF
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
Revision: Design