You are on page 1of 59

EASTERN INTERNATIONAL UNIVERSITY

SCHOOL OF ENGINEERING

PROJECT C REPORT
DESIGN AND PROGRAM SILK TENSILE
TESTING SYSTEM

Advisor: Nguyen Ngoc Hay


Student: Nguyen Thanh Hiep – IRN: 1531100007
Dang Thanh Hung – IRN: 1531100050

-Submitted for the Project C of Automation and Control Engineering Department -


September, 2020.
REMARK OF THE ADVISOR
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………

Date: ………./………../……………

Signature
REMARKS OF COMMITEES

…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………

Date: ………./………../……………

Signature
TABLE OF CONTENT
ABBREVIATION…………………………………………………………………………….i
ACKNOWLEDGEMENT.......................................................................................................ii
ABSTRACT.............................................................................................................................iii
CHAPTER 1. INTRODUCTION...........................................................................................1
1.1 Project purpose..........................................................................................................1
1.2 The necessary of strength testing in manufacture industry..................................1
1.3 Academic factors.......................................................................................................2
CHAPTER 2: LITERATURE REVIEW...............................................................................3
2.1 General about Arduino..................................................................................................3
2.2 Arduino Mega 2560........................................................................................................4
2.3 Mechanical power transmission....................................................................................5
2.4 Control and Program technique...................................................................................7
2.4.1 Tensile calculation...................................................................................................7
2.4.2 Motor speed control................................................................................................8
2.4.3 PID controller..........................................................................................................9
CHAPTER 3: HARDWARE AND MODEL.......................................................................11
3.1 Hardware desgin..........................................................................................................11
3.2 Hardware specifications..............................................................................................12
3.2.1 Nisca DC servo motor...........................................................................................12
3.2.2 DC motor driver BTS7960 43A...........................................................................12
3.2.3 Encoder..................................................................................................................13
3.2.4 Hall effect current sensor ACS712......................................................................14
3.2.5 Power supply..........................................................................................................14
3.2.6 Data transfer module UART................................................................................14
3.3 Designing and Modelling.............................................................................................15
3.3.1 Designing................................................................................................................15
3.3.2 Manufacture method............................................................................................16
3.3.3 Real model..............................................................................................................16
CHAPTER 4: SOFTWARE..................................................................................................18
4.1 Model design – SOLIDWORKS...................................................................................18
4.2 Programming – ARDUINO IDE.................................................................................18
4.3 Control panel desgin and PID adaptive chart – VISUAL STUDIO.........................19
CHAPTER 5: PROGRAMMING........................................................................................20
5.1 System work flow.........................................................................................................20
5.2 I/O table.........................................................................................................................20
5.3 Flow chart.....................................................................................................................21
5.4 Control panel and windows.........................................................................................21
CHAPTER 6: CONCLUSION..............................................................................................22
BIBLIOGRAPHY..................................................................................................................24
APPENDIX.............................................................................................................................25
TABLE OF FIGURES
Fig 1.1 Tensile Testing Machine…………………………………………………….…………
1
Fig 1.2 Silk/paper rolling system………………………………………………………………………
2
Fig 2.1 Arduino Uno board…………………………………………………………………………….3
Fig 2.2 Arduino Nano board……………………………………………………………………………
3
Fig 2.3 Arduino Gemma board………………………...………………………………………
3
Fig 2.4 Arduino Mega 2560 board…………………………………………………………….4
Fig 2.5 Arduino Mega 2560 specification………………………………..
…………………….4
Fig 2.6 Arduino Mega 2560 Pinout……………………………………………………………
5
Fig 2.7 Arduino boards digital pins usable for interrupt………………………………………
5
Fig 2.8 The mechanical power transmission on the model……………………………………6
Fig 2.9 DC motor movement theory……………………………………………………………
6
Fig 2.10 The PID formula………………………...……………………………...
…………….9
Fig 3.1 Nisca NF5475 DC servo motor………………………………………………………
12
Fig 3.2 Motor specification……………………………………………………………...……
12
Fig 3.3 DC motor driver
BTS7960…………………………………………………………...12
Fig 3.4 BTS 7960 DC motor pinout………………………………………………………..
….13
Fig 3.5 600ppr rotary
encoder………………………………………………………………..13
Fig 3.6 Encoder theory……………………………………………………………………….13
Fig 3.7 ACS712
Pinout………………………………………………………………………..14
Fig 3.8 24VDC switching mode power
supply………………………………………………..14
Fig 3.9 UART CP2102 USB
Module………………………………………………………….15
Fig 4.1 Solidworks icon………………………………………..……………………………..18
Fig 4.2 Solidworks 2017 interface……………………………………………………………
18
Fig 4.3 Arduino IDE interface …………………………………………………………….
….19
Fig 4.4 Visual Studio
icon……………………………………………………………………………..19
Fig 4.5 Visual Studio
interface………………………………………………………………………..19
Fig 5.1 PID chart of silk speed and
tension………………………………………………………….21
Fig 5.2 PID adjust window for Tension and Speed…………………………………………………
22
Fig 5.3 Set point input window for Tension and
Speed…………………………………………….22
Fig 5.4 PID chart of silk speed and
tension…………………………………………………...22
ABBREVIATIONS

PWM: Pulse Width Modulation

PLC: Programmable Logic Controller

IDE: Integrated Development Environment

PID: Proportional–Integral–Derivative

UART: Universal asynchronous receiver transmitter


ACKNOWLEDGEMENT
First of all, I am wholeheartedly thankful to all academics of EIU Engineering School,
especially the Automation and Control Engineering Faculty and Fablab for helping and
providing me the best working atmosphere and equipment to work during this project.

Besides, I want to thank my lecturer, he is also my advisor in this project – Mr. Nguyen Ngoc
Hay for spending time to give me useful advises in testing solution, power transmission,
programming C language and apply controller to the real model in the most effective way.

