Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 22

E-Design 314: Gate controller

Z. Du Toit
17042844

Declaration
I, the undersigned, hereby declare that the work contained in this report is my own work
unless otherwise stated.

Signature:

Z. Du Toit

Date:

Summary

Table of Contents
Chapter 1: Introduction................................................................................................. 7
Chapter 2: System Description........................................................................................ 8
Chapter 3: Detailed Design.......................................................................................... 10
3.1 Power Supply................................................................................................... 10
3.2 Buzzer............................................................................................................ 10
3.2.1 Calculations/Design of the buzzer....................................................................10
3.3 Buttons (Including buttons used on remote)..............................................................11
3.3.1 LPF calculations for buttons...........................................................................11
3.4 LCD.............................................................................................................. 12
3.5 IR remote transmitter and receiver.........................................................................12
3.5.1 Calculations for IR transmitter driver circuit.......................................................13
3.6 Motor driver, Motor and Gate...............................................................................13
Chapter 4: Programs.................................................................................................. 14
4.1 Program functions............................................................................................. 14
4.2 Files in the main program.................................................................................... 16
4.3 Flow diagram of main program............................................................................. 16
Chapter 5: Measurements and results..............................................................................17
Chapter 6: Conclusion................................................................................................ 18
References.............................................................................................................. 20

List of abbreviations and symbols


V

Volts

Vpp

Peak-to-peak voltage

Vp

Peak voltage

Amperes

ADC

Analogue to digital converter

HPF

High Pass Filter

LPF

Low Pass Filter

Ohm

Farad

Hz

Hertz

DC

Direct Current

PCB

Printed circuit board

IR

Infrared

Cut off frequency (Radians)

fc

Cut off frequency (Hertz)

f osc

Oscillation frequency

USB

Universal Serial Bus

UART

Universal asynchronous receiver/transmitter

COM

Communications Port

GUI

Graphical User interface

RC

Resistor-Capacitor

FET

Field Effect Transistor

JFET

Junction Field Effect Transistor

NPN

Negative-Positive-Negative

PNP

Positive-Negative-Positive
4

BJT

Bipolar Junction Transistor

Op-amp

Operational Amplifier

Second

Meter

pico

nano

micro

millie

centi

kilo

mega

Table of Figures
Figure
Figure
Figure
Figure
Figure
Figure

1:
2:
3:
4:
5:
6:

Block diagram describing the system as a whole.........................8


Circuit used for the power supply...............................................10
Circuit used for the buzzer..........................................................11
Push button circuit......................................................................12
Driver circuit for the IR transmitter.............................................12
Files contained in the final project..............................................16

Chapter 1: Introduction

Chapter 2: System Description


In this chapter, the general functionality of the gate controller is explained. In Figure 1 below,
a block diagram is shown, illustrating all the major components used, including the manner in
which they communicate with the micro-controller. Note that the direction of the arrows
showing the direction of communication to, from or bi-directionally from the microcontroller.

Power Supply

Buzzer

4 Push Buttons

16 x 1 LCD
DRV8801
Motor Driver
QJT38 6 V
DC

RL78G14 MicroController

TSOP 34838 IR
receiver

Motor
Gate

FT230XS
UART

Computer
program

RL78G12,
IR remote
transmitter
Figure 1: Block diagram
describing the system as a
controller waswhole
implemented by

As in Figure 1 above, the gate


using the Renesas RL78G14
micro-controller. The system is powered by a 10 V DC power supply (Or a heavy duty 9 V
battery) that is regulated down to 5 V by a LM7805 3-Terminal voltage regulator. This is
done because all the other components are able to run at 5 V or less.
The FT230XS UART is used for communication between computer programs via USB. In
addition to the computer program, the system is also partially controllable by 4 push buttons,
of which only 3 are given functionality in this report.
The system includes a buzzer to notify the user of the current state the system may have
entered or any operations that may have occurred, such as the gate opening or closing. The
8

LCD is a 16 by 1 display that uses parallel ports on the micro-controller to send and receive
data and commands. The LCD is used to display any necessary data to the end-user.
A QJT38 6 V DC motor (includes gearbox) is completely assembled by instructions given
upon receipt. A DRV8801 motor driver is used which contains a full H-bridge that is used to
drive the QJT38 6 V DC motor.
Lastly, TSOP34838 receiver is used to receive IR commands. This component operates at 38
kHz and includes in itself a BPF and demodulator, which solves all of the problems for
receiving a signal. A Renesas RL78G12 was modified and used as a remote to send the
signals. This micro-controller is similar to the main micro-controller that controls the whole
system, with a smaller form factor and less functions.
The complete circuit diagrams can be found in Appendix.

Chapter 3: Detailed Design


Chapter 3 focusses on the design detail of the gate controller. This chapter provides
information about all the major and minor components used, including some calculations that
lead the design choices of the system.

3.1 Power Supply


Figure 2 below shows the circuit used to power the gate controller system. This design was
directly given externally and by the LM7805s data sheet, for an output of 5 V. The capacitors
stabilises the output of the regulator. The LM7805 requires at least 7 V, so the system is
capable of being powered by a 9 V battery. However, the absolute maximum voltage that can
be supplied to the LM7805 is around 30 V, though the system was generally run on 10 V.
The reason for regulating the voltage in this system is because most of the components used
in this system were designed and manufactured for 5 V and 3.3 V.