Last but not least, I also want to say thanks to all committees for examining and supervising
my project report, program and hardware. Your comments will be very necessary for my last
project, the capstone, and job in the future.
ABSTRACT
The achievement of 4.0 industry revolution has set huge changes in factories around the
world. These positive change happen the same in many aspects of a modern factory, from
importation, manufacture process, packaging, storage system until exportation. This project
modelling a tensile testing system that applied mostly in textile industry or metallurgy
industry with the same structure of system. Furthermore, we drive this project to be a
functional project, by applying with PID controller with user control interface by C#,
controller adaptive graph, power transmission design and calculate, data transfer via wifi with
basic step of cloud data transfer, this is the basic object of the forth industry revoluotion.
Arduino is our choice, this is not a complicated microcontroller board as PIC, ARM or PLC,
but it is useable and popular nowadays, this board allows us to be more familiar with data
transfer by internet to get the most important goal: understand how technology work in the
era of IOT.

 Working area:
- Control speed of DC servo motors with encoder read.
- Read data from current meters.
- UART and Arduino Mega 2560 connection.
- Mechanical design.
- User control inteface design.

Keywords: UART communication, Arduino, PID controller of speed


CHAPTER 1. INTRODUCTION
1.1 Project purpose.
The idea of a strength testing system come from the real demand of quality checking
process in industry. This step happens in factories that manufacturing packaging,
weaving or rolled steel. By testing the quality and pull the material, normally band type,
this system will make sure the strength of material and place it in the right postion for the
next process.
In this project, we use ribbon to simulate a rolling and stretching process with wireless
data collecting and controlling. A digital control panel will be used to control and display
data, also the adaptive control graph in order to evaluate the control signal and how the
system work.
1.2 The necessary of strength testing in manufacture industry.
There are many reasons that make factories apply testing as a part of the whole producing
process, some of them are listed below:
 In Food & Beverage: company needs to test the strength of packaging by pressing or
stretching when full load or no load to make sure the quality of packaging. Customers,
in some cases, will ask to check the report of strength test when product has error
come from the packaging.

Fig 1.1 Tensile Testing Machine

1
 In weaving industry and rolled steel: this situation shows another type of strength
testing while the motors need to run at the right speed to keep the material at the right
shape, also prevent it from torn.

Fig 1.2 Silk/paper rolling system


By these examples, we can see that strength testing may lead to some different types but
still apply one of the fundamental topic of automation and control engineering: motor
speed control.
1.3 Academic factors.
An applicability project must come from study and experience before applied in the real
life. In strenght testing, we apply not only automation and control engineering
knownledge, our main mature, but also knownledge of mechanical engineering in
calculating the ratio of the power transmisstion for the model design. Furthermore, we
move a bit in and data communication for the data collecting and controlling. This result
will be the first step for us to develop the project to an IOT system in wireless data
collection in the future, when we already had the hardware and the main work flow of the
process.
More detail of the these types of knownledge will be illustrated in the Literature Review.

2
CHAPTER 2: LITERATURE REVIEW
2.1 General about Arduino.
Arduino is an electronic platform invented since 2005 that works mainly for testing,
experience and work easily on hardware and software. For many years, Arduino becomes
the controller of million projects, from daily activities to professional projects, which can
read input data from sensors or button and talk to the actuators like valves, motors,…The
important factor that makes Arduino becomes popular is the open – source environment,
where Arduino users can connect with others, they can be students, makers or engineers.
At the beginning, Arduino was born in Ivrea Interaction Design Institute as a tool for fast
prototyping, especially for people who have no engineering background. Since its easy to
use for beginer coders, but still flexible to adapt with advance projects in different areas,
Arduino reaches a huge community of user.
Unlike other controllers or processors like PIC, ARM, or much more complex like PLC,
Arduino is a simple circuit board that includes the microcontroller of ATMega series and
other pinout to connect with different devices.

Fig 2.1 Arduino Uno board. Source: arduino.cc

Fig 2.2 Arduino Nano board. Source: arduino.cc

Fig 2.3 Arduino Gemma board. Source: arduino.cc

3
In this project, we use Arduino Mega 2560 board as the controller, plus other
peripherals like current sensors, encoders and data transfer module via UART
protocol.

2.2 Arduino Mega 2560.


Mega 2560 is a strong and impressive microcontroller that has huge number of digital
I/O address with several functions in default or can be extented. It contains everything
needed to support the microcontroller; connect easily to computer by USB cable or
power it with a AC-to-DC adapter or battery to get started. Besides the hardware, the
software called Arduino IDE is an important part of Arduino community, which is the
programming tool to power the project with all of Arduino board.

Fig 2.4 Arduino Mega 2560 board. Source: arduino.cc


Arduino Mega 2560 board is known as one of the most popular controller in
prototyping pojects or program testing process. The specification table below will
show all of information about Arduino Mega 2560 with the main point is the number
of I/O pins, which can extent and open the working area of this controller by
connecting and controlling several devices.

4
Fig 2.5 Arduino Mega 2560 specification. Source: arduino.cc

Fig 2.6 Arduino Mega 2560 Pinout. Source: TheEngineeringProjects.com


In the advance project, there are some complicated programming technique must be
applied. Arduino includes all of these technique, such as: interrupt, timer, PWM,
ADC,… while almost basic function of Arduino Mega 2560 pins are shown on the
picture above, the table below will contain information of digital pins usable for
interrupts of all types of Arduino board (the information about interrupts of
Mega2560 is marked in the red rectangle).

Fig 2.7 Arduino boards digital pins usable for interrupt. Source: arduino.cc

2.3 Mechanical power transmission.


Mechanical power transmission is an important part of a machine or moveable
mechanism structure. There are two main function of a mechanical power
transmission applied widely in engineering: increase torque and undirect power
transfer.
- Increase torque: the mechanical structure that can increase torque when it reduce the
speed transfer from motor to objects. Speed decrease will lead to the increase in
torque.

5
R1
N=
R2

Where:
-N: ratio
-R1: number of teeth/diameter of gear, pulley 1
-R2: number of teeth/diameter of gear, pulley 2
- Undirect power transfer: in some cases, the position of motor shaft is not directed to
the rotary objects. For that reason, mechanism structure work as a power transfer,
such as linkage, cam shaft,…
In this project, we apply XL belt and XL pulley to for the power transfer from DC
servo motor to the two main rollers. The ratio between motor and rollers speed is 1:5
(the motor take one revolution, the main roller rotate five revolution).

Fig 2.8 The mechanical power transmission on the model.


In order to calculate the belt length and the distance between pulley center points, we
applied this formula:

3.14(d 2+d 1) (d 2−d 1)2


L = 2a + +
2 4a
Where:
-L: Belt length.
-a: pulley center points distance.
-d1: diameter of pulley 1
-d2: diameter of pulley 2

6
2.4 Control and Program technique.
2.4.1 Tensile calculation.
Tensile calculation is a combination between three different numbers from the
motor: torque, current, voltage. The table below shows the range of current in
two motors after the manual test with the power supply.

Voltage(V)
DC Motor 1 DC Motor 2
Current (A)
2.64 24 24
2.61 24 0
2.71 0 24
The torque formula is:
F .D
T=
2
Where:
-T: torque (Nm)
-F: Force (N)
-D: Roller diameter (m)
The total torque of two DC motor to stretch the silk is calculated base on the
formula below:
0.5 x (Current of motor 1+Current of motor 2)
T =
7.5
Where:

-T: the total torque (Nm)


-Current of motor is collected from sensors
-7.5 is the reference current of motor
The stretching force of silk is calculated by the formula below:
T x2
F=
D'
Where:
-D’ is the ratio between two encoders on motors.
If the silk goes left, the left motor will control the stretch force while the right
one control the speed.
D’ = n.D

7
Where:
pulled encoder
n=
active encoder

2.4.2 Motor speed control.


Motor speed control is one of the fundametal content of automation and
control engineering, also the most useful features of the motor. Controlling the
speed will help in determine the motor speed of according to the requirements
to get the required operation.

Fig 2.9 DC motor movement theory


There are three ways to control a DC motor: flux control, armature control and
voltage control. This report will mainly focus on voltage control which is the
most popular solution for speed control in experiments.
The silk speed calculated from encoders attached on motor 1 and 2 by the
formula below:
60 x middle encoder
Silk speed = x 0.01
600
Where:
-The middle encoder is attached in the middle roller to
collect the speed of silk move in the process.
-600 is the resolution of encoder (ppr).
-0.01 is the sample time (10ms).
-60 is the number of pulse per minute.

The voltage control use a DC motor driver, normally known as H-bridge, to


send voltage signal from microcontroller to the motor to control the speed and

8
direction (information about the motor driver is used in this project mentioned
in Chapter 3). A definition called PWM (Pulse Width Moderation) is created
by the microcontroller and feed to the motor driver. It is involves application
of varying width pulses to the motor driver to control the supply voltage. This
method proves to be very efficient as the power loss is kept at minimum, and it
doesn’t involve the use of any complex equipment.
2.4.3 PID controller.
PID (Proportional-Intsssssssegral-Derivative) controller is applied in many
industrial control engineering areas. Unlike open-loop control process, the
main key point of PID controller is closed-loop control, where the feedback of
output signal from system must follow the set point as order on each
manufacture process, this number proved that the system is working at the
right condition.

Fig 2.10 The PID formula.

PID control was implemented by the analog electronic components years


before microprocessors invented. Today, all PID controllers are processed by
the microprocessors via programming. Programmable logic controllers
(PLC) also have the inbuilt PID controller instructions. Because of the
flexibility and reliability of the PID controllers, these are widely applied in
process control applications or in control techniques that demand high
accuracy.

There are three element of PID controlle: P (Proportional), I (Integral), D


(Derivative). Depend on the system demand, engineer can create one of three
controller: P, PI, PID. Here is the PID calculation formula on Laplacian:

9
 P - Propotional

Proportional or P- controller gives output which is proportional to current


error e (t). It compares desired or set point with actual value or feedback
process value. The resulting error is multiplied with proportional constant
to get the output. If the error value is zero, then this controller output is
zero.

 I – Integral
Because P - controller always exists an offset between the process variable
and set point, I-controller provides necessary action to eliminate the steady
state error.  It integrates the error over a period of time until error value
reaches to zero. It holds the value to final control device at which error
becomes zero.
 D – Derivative
I-controller doesn’t have the capability to predict the future behavior of
error. So it does nothing when the set point is changed. D-controller solves
this problem by anticipating future behavior of the error. Its output
depends on rate of change of error with respect to time, multiplied by
derivative constant.

Normally, a PID controller when run will be looked as a continuous line graph
that present the response from system, this graph will autmatically do the real
– time compare with the set point line, troubleshoot all data appear during the
process.

10
CHAPTER 3: HARDWARE AND MODEL
3.1 Hardware desgin.
The hardware is designed base on the real model in industry with parts are listed in
the table below:

No. Name of parts Quatity

1 Nisca DC servo motor 2

2 Main roller with XL49 pulley attached on 2

3 Pulley XL10 as active pulley 2

4 120 XL timing belt 2

5 19 – 10 hat bearing 10

6 26 – 10 bearing 2

7 58 – 45 bearing 2

8 Roller 5

9 600p/r rotary encoder 1

10 Encoder stand 1

11 Limit switch 2

12 Limit switch stand 2

13 Glass plastic frame 1

14 Wood electrical box 1

15 Box angle support 8

16 Silk postion limit 2

17 Aluminium support connector 2

11
3.2 Hardware specifications
3.2.1 Nisca DC servo motor.
Nisca NF5475 DC servo motor is a 24VDC motor that includes a 200ppr encoder.

Fig 3.1 Nisca NF5475 DC servo motor.

Fig 3.2 Motor specification.


3.2.2 DC motor driver BTS7960 43A
There are two DC motors are used in our project. One for active pull, one for
stretching. Normally, with some application that create high current will cause
heat in the motor driver, especially the main IC driver will become hot and can
burn.

Fig 3.3 DC motor driver BTS7960

12
Specification:
- Power supply: 6 – 27 VDC
- Shutdown automatically if the voltage is lower than 5.5V to avoid motor run
on low voltage.
- Maximum control frequency: 25kHz

Fig 3.4 BTS 7960 DC motor pinout.


3.2.3 Encoder.
Encoder is a device that collect data and provide feedback about speed and rotary
direction. Resolution is the most important information because it shows the accuracy
of an encoder, counted by pulse/revolution (ppr – pulse per revolution). Depend on
the demand of projects, engineer can choose the right encoder to get the best
performance and also the economy aspect.
Besides two encoders attached on two DC motors already, we also use one more
600ppr encoder to count the speed of silk run between rollers. This is the feedback
signal for the motor speed control in order to stretch the band of silk at the right speed
as order.