Figure 2: Circuit used for the power supply

3.2 Buzzer
The circuit for the MT12G-2P (14M4713) buzzer is shown on the following page in Figure 3.
The buzzer can be operated in a range of frequencies; however, the micro-controller was only
able to supply an audible signal at 1 kHz and 2 kHz. Only the 1 kHz buzzer tone was used,
although the two tones in tandem could be used to create an alarm sound.

3.2.1 Calculations/Design of the buzzer


According to the data sheet of the buzzer, it is rated for 10 mA and approximately 1.5 VDC.
The supply, Vcc, is 5 V. Therefore R2 and maximum value of R3 in Figure 3 will be calculated.
(Using the data sheet of transistor Q1, model 2N3904.)
10

If IC = 10 mA, VBE(sat) min = 0.65 V, VCE(sat) = 0.2 V with hFE(min) = 100 and hFE(max) = 300:

R2

(51.50.2)
= 330 and R3 =
10 m

(50.65)
=
0.1 m

43.5 k

Figure 3: Circuit used for the buzzer

3.3 Buttons (Including buttons used on remote)


Figure 4 shows the push button designed used on the remote and the main system. The circuit
is relatively simple and involved choosing a pull down resistor. The purpose of the circuit is
to provide a logical low for the RL78G14 to register a button press. A logical low is
registered as any voltage less than 1 V, and a logical high is registered as greater than 4 V.
A problem that needed to be overcome is the fact that the buttons do not switch cleanly from
one state to another as a result of a mechanical vibration it undergoes because of a physical
press. Three methods were considered to overcome this problem. The first method is to use a
majority vote within software and the second method is to use a simple RC LPF. The third
method was to use another software method by making use of interrupts (Stopping the
interrupt as soon as an edge is detected, resolving it and then switching the interrupt on
again). However, the third method was only used on the RL78G12 (The remote) as the
RL78G14 did not have enough interrupt pins remaining as it was used for other functions.
The second method was used instead and although the RC network is not shown in Figure 4,
a calculation for the RC LPF will be shown. This filter should be added just before the RL78
Pin as shown in Figure 4.

3.3.1 LPF calculations for buttons

11

The average time a bounce in a press lasting 200 ms to 800 ms is around 1 ms to 5 ms. So
given that the frequency of the bounce is approximately 100 to 200 Hz, and RC network,
using a resistor = 330 k and a capacitor = 0.01F suffices to de-bounce the signal.

Figure 4: Push button circuit

3.4 LCD
As explained before, the LCD was integrated into the system simply as a visual aid to the
end-user. However, it may be worth noting that the LCD contrast can be set by varying R2
(As in schematic) between 600 and 1 k. The higher the resistance, the lighter the contrast
and vice versa.

3.5 IR remote transmitter and receiver


The RL78G12 was used to drive the IR remote. RC-5 protocol was implemented in the
design of the IR remote. Firstly, the timers were set in code to generate PWM signal that
serves as the IR carrier. Manchester line coding was then used to embed messages into the
carrier. The Vcc for the remote is set to 3.3 V.

Figure 5: Driver circuit for the IR transmitter

Following this, using a TSAL6200 IR emitting diode and a BS170 transistor was used. Figure
5 shows the complete driver circuit for the transmitter. As shown in Figure 5, R1 is a pull
down resistor and was simply chosen as 10 k.
12

The circuit for the receiver was given in the data sheet for the TSOP 34838 and therefore
required no calculations.

3.5.1 Calculations for IR transmitter driver circuit


To calculate the value of R2 in Figure 5, the BS170 transistor Drain-Source On-Resistance
was taken as 7.5 , as per the data sheet. The current that flows through the IR diode was
chosen as approximately 40 mA, making the forward voltage 1.3 V, also per the data sheet.
Following this:
3.3 1.3 40mxR2 7.5x40m = 0

R2 = 42.5 ,
But 100 was chosen instead due to availability.

3.6 Motor driver, Motor and Gate


The motor driver (DRV8801) was used to drive the motor, as mentioned before. The design
and application of the driver was given in its data sheet and this warranted no design
decisions. However, the motor driver has an output voltage that can be used to read the
current of the motor at any given time. The voltage read from the driver (Pin 15, VPROPI),
was however, very small, and required amplification.
For this, a simple op-amp was integrated into the system. The voltage from this Pin was
amplified so that the RL78G14 could read it (This was mentioned before, any voltage lower
than 1 V is read as a logical low). This voltage is then manipulated to produce the current
produced by the motor. The circuit and calculations for this is not shown as it did not work in
this iteration (In programming as well, sfprint() function problems) and was left out because
it was not an integral to the total functioning of the system as a whole.
Instructions for building the gate and motor was given externally and will thusly not be
discussed any further.

13

14