Fig 3.5 600ppr rotary encoder.

13
Fig 3.6 Encoder theory. Source: orentialmotor.com
3.2.4 Hall effect current sensor ACS712.
Hall effect current sensor ACS712 is a type of current sensor that apply Hall Effect to
record current signal from AC/DC power supply. The analog output signal is linear
with the current so it easy to collect data in high accuracy by controllers.

Fig 3.7 ACS712 Pinout. Source: TheEngineeringProjects.com


+ DC current record:
Ip+ and Ip- must be series connected at the right position. When the current
goes from Ip+ to Ip-, the voltage output value will be at 2.5~5VDC, means the
current will come from 0~Max. Changing the postion of Ip+ and Ip-, the result
will be opposited.
3.2.5 Power supply.
The power supply is a 24VDC switching mode source. This source will run the
motors mainly, while other low voltage devices like encoders or current sensor will be
supplied by the 5VDC pins from Arduino board.

14
Fig 3.8 24VDC switching mode power supply.
3.2.6 Data transfer module UART
Universal Asynchronous Receiver Transmitter (UART) is a serial communication
device that performs parallel to serial data conversion at the transmitter side and serial
to parallel data at the receiver side. The transfer speed and data speed are
configurable.

Fig 3.9 UART CP2102 USB Module


UART is a piece of hardware like a bridge between the processor and the serial
communication protocol or port. There is no clock signal to synchronize the data
transmitted from transmitter and received by the receiver. The pin transmits the serial
data is called TX and the pin receives the serial data is called RX.

15
3.3 Designing and Modelling
3.3.1 Designing

16
3.3.2 Manufacture method.
The hardware is manufactured with several method that applied at EIU
Fablab:
 3D printing.
 Laser cutting and engraving.
 Lathe.
3.3.3 Real model.

17
Note: The real model and the design is quite different because errors happen during
manufacture and some points need to be changed to adapt the program easily.

18
CHAPTER 4: SOFTWARE
During the working process, we applied different software in each step of the project.

4.1 Model design – SOLIDWORKS.


Solidworks is a mechanical modeling computer-aided design (CAD) and computer-
aided engineering (CAE) software that owned by Dassault Systems. Besides CAD and
CAE, Solidworks also support for simulation, CAD/CAM, electrical design and
rendering.

Fig 4.1 Solidworks icon.

Fig 4.2 Solidworks 2017 interface.

4.2 Programming – ARDUINO IDE.


Arduino IDE is a programming platform that support for Arduino board series. This
software allow coders apply programming in C langugage but more easier and
comfortable to undertstand. From that point, it becomes an important part of Arduino
programming, not only provide simple code for testing or examples, but Arduino IDE
is also an environment for Arduino users commnunity share ideas of many project
since it invented.

19
Fig 4.3 Arduino IDE interface

4.3 Control panel desgin and PID adaptive chart – VISUAL STUDIO.
Visual Studio is a popular intergrated development environment (IDE) created by
Microsoft for programming app, web service, web apps or offline apps also. This
software applies many platforms such as Windows Form, Windows API, Windows
Presentation Foundation,… to support users in 36 programming languages with
usable tools.

Fig 4.4 Visual Studio icon.

Fig 4.5 Visual Studio interface

20
CHAPTER 5: PROGRAMMING
5.1 System work flow.
Two DC servo motor linked by a system of roller, transfer power via belt and pulley
to run a silk stretching system. There are two 200ppr encoders already attached on
motors that will collect data of speed and send back to Arduino as the feedback signal
for the PID controller that control stretch force, while the middle encoder that
attached on the middle roller collect data of silk speed when run between rollers.
There are two separate PID controller for two motors, one will control the stretch
force while the other go with silk speed. All control element and chart display will
work through a control panel designed by C# programming, the chart will show the
condition of response signal base on the set point value.

5.2 I/O table.


No Name Address pin Device category I.O type
.
1 Left motor 7
Motor Output
2 Right motor 9
3 Left encoder A 2
4 Left encoder B 3
5 right encoder A 20
6 right encoder B 21
7 Mid encoder A 19 Sensor
Input
8 Mid encoder B 18
9 Left limit switch 5
10 Right limit switch 10
11 Left current sensor A0
12 Right current sensor A1

21
5.3 Flow chart.

5.4 Control panel and windows

Fig 5.1 Main control panel with informed message.

22
Fig 5.2 PID adjust window for Tension and Speed.

Fig 5.3 Set point input window for Tension and Speed..

Fig 5.4 PID chart of silk speed and tension.

23
CHAPTER 6: CONCLUSION
In conclusion, this project is a chance for us to practice programming a close-loop system to
research and do study about a truthly automatic system. Furthermore, we can apply
knowledge of some important subjects: Microcontroller and Measurement – Control in data
collecting by sensor and data transfer via UART module, while the knownledge of Basic
Mechanism Transmission help us in calculate and design the mechanical power transmission
system that is suitable for tensile testing. With all the knowledge and experiences, this project
will be the first step for us to understand the fundamental points of the system and prepare for
the capstone, where we will make a bigger model, stronger motor and new solution for data
transfer.
In this project, we pay attention mostly on automation control, data collecting and processing.
Mostly using encoders with different resolution for three points of speed control, current
sensor that have different ways of signal processing. We can practice and being flexible in
choosing solution of coding, also the solution for searching and analysing documents.
After microcontroller project, this is our third project during the education program. We
achieved our main goals of the project: study about sensors, automation and control
engineering via PID controller, and the best thing is researching and document collecting, it
will be our most valuable experience for us to prepare for the future job in engineering area.

24
BIBLIOGRAPHY
- Tension Control Systems for Light, Medium and Heavy-Duty Tensioning, Warner
Electric.
- What is Arduino ? https://www.arduino.cc/en/guide/introduction
- a t t a c h I n t e r r u p t ( ) , https://www.arduino.cc/reference/en/language/functions/
external-interrupts/attachinterrupt/

25
APPENDIX
Arduino code:
#define RPWM_Output_Left 7 // left motor
#define LPWM_Output_Right 9 // right motor

int encoder = 0;
int encoder1 = 0;
int encoder_mid = 0;