Chapter 4: Programs
This chapter describes the C-code that the micro-controller runs to implement the gate
controller. A brief description of the functions used, is given, as well as a structured layout
showing all the files in the final project. The code was written in the Renesas Electronics E2
Studios Environment. Calculations used in the program are included. A flow diagram
detailing the flow of the main project file is also given.

4.1 Program functions


The functions listed are in no particular order. These functions were, however, useful as they
were the most frequently used:
void delayNoInt(unit16_delay);
This provides a delay of a user-defined amount of microseconds, using the internal
timers of the micro-controller. The maximum time that can be delayed per call is
65535 microseconds.
void estop(void);
This function safely performs and emergency stop when a button on the PCB is
pressed. It does it by setting the duty cycle of the PWM controlling the motor to zero,
then after a slight delay, puts the motor to sleep, stopping it instantly.
void buttonOC(void);
This function waits for a logical low on one of two buttons. Once a logical low is
detected from a specific button, the function sets the duty cycle of the PWM to about
45%, to either close or open the gate.
void onoffbuz(void);
This function simply starts the buzzer at a certain frequency for about 0.5 seconds,
then stops the buzzer after that amount of time. This function is used to alert the user
of certain states that the gate is in.
void decodeRemote(void);
This function decodes the data that was received by the remote. This function only
stores the re-inverted bits that was received into an array and does nothing else. This
is done so that this array can be accessed and used at any point, should the raw data be
needed.
15

int whatIsIt(void);
This function further analyses the array that is stored by the function decodeRemote.
It accesses the command within the received data and returns and integer to clarify
one of 3 commands sent from the remote.
void remoteFoo(void);
This function simply reads the states in to determine when the gate is opening or
closing and displays this information onto the LCD.
void writeByteLcd(uint8_t reg, uint8_t value);
This function takes in a command or instruction and sends it to the LCD
void initLcd(void);
This function initialises the LCD.
void writeString(char *word,char length);
This functions uses writeByteLcd to write long strings to the LCD. This function
takes in a char pointer with its length and uses this information to write ASCII
characters onto the LCD.
void scroll(char lengthofa);
This function takes in a length (generally larger than 16, so that all the characters on
the LCD is displayed) and scrolls the shifts the addresses on the display from right to
left on the LCD.
void R_TAU0_Channel3_ChangeDuty_for_Servo(uint8_t servo_ratio);
This function safely changes the duty cycle of the PWM to any percentage it is called
with. This function saves time from having to use a peripheral code generator to
change the duty cycle of the PWM.
void r_intc1_interrupt(void) and void r_intc2_interrupt(void);
These functions are used to detect a logical low from two micro-switches to indicate
whether the gate has completely opened or closed. Both of these functions are
interrupts and it uses the R_TAU0_Channel3_ChangeDuty_for_Servo function to stop
the motor safely.

16

4.2 Files in the main program


Figure 6 below shows a structured project file showing all of the files in the completed gate
controller project.

Figure 6: Files contained in


the final project

4.3 Flow diagram of main program


The flow diagram showing the main function in of the program used in the micro-controller
can be found in Appendix D.

17

Chapter 5: Measurements and results


The following measurements were taken on the gate controller that was built.

Table 1: Shows different currents and voltages during different commands for the main
system, including the remote

Current (Normal mode, idle)


Current (Button pressed)
Current (Remote, idle)
Current (Remote, transmitting/button pressed)
Current (Gate Open/Close)
Voltage (Measured Vcc)
Voltage of gate driver(Gate idle)
Voltage of gate driver(Gate open/Close)
Voltage (Remote, idle)
Voltage (Drop over IR diode)
Frequency (Remote, transmitting)

3.3 V

Insert pictures here

18

Chapter 6: Conclusion
Overall, most of the major specifications of the gate controller were met. The gate controller
accepted wireless remote commands to open and close, the gate could be operated manually
with buttons on the PCB, and finally the gate can be controlled via a program on a computer.
A small problem occurs when users attempt to read the current from the motor, the system
slows down or even restarts. This is due to a function in the program called sprintf, which
uses to too much memory and computing power when called. A possible solution to this is to
manually calculate the result of the current within the code and send the value to the
computer using a much more memory and computation efficient method. However, this was
not thoroughly explored and it is recommended that users following this report find a better
implementation to read the current from the motor. A data log could also easily have been
implemented into the system but this was not done in this report.
In summary, the system functions well without any problems and meets all the major
specifications, although it has not met all the minor design specifications. However, the
minor specifications such as being able to read motor current were not physical problems
with the circuit, but a programming error. This however leaves room for improvement in the
coding used for this system.
Below in Figures a, b, and c are the, motor, main PCB and remote, respectively:

19

References
Renesas Electronics, 2015, RL78/G14 Micro-controllers Hardware Manual

20

Renesas Electronics, 2015, RL78/G14 Micro-controllers Software Manual


Fairchild LM7801, 2014, Voltage Regulator Datasheet
Diodes Incorporated, n/a, 14N007 Diode Datasheet
FTDI Chup, 2013, FT230XS UART Datasheet
Das & Sons International, Fuse Datasheet
Texas Instruments, 2015, DRV8801, Full Bridge Motor Driver

21

You might also like