//----------------truyen nhan---------------
String mySt = "",myPara ="",myPara2="",
kp_string, ki_string, kd_string,
F_set_speed_string, stop_string,
kp_speed_string, ki_speed_string,
kd_speed_string, set_speed_string;

byte sky,oi,son,tung,em,ti,py,ne;

//--------------------PID Force-------------
boolean motor_start = false;
boolean goto_Left = false ;
boolean goto_Right = false;

float vpp = 0.0048828125; // 5/1024


float sensitivity = 0.185;
float ampe, ampe_Right;

float F_pv_speed = 0;
float F_set_speed = 0;// unit N
float F_e_speed = 0; //error of speed = set_speed - pv_speed

26
float F_e_speed_pre = 0; //last error of speed
float F_e_speed_sum = 0; //sum error of speed
float F_pwm_pulse = 0; //this value is 0~255

double F_kp = 0; //p:0.7, i:0.6 d:0.13


double F_ki = 0;
double F_kd = 0; //PID Force

float pv_speed = 0;
float actual_pv_speed = 0;
float set_speed = 0;
float e_speed = 0; //error of speed = set_speed - pv_speed
float e_speed_pre = 0; //last error of speed
float e_speed_sum = 0; //sum error of speed
float pwm_pulse = 0; //this value is 0~255

double kp=0; //0.11


double ki=0 ; //0.09
double kd=0 ; //0.1 PID speed

double n=0;
int i=0;
double Torque = 0;
float Left_Current = 0.0;
float Right_Current = 0.0;

int timer1_counter; //for timmer

//volaemle unsigned int ttungp, counter, ttungp1, counter1, ttungp2, counter2 = 0;

27
const int kenhA = 2; //encoder left
const int kenhB = 3;

const int kenhA1 = 20; //encoder right


const int kenhB1 = 21;

const int encoder_green_channelA = 19; //encoder


const int encoder_green_channelB = 18;

void setup()
{
pinMode(10, OUTPUT);
pinMode(5, INPUT_PULLUP);
Serial.begin(9600); //Starts the serial connecemon with 115200 Buad Rate

pinMode(kenhA, INPUT_PULLUP); //doc encoder motor left


pinMode(kenhB, INPUT_PULLUP);

pinMode(kenhA1, INPUT_PULLUP); //doc encoder motor right


pinMode(kenhB1, INPUT_PULLUP);

pinMode(encoder_green_channelA, INPUT_PULLUP); //doc encoder motor


right
pinMode(encoder_green_channelB, INPUT_PULLUP);

attachInterrupt(digitalPinToInterrupt(kenhA), updateEncoder0, RISING);


attachInterrupt(digitalPinToInterrupt(kenhA1), updateEncoder1, RISING);
attachInterrupt(digitalPinToInterrupt(encoder_green_channelA), updateEncoder2,
RISING);

28
pinMode(RPWM_Output_Left,OUTPUT);
pinMode(LPWM_Output_Right,OUTPUT);

//--------------------------timmer setup
noInterrupts(); // disable all interrupts
TCCR1A = 0;
TCCR1B = 0;
timer1_counter = 64911;//64911;
// gia tri TCNT1 = timmer1_counter = 65535 - T*(F/n)
// F: tan so vi dieu khien = 16 Mhz
// n: bo chia tan so emmer1 = 256
// T: thoi gian can dinh thoi = 0.01s

TCNT1 = timer1_counter; // preload emmer


TCCR1B |= (1 << CS12); // 256 prescaler
TIMSK1 |= (1 << TOIE1); // enable emmer overflow interrupt
interrupts(); // enable all interrupts
//--------------------------emmer setup
}
void loop()
{
if (Serial.available()>0)
{
mySt = Serial.readString();
if (mySt.startsWith("A"))
{
myPara = mySt.substring(1);
for (int i = 0; i < myPara.length(); i++) //1
{
if (myPara.charAt(i) == '~') {sky = i;}

29
}
for (int i = 0; i < myPara.length(); i++) //2
{
if (myPara.charAt(i) == '|') {oi = i;}
}
for (int i = 0; i < myPara.length(); i++) //3
{
if (myPara.charAt(i) == '?') {son = i;}
}
for (int i = 0; i < myPara.length(); i++) //3
{
if (myPara.charAt(i) == '%') {tung = i;}
}
for (int i = 0; i < myPara.length(); i++) //3
{
if (myPara.charAt(i) == '^') {em = i;}
}
Serial.println("!");
}
kp_string/*sky*/= ki_string/*sky+1*/= kd_string/*oi*/
= kp_speed_string /*son*/= ki_speed_string /*tung*/= kd_speed_string
= myPara;

kp_string.remove(sky); //Tách giá trị thanh trượt 1 ra chuoi1


ki_string.remove(0, sky + 1); ////Tách giá trị thanh trượt 2 ra chuoi2
kd_string.remove(0, oi + 1);
kp_speed_string.remove(0, son + 1);
ki_speed_string.remove(0, tung + 1);
kd_speed_string.remove(0, em + 1);

30
F_kp = kp_string.toFloat();
F_ki = ki_string.toFloat();
F_kd = kd_string.toFloat();

kp = kp_speed_string.toFloat();
ki = ki_speed_string.toFloat();
kd = kd_speed_string.toFloat();

if (mySt.startsWith("B"))
{
myPara2 = mySt.substring(1);
for (int i = 0; i < myPara2.length(); i++)
{
if (myPara2.charAt(i) == ';') {ti = i;}
}
F_set_speed_string = set_speed_string = myPara2;
F_set_speed_string.remove(ti);
set_speed_string.remove(0, ti+1);

F_set_speed = F_set_speed_string.toFloat();
set_speed = set_speed_string.toFloat();
Serial.println("=");
}

if (mySt.startsWith("R")) { motor_start = true;}

if (mySt.startsWith("S")) { analogWrite(RPWM_Output_Left,0);
analogWrite(LPWM_Output_Right,0);
motor_start = false;}
if (mySt.startsWith("L")) { goto_Left = true;

31
goto_Right = false;
Serial.print("[");}
if (mySt.startsWith("N")) { goto_Left = false;
goto_Right = true;
Serial.print("]");}
}
if (digitalRead(5) == LOW)
{
motor_start = false ;
analogWrite(LPWM_Output_Right,0);
analogWrite(RPWM_Output_Left,0);
digitalWrite(10, HIGH);
}
else{digitalWrite(10, LOW);}
//-----------------------cam bien dong left------------------//
float AcsValue_Left=0.0,Samples_Left=0.0,AvgAcs_Left=0.0,AcsValueF_Left=0.0;
for (int x = 0; x < 100; x++){AcsValue_Left = analogRead(A0)+1; //Read
current sensor values
Samples_Left = Samples_Left + AcsValue_Left; //Sum
delay (1);}
AvgAcs_Left=Samples_Left/100; //TaF_king Average
of Samples
AvgAcs_Left = AvgAcs_Left * vpp;
AvgAcs_Left = AvgAcs_Left - 2.5;
AcsValue_Left = AvgAcs_Left / sensitivity;
Left_Current = AcsValue_Left;
//-----------------------cam bien dong right------------------//
float
AcsValue_Right=0.0,Samples_Right=0.0,AvgAcs_Right=0.0,AcsValueF_Right=0.0;
for (int x = 0; x < 100; x++){AcsValue_Right = analogRead(A1)+1; //Read
current sensor values

32
Samples_Right = Samples_Right + AcsValue_Right; //Sum
delay (1);}
AvgAcs_Right=Samples_Right/100; //TaF_king
Average of Samples
AvgAcs_Right = AvgAcs_Right * vpp;
AvgAcs_Right = AvgAcs_Right - 2.5;
AcsValue_Right = AvgAcs_Right / sensitivity;
Right_Current = AcsValue_Right;
//--------------phan 2 : gui du lieu len c#--------------
pv_speed = pv_speed *0.09424;
Serial.println("K"+ String(pv_speed));
delay(30);
Serial.println("D"+ String(F_pv_speed));
}
//-------------------end loop---------------------//
void updateEncoder0() {encoder+=1;} //increasing encoder at new pulse
void updateEncoder1() {encoder1+=1;} //increasing encoder at new pulse
void updateEncoder2() { encoder_mid+=1; } //increasing encoder at new pulse

ISR(TIMER1_OVF_vect) // interrupt service rouemne - emck every 0.1sec


{
TCNT1 = timer1_counter; // set timmer
if (goto_Left) ToLeft();
if (goto_Right) ToRight();
//PID program
}
void ToLeft()
{
n = encoder/encoder1;
if (n > 1.1) n = 1.05;

33
if (n < 0.9) n = 0.95;
F_pv_speed = (Torque*2)*n*(1/0.045); //calculate motor speed, unit is rpm
pv_speed = 60.0*(encoder_mid/600.0)/0.01;
encoder = 0;
encoder1 = 0;
encoder_mid = 0;
//PID program
if (motor_start)
{
F_e_speed = F_set_speed - F_pv_speed;

Torque = 0.5*(Left_Current*2)*(1/7.5);

F_pwm_pulse = F_e_speed*F_kp + F_e_speed_sum*F_ki + (F_e_speed -


F_e_speed_pre)*F_kd;
F_e_speed_pre = F_e_speed; //save last (previous) error
F_e_speed_sum += F_e_speed; //sum of error

if (F_e_speed_sum >4000) F_e_speed_sum = 4000;


if (F_e_speed_sum <-4000) F_e_speed_sum = -4000;

e_speed = set_speed - pv_speed;


pwm_pulse = e_speed*kp + e_speed_sum*ki + (e_speed - e_speed_pre)*kd;
e_speed_pre = e_speed; //save last (previous) error -- tich phan
e_speed_sum += e_speed; //sum of error --vi phan

if (e_speed_sum >4000) e_speed_sum = 4000;


if (e_speed_sum <-4000) e_speed_sum = -4000;
}
else

34
{
F_e_speed = 0;
F_e_speed_pre = 0;
F_e_speed_sum = 0;
F_pwm_pulse = 0;

e_speed = 0;
e_speed_pre = 0;
e_speed_sum = 0;
pwm_pulse = 0;
}
if (F_pwm_pulse <255 & F_pwm_pulse >0)
{analogWrite(LPWM_Output_Right,F_pwm_pulse);} //set motor speed
else{
if (F_pwm_pulse>255){F_pwm_pulse=255;
analogWrite(LPWM_Output_Right,F_pwm_pulse);}
else {F_pwm_pulse=0; analogWrite(LPWM_Output_Right,
F_pwm_pulse);}
}
if (pwm_pulse <255 & pwm_pulse >0)
{analogWrite(RPWM_Output_Left,pwm_pulse);} //set motor speed
else{
if (pwm_pulse>255){pwm_pulse=255;
analogWrite(RPWM_Output_Left,pwm_pulse);}
else {pwm_pulse=0; analogWrite(RPWM_Output_Left, pwm_pulse);}
}
}
void ToRight()
{
n = encoder1/encoder;
if (n > 1.1) n = 1.05;

35
if (n < 0.9) n = 0.95;
F_pv_speed = (Torque*2)*n*(1/0.045); //calculate motor speed, unit is rpm
pv_speed = 60.0*(encoder_mid/600.0)/0.01;
encoder = 0;
encoder1 = 0;
encoder_mid = 0;
//PID program
if (motor_start)
{
F_e_speed = F_set_speed - F_pv_speed;
Torque = 0.5*(Right_Current*2)*(1/7.5);

F_pwm_pulse = F_e_speed*F_kp + F_e_speed_sum*F_ki + (F_e_speed -


F_e_speed_pre)*F_kd;
F_e_speed_pre = F_e_speed; //save last (previous) error
F_e_speed_sum += F_e_speed; //sum of error

if (F_e_speed_sum >4000) F_e_speed_sum = 4000;


if (F_e_speed_sum <-4000) F_e_speed_sum = -4000;

e_speed = set_speed - pv_speed;


pwm_pulse = e_speed*kp + e_speed_sum*ki + (e_speed - e_speed_pre)*kd;
e_speed_pre = e_speed; //save last (previous) error -- tich phan
e_speed_sum += e_speed; //sum of error --vi phan

if (e_speed_sum >4000) e_speed_sum = 4000;


if (e_speed_sum <-4000) e_speed_sum = -4000;
}
else
{

36
F_e_speed = 0;
F_e_speed_pre = 0;
F_e_speed_sum = 0;
F_pwm_pulse = 0;

e_speed = 0;
e_speed_pre = 0;
e_speed_sum = 0;
pwm_pulse = 0;
}
if (F_pwm_pulse <255 & F_pwm_pulse >0)
{analogWrite(RPWM_Output_Left,F_pwm_pulse);} //set motor speed
else
{
if (F_pwm_pulse>255){F_pwm_pulse=255;
analogWrite(RPWM_Output_Left,F_pwm_pulse);}
else {F_pwm_pulse=0; analogWrite(RPWM_Output_Left,
F_pwm_pulse);}
}
if (pwm_pulse <255 & pwm_pulse >0)
{analogWrite(LPWM_Output_Right,pwm_pulse);} //set motor speed
else{
if (pwm_pulse>255){pwm_pulse=255;
analogWrite(LPWM_Output_Right,pwm_pulse);}
else {pwm_pulse=0; analogWrite(LPWM_Output_Right, pwm_pulse);}}
}

37
Code C#:
FROM 1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
if (!serialPort1.IsOpen)
{
serialPort1.Open();
textBox1.Text = "Opened";
textBox1.ForeColor = Color.MediumSeaGreen;
}
else { textBox1.Text = "Busy"; textBox1.ForeColor = Color.Gray; }
}
int[] recieve = new int[10];
int i = 0;
string[] String;
double temp;

38
private void label1_Click(object sender, EventArgs e)
{
}
private string rxString;
string inputString;
private void displayText(object o, EventArgs e)
{
//hien thi len c#
if (rxString.StartsWith("K"))
{
rxString = rxString.Substring(1);
rpm_textBox.Text = rxString;
}
if (rxString.StartsWith("D"))
{
rxString = rxString.Substring(1);
tension_textBox.Text = rxString;

FROM 2
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1

39
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
Boolean txt = true;
private void Form2_Load(object sender, EventArgs e)
{
if (txt)
{
Kp_textBox_F2.Text = "1.0";
Ki_textBox_F2.Text = "0.45";
Kd_textBox_F2.Text = "0";

Kp_TB_speed_F2.Text = "0.12";
Ki_TB_speed_F2.Text = "0.19";
Kd_TB_speed_F2.Text = "0";
txt = false;
}
}
private void button1_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}}

40
PID CHART
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ZedGraph;

namespace WindowsFormsApp1
{
public partial class TensionChart : Form
{
int tickStart = 0;
public TensionChart()
{
InitializeComponent();
}
double tension, tesion_setpoint;
Boolean scroll = true;
public void draw(double tension, double tesion_setpoint) // Ở ví dụ này chúng ta
có 2 đường
{
tension = (Convert.ToDouble(textBox2.Text));
tesion_setpoint = (Convert.ToDouble(tension_label.Text));
if (zedGraphControl1.GraphPane.CurveList.Count <= 0)
return;

41
// Kiểm tra việc khởi tạo các đường curve
// Đưa về điểm xuất phát
LineItem curve1 = zedGraphControl1.GraphPane.CurveList[0] as LineItem;
LineItem curve2 = zedGraphControl1.GraphPane.CurveList[1] as LineItem;
if (curve1 == null)
return;
if (curve2 == null)
return;
// list chứa các điểm.
// Get the PointPairList
IPointListEdit list1 = curve1.Points as IPointListEdit;
IPointListEdit list2 = curve2.Points as IPointListEdit;
if (list1 == null)
return;
if (list2 == null)
return;
// Time được tính bằng ms
double time = (Environment.TickCount - tickStart) / 1000.0;
// Tính toán giá trị hiện thị
// Muốn setpoint1hiện thị cái gì thì chỉ việc thay vào setpointx
list1.Add(time, tension); // Đây chính là hàm hiển thị dữ liệu của mình lên đồ
thị
list2.Add(time, tesion_setpoint); // Đây chính là hàm hiển thị dữ liệu của
mình lên đồ thị
// Ko vẽ setpoint2 mà thử vẽ đồ thị hình sin với 3 seconds per cycle
//list2.Add(time, Math.Sin(2.0 * Math.PI* time / 3.0));
// đoạn chương trình thực hiện vẽ đồ thị
Scale xScale = zedGraphControl1.GraphPane.XAxis.Scale;
if (time > xScale.Max - xScale.MajorStep)
{

42
//xScale.Max = time + xScale.MajorStep;
// xScale.Min = xScale.Max - 30.0; // Timer chạy qua 30 sẽ tự động dịch
chuyển tịnh tiến sang trái
// Nếu ko muốn dịch chuyển mà chạy bắt đầu từ 0 thì :
xScale.Min = 0;
if (scroll)
{
xScale.Max = time + xScale.MajorStep;
xScale.Min = xScale.Max - 30.0;
}
else
{
xScale.Max = time + xScale.MajorStep;
xScale.Min = 0;
}
}
// Vẽ đồ thị
zedGraphControl1.AxisChange();
// Force a redraw
zedGraphControl1.Invalidate();}
public void draw2(double speed, double speed_setpoint) // Ở ví dụ này chúng ta
có 2 đường
{
speed = (Convert.ToDouble(rpm_textBox.Text));
speed_setpoint = (Convert.ToDouble(speed_label.Text));
if (zedGraphControl2.GraphPane.CurveList.Count <= 0)
return;
// Kiểm tra việc khởi tạo các đường curve
// Đưa về điểm xuất phát
LineItem curve_1 = zedGraphControl2.GraphPane.CurveList[0] as LineItem;

43
LineItem curve_2 = zedGraphControl2.GraphPane.CurveList[1] as LineItem;
if (curve_1 == null)
return;
if (curve_2 == null)
return;
// list chứa các điểm.
// Get the PointPairList
IPointListEdit list_1 = curve_1.Points as IPointListEdit;
IPointListEdit list_2 = curve_2.Points as IPointListEdit;
if (list_1 == null)
return;
if (list_2 == null)
return;
// Time được tính bằng ms
double time = (Environment.TickCount - tickStart) / 1000.0;
// Tính toán giá trị hiện thị
list_1.Add(time, speed); // Đây chính là hàm hiển thị dữ liệu của mình lên đồ
thị
list_2.Add(time, speed_setpoint); // Đây chính là hàm hiển thị dữ liệu của
mình lên đồ thị
Scale x_Scale = zedGraphControl2.GraphPane.XAxis.Scale;
if (time > x_Scale.Max - x_Scale.MajorStep)
{
//xScale.Max = time + xScale.MajorStep;
// xScale.Min = xScale.Max - 30.0; // Timer chạy qua 30 sẽ tự động dịch
chuyển tịnh tiến sang trái
// Nếu ko muốn dịch chuyển mà chạy bắt đầu từ 0 thì :
x_Scale.Min = 0;
if (scroll)
{
x_Scale.Max = time + x_Scale.MajorStep;

44
x_Scale.Min = x_Scale.Max - 30.0;
}
else
{
x_Scale.Max = time + x_Scale.MajorStep;
x_Scale.Min = 0;
} }
// Vẽ đồ thị
zedGraphControl2.AxisChange();
// Force a redraw
zedGraphControl2.Invalidate();
}

public void TensionChart_Load(object sender, EventArgs e)


{
GraphPane myPane = zedGraphControl1.GraphPane;
// Khai báo sửa dụng Graph loại GraphPane;
myPane.Title.Text = "Tension PID Graph";
myPane.XAxis.Title.Text = "Time";
myPane.YAxis.Title.Text = "Tension";
// Định nghĩa list để vẽ đồ thị. Để các bạn hiểu rõ cơ chế làm việc ở đây khai
báo 2 list điểm <=> 2 đường đồ thị
RollingPointPairList list1 = new RollingPointPairList(1000);
RollingPointPairList list2 = new RollingPointPairList(1000);
LineItem curve1 = myPane.AddCurve("actual tension", list1,
Color.Red,SymbolType.None); // Color màu đỏ, đặc trưng cho đường 1
LineItem curve2 = myPane.AddCurve("tension set point", list2,
Color.Blue,SymbolType.None); // Color màu Xanh, đặc trưng cho đường 2
// ví dụ khoảng cách là 50ms 1 lần
timer1.Interval = 50;
//timer1.Enabled = true; // Kích hoạt cho timer1

45
//timer1.Start(); // Chạy Timer1
// Định hiện thị cho trục thời gian (Trục X)
myPane.XAxis.Scale.Min = 0; // Min = 0;
myPane.XAxis.Scale.Max = 30; // Mã = 30;
myPane.XAxis.Scale.MinorStep = 1; // Đơn vị chia nhỏ nhất 1
myPane.XAxis.Scale.MajorStep = 5; // Đơn vị chia lớn 5
// Gọi hàm xác định cỡ trục
zedGraphControl1.AxisChange();
myPane.YAxis.Scale.Min = 0;
myPane.YAxis.Scale.Max = 70;
GraphPane myPane2 = zedGraphControl2.GraphPane;
// Khai báo sửa dụng Graph loại GraphPane;
myPane2.Title.Text = "Speed PID Graph";
myPane2.XAxis.Title.Text = "Time";
myPane2.YAxis.Title.Text = "Speed";
//myPane2.XAxis.Title.Text.bo
//myPane2.YAxis.Title.Text = "Speed";
// Định nghĩa list để vẽ đồ thị. Để các bạn hiểu rõ cơ chế làm việc ở đây khai
báo 2 list điểm <=> 2 đường đồ thị
RollingPointPairList list_1 = new RollingPointPairList(1000);
RollingPointPairList list_2 = new RollingPointPairList(1000);
LineItem curve_1 = myPane2.AddCurve("actual speed", list_1, Color.Red,
SymbolType.None); // Color màu đỏ, đặc trưng cho đường 1
LineItem curve_2 = myPane2.AddCurve("speed set point", list_2, Color.Blue,
SymbolType.None); // Color màu Xanh, đặc trưng cho đường 2
// ví dụ khoảng cách là 50ms 1 lần
timer1.Interval = 50;
//timer1.Enabled = true; // Kích hoạt cho timer1
//timer1.Start(); // Chạy Timer1
// Định hiện thị cho trục thời gian (Trục X)
myPane2.XAxis.Scale.Min = 0; // Min = 0;

46
myPane2.XAxis.Scale.Max = 30; // Mã = 30;
myPane2.XAxis.Scale.MinorStep = 1; // Đơn vị chia nhỏ nhất 1
myPane2.XAxis.Scale.MajorStep = 5; // Đơn vị chia lớn 5
// Gọi hàm xác định cỡ trục
zedGraphControl1.AxisChange();
myPane2.YAxis.Scale.Min = 0;
myPane2.YAxis.Scale.Max = 50;

myPane2.YAxis.Scale.MinorStep = 1; // Đơn vị chia nhỏ nhất 1


myPane2.YAxis.Scale.MajorStep = 5; // Đơn vị chia lớn 5

//Khởi động timer về vị trí ban đầu


tickStart = Environment.TickCount;
}
private void timer1_Tick(object sender, EventArgs e)
{
draw(5, 20);
draw2(5, 20);
}
private void button3_Click(object sender, EventArgs e)
{
}
int check = 0; // để cho khi nhấn Start là sẽ bắt đầu từ điểm 0
private void button1_Click(object sender, EventArgs e)
{
if (button1.Text == "START")
{
timer1.Enabled = true;
button1.Text = "STOP";
button1.BackColor = Color.IndianRed;

47
// Khởi động timer về vị trí ban đầu
if (check == 0) { tickStart = Environment.TickCount; check = 1; }
}
else
{
timer1.Enabled = false;
button1.Text = "START";
button1.BackColor = Color.LightSeaGreen;
}}
private void rpm_textBox_TextChanged(object sender, EventArgs e)
{}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
zedGraphControl1.GraphPane.CurveList.Clear();
zedGraphControl1.GraphPane.GraphObjList.Clear();
zedGraphControl2.GraphPane.CurveList.Clear();
zedGraphControl2.GraphPane.GraphObjList.Clear();
this.Close();
} }}
INPUT FORM
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;

48
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class InputForm : Form
{
public InputForm()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{ this.Close();}
private void InputForm_Load(object sender, EventArgs e)
{
tension_TB.Text = "8";
speed_TB.Text = "120";
} }}

49

You might also like