Вы находитесь на странице: 1из 32

MIDDLE EAST TECHNICAL UNIVERSITY

ELECTRICAL & ELECTRONICS ENGINEERING DEPARTMENT

EE400 SUMMER PRACTICE REPORT

Student Name: Beril Günay

Student ID: 2232015

SP Company: ASELSAN

SP Date: 10.06.2019 – 05.07.2019

SP Supervisor: Abdullah Hakan Akış


TABLE OF CONTENTS
1.INTRODUCTION………………………………………………………………………………………………………………….….……....1
2.DESCRIPTION OF THE COMPANY……………………………………………………………………………………….………….. 2
2.1.COMPANY NAME……………………………………………………………………………………………………….……2
2.2.COMPANY LOCATION………………………………………………………………………………………………....….2
2.3.GENERAL DESCRIPTION OF THE COMPANY……………………………………………………………..….….2
2.4.ORGANIZATIONAL CHART…………………………………………………………………………………………….…3
2.5.NUMBER OF EMPLOYEES………………………………………………………………………………………..…….…
3
2.6.MISSION & VISION OF THE COMPANY………………………………………………………………….…..….…
3
3.WORK DONE IN SUMMER PRACTICE……………..……………………………………………………………………………….4
3.1.PROTOCOLS…………………………………………………………………………………………………………….………6
3.1.1.I2C PROTOCOL………………………………………………………………………………………..……….6
3.2.MODULES………………………………………………………………………………………………………………….......8
3.2.1.TEMPERATURE MODULE………………………………………………………………………….…..…8
3.2.2.ACCELEROMETER MODULE…………………………………………………………………………..…9
3.2.3.MAGNETOMETER MODULE…………………………………………………………………..……..…9
3.2.4.LCD MODULE………………………………………………………………………………………………..…9
3.2.5.LED MODULE………………………………………………………………………………………….…..…10
3.2.6.BUTTON MODULE……………………………………………………………………………..………..…11
3.2.7.RTC MODULE………………………………………………………………………………………….…..…11
3.2.8.ANGLE MODULE……………………………………………………………………………………..…..…11
3.3.MAIN FUNCTION and SUBFUNCTIONS
…………………………………………………………………….......12
3.3.1.SUBFUNCTIONS …………………………………………………………………………………..……..…12
3.3.2.MAIN FUNCTION ………………………………………………………………………………………..…12
3.4.CYCLIC REDUNDANCY CHECK ………………………………………………………………………..……….......13
4.CONCLUSION…………………………………………………………………………………………………………………………........14
5.REFERENCES…………………………………………………………………………………………………………………………….……15
1.INTRODUCTION

I have performed my third year Summer Practice in ASELSAN. My internship lasted


for 4 weeks, between the dates 10.06.2019 – 05.07.2019. I have performed my practice in
Embedded Systems Department, under the supervision of electrical and electronics engineer
Abdullah Hakan Akış.

During my summer practice, I worked with my partner to establish a communications


protocol between a development board and a computer using USB interface. I was
responsible of the board while my partner was responsible of the computer. Thanks to this
internship I became fluent in C, learned about various communications protocols, created
one, learned about interrupts and error detection method: Cyclic Redundancy Check.

This report starts with the introduction of the company, continues with the
description of the project and a detailed explanation of it, and ends with a conclusion
including my experiences and things that I have learned.

1
2.DESCRIPTION OF THE COMPANY

2.1.COMPANY NAME

ASELSAN A.Ş.

2.2.COMPANY LOCATION

ASELSAN has four facilities in Ankara which are in Macunköy, Akyurt, Gölbaşı, Teknokent. I
completed my work in ASELSAN Teknokent.

ASELSAN Macunköy: Mehmet Akif Ersoy Mahallesi 296. Cadde No: 16, 06370 Yenimahalle-
Ankara, Türkiye

ASELSAN Akyurt: Balıkhisar Mahallesi Koca Seyit Onbaşı Caddesi No: 1 Akyurt-Ankara P.K. 20
Akyurt, 06750 Ankara, Türkiye

ASELSAN Gölbaşı: Konya Yolu 8. Km, Oğulbey Mah. 3051. Sok. No:3, 06830 Ankara, Türkiye

ASELSAN Teknokent: Üniversiteler Mahallesi İhsan Doğramacı Bulvarı No:23/A Teknokent


ODTÜ, 06800, Türkiye

2.3.GENERAL DESCRIPTION OF THE COMPANY

ASELSAN is a company of Turkish Armed Forces Foundation, established in 1975 in


order to meet the communication needs of the Turkish Armed Forces by national means.
Currently 74,20% of the shares are owned by the Foundation whereas the remaining 25,7%
runs in İstanbul Borsa stock market.
ASELSAN is the largest defense electronics company of Turkey whose
capability/product portfolio comprises communication and information technologies, radar
and electronic warfare, electro-optics, avionics, unmanned systems, land, naval and weapon
systems, air defence and missile systems, command and control systems, transportation,
security, traffic, automation and medical systems. Today ASELSAN has become an indigenous
products exporting company, investing in international markets through various cooperation
models with local partners and listed as one of the top 100 defence companies of the world
(Defense News Top 100).

2
ASELSAN, together with the technology emphasis in its vision, has targeted to be a
company that maintains its sustainable growth by creating value in the global market;
preferred due to its competitiveness, trusted as a strategic partner, and caring for the
environment and people.
Together with the highly qualified engineering staff within more than 6.000
employees, being the main driving factor of the company's success, ASELSAN allocates 7% of
its annual income for self-financed research and development activities. [1]

2.4.ORGANIZATIONAL CHART
The organizational chart of the company is shown in Fig.1 .

Figure 1: Organizational chart

2.5.NUMBER OF EMPLOYEES

Currently, there are 6725 employees working at ASELSAN. %60 is engineers, %28 is
technicians, %7 is faculty, %5 is other personnel. Academically, %31 have completed masters
or PhD and %37 have bachelor’s degree.

2.6.MISSION & VISION OF THE COMPANY

VISION: To be a reliable, competitively preferred, environment-friendly and human


conscious technology firm which preserves its sustainable growth in the global market via
the values created for stakeholders, as well as serving its establishment purposes.

3
MISSION: By focusing primarily on the needs of the Turkish Armed Forces; to provide high-
value-added, innovative and reliable products and solutions to both local and foreign
customers in the fields of electronic technologies and system integration; continuing
activities in line with global targets as well as increasing brand awareness and contributing to
the technological independence of Turkey.

3.WORK DONE IN SUMMER PRACTICE

In the first three days of the summer practice, we were given various trainings in
Macunköy facility. These consisted of electrostatic discharging, information security,
occupational health and safety trainings.
In the third day, we were distributed to our own departments. The department that I
was assigned to was the Embedded Systems department of Communication and Information
Technologies. After I met with my supervisor and my partner for the project, we were given
the details. We needed to establish a commucation protocol between a board and a
computer via USB, then using that protocol, we needed to do various tasks such as
requesting and sending sensor data of the board, displaying numbers on LCD screen on the
board etc. I was given the task of handling the board side while my partner was responsible
of handling computer side. I worked with C language on a Windows operating system while
he worked with Python on a Linux operating system. Since both of our knowledge about the
languages and equipment were insufficient, remaining two days of the first week were spent
with acquiring information about them and inspecting example codes.

Figure 2: FRDM-KL43Z

4
The board I worked with was FRDM-KL43Z development board shown in Fig. 2. It has
many components including but not limited to a MAG3110 magnetometer, a MMA8451
accelerometer, two LEDs, two buttons, an ADC module containing temperature sensor, an
LCD display and an RTC module [2]. I used MCUXpresso IDE shown in Fig. 3 to control the
board [3].

Figure 3: MCUXpresso IDE

To get familiar with the board, I examined software development kit (SDK) and demo
app codes of the board which included various modules such as ADC module, USB module,
accelerometer module etc. To understand how board and computer communicate via USB
and to have a better understanding of communication protocols in order to establish our
own, I researched various existing protocols. These protocols are I2C, SPI, UART and USB.
Since most sensors on the board used I2C interface, the protocol I focused on was I2.

5
3.1.PROTOCOLS:

A communications protocol is a series of rules that determine the method of data


transmission in a network from one point to another. These data are sent as packets. These
packets consist of the information about the data and the data itself. The information about
the data may contain the receiver and sender identifications and the type and length of the
data. A protocol also defines procedures including but not limited to error check, flow
control and segmentation [4].

3.1.1.I2C PROTOCOL:

The reason for the popularity of I2C is because it can connect one master and
multiple slaves serially with only two lines: Serial Clock (SCL) and Serial Data (SDA). Each
slave has an address that is unique. Every message that is sent by the master contains the
slave address it is supposed to go to. Only the corresponding slave processes the message.
This way, the system becomes very simple [5].

Figure 4: Packet structure

Having a solid understanding of protocols, we created and tested our own protocol.
To test it, I merged temperature and USB modules to send temperature data when
requested. According to our packet structure which is represented in Fig. 4, first four bytes
determine the type of the message, second four bytes determine the length of the data
transmitted, and remaining are the data, encoded according to the message type. Message
types and their corresponding bytes can be seen in the table X below.
Type and length are 4 bytes, each byte represents a digit of a 4 digit number.
Although there were not enough message types to exceed 256, which would correspond to 1
byte that would be sufficient for us, we chose to send the information with 4 bytes on the
advice of our supervisors. The reason was because the size of the registers of components
were 4 bytes and that would be more compatible with our system for stable operation.

6
Table 1: Message type bytes

echo 1000
temperature 1001
magneticField 1002
acceleration 1003
controlSLCD 1004
controlRedLED 1005
controlGreenLED 1006
setRTCtime 1007
getRTCtime 1008
setRTCalarm 1009
button1press 1010
button2press 1011
boardAngle 1012

According to Table 1, when type 1000 is received from the computer, data is copied
and sent back from the board. When 1001, 1002, 1003, 1012 are received, temperature,
magnetic field, acceleration and board angle raw values are sent respectively. When 1004 is
received, according to data the display gets cleared or shows values. When 1005 and 1006
are received, red and green LEDs are turned on or off according to data. When 1007 is
received, according to the data, date is set on the board. When 1008 is received, board date
is sent to computer. When 1009 is received, an alarm for n seconds according to data is set,
after n seconds a message is sent to the computer signaling the alarm going off. When
button 1 or button 2 is pressed on the board, a message with type 1010 or 1011 is sent to
the computer to notify it. All response message types are the same as received message
types.
After testing with temperature module, I started adding more modules to use more
sensor data. Accelerometer module was added in order to test our program’s ability to
detect different message types and respond in accordance. Having multiple modules, the
code structure began to form. The main code had two parts: module initialization and the
main loop which was a while(1) loop that ran until the program was stopped. After all
modules got initialized, USB module functions tried to detect if a message was received in
the while loop. If the message got received, it got processed and got sent. We also tested
our system to find maximum data speed for various scenarios.
One of the problems we faced with the board was the buffer size. Even though the
real buffer size was more than 64 bytes, according to the USB module the receive buffer size
was 64 bytes. This created the need for different states. I created two states: reassembling
and processing. Whenever a message with length more than 64 bytes were received, the

7
board would go to reassembly state. It would wait until the whole message was received,
then go to processing state. If the message received had less than or equal to 64 bytes, it
would directly go to processing state. After processing, reply would be sent.
Remaining of the modules were added which include RTC, LCD, buttons, LEDs and
magnetometer modules. In the demo app codes, all of them had a similar structure. First,
the hardware is initialized. Then the measurements are taken or results are displayed in a
loop. Making use of this structure, I added the initialization functions to my main file’s
initialization part. Functions used for taking measurements and displaying the results were
added under message processing function. Therefore whenever the program is started, the
hardware is initialized. After a request for a measurement is received, operation is done by
using the functions of corresponding module.

3.2.MODULES

In Fig. 5, the components that were used for these modules can be seen.

Figure 5: Components of FRDM-KL43Z [6]

3.2.1.TEMPERATURE MODULE

Temperature module is a side product of the ADC module, it gets initialized with
initTemperatureModule function. To get the temperature measurement,
GetCurrentTempValue function is used. Since the variable type is int8_t which has values
min -128 max 127 and the temperature values are well within these boundaries,
measurement is stored and sent with 1 byte.

8
3.2.2.ACCELEROMETER MODULE

Accelerometer module is initialized with initAccelModule function. Measurements


are taken with measureAccel function. With this module, I was able to see which register
was being used for which operation.
The values that are obtained after this measurement is usually observed to be in
range -3000 to 3000. These values were packed into two bytes as shown:
DataArray[0] = (val >> 8) & 0xff;
DataArray[1] = val & 0xff;

3.2.3.MAGNETOMETER MODULE

Magnetometer was the most complex module to implement. It did not have demo
app codes, so I used a similar method that was used in accelerometer module. I had to look
up the registers for MAG3110 and learn what they were used for. Initialization was done by
initMagModule function.
To initialize the magnetometer, it needed to be calibrated. Calibration codes were
not provided, therefore I looked up for solutions on the internet. The method I chose to use
is as follows: measurements of magnetic field in 3 axes are taken in a loop. For every axis,
max and min values are found and updated at each loop. The loop continues to be executed
until all of the axes have a difference larger than 500 between min and max values. While
the measurements are being taken, the board is rolled around each axis to get min and max
values. The function used to calibrate the magnetometer is calibrateMag under
initMagModule. To get the measurement, measureMag is used.
The values that are obtained after this measurement is usually observed to be in
range -30000 to 30000. These values were packed into two bytes with the same method
used in accelerometer module.

3.2.4.LCD MODULE

LCD module had the demo app codes but did not have the option to display different
numbers. I wrote the codes for each number corresponding to their indexes on the LCD as
can be seen in Fig 6.

9
Fig 6: LCD and phase indexes

LCD module is initialized with initLCDmodule function. After that, if nothing is sent as
data, display is cleared with deleteAllDigitsSLCD. If data is sent, the digit on the
corresponding slot is deleted with deleteDigit and it is displayed with displayDigit.
The response to display a number on LCD can be two types. If there were no errors, 1
is sent as data to symbolize that display was successful. Otherwise 0 is sent.

3.2.5.LED MODULE

LEDs are initialized with macros LED_RED_INIT and LED_GREEN_INIT. There are only
two functions for LEDs: turn on and turn off which are LED_RED_ON, LED_GREEN_ON,
LED_RED_OFF, LED_GREEN_OFF. All other complex operations such as blinking are
controlled by sending periodic messages from the computer.

10
3.2.6.BUTTON MODULE

Button module is initialized with initButtonsInterruptModule function. Even though


the USB module contained interrupt mechanisms, I learned what interrupt is when working
with this module.
button1PressCheck and button3PressCheck functions are called before checking if a
message is received in the while(1) loop of the main function to see if the buttons are
pressed. If they are pressed, a message is sent to the computer to signal the successful
operation.

3.2.7.RTC MODULE

RTC module is initialized with initRTCmodule function. It has 3 functionalities:


setRTCtime, getRTCtime, setRTCalarm. They have different message types.
When setRTCtime request is received with the date, the data gets unpacked as
follows: first two bytes are for year, remaining one bytes are for month, day, hour, minute
and second. Then these are used as input for setRTCdatetime function.
When getRTCtime request is received, date is acquired with CommandGetDatetime
function. It is packed into the array with the same method as setRTCtime.
When setRTCalarm request is received with the offset as seconds, CommandAlarm is
called. Inside this function, RTC_SetAlarm is called with the expected alarm date and it waits
until g_AlarmPending is zero. When the interrupt is done, response is sent with the current
date signaling the alarm.
setRTCalarm is problematic because the messages that are received in the waiting
period are not processed. Also it does not support a large gap between setting and alarm
time. I did not have enough time to improve these. If I had more time I would construct a
similar structure as I did with the button module, taking the g_AlarmPending check to the
beginning of the while(1) loop.

3.2.8.ANGLE MODULE

Angle module is initialized with initAngModule function. Measurements are taken


with measureAngle function.
The values that are obtained after this measurement is usually observed to be in
range -180 to 180. These values were packed into two bytes with the same method used in
accelerometer module.
All values that are acquired after measurements are raw values. They are sent as raw
values to the computer, then the computer processes them.

11
3.3.MAIN FUNCTION and SUBFUNCTIONS

3.3.1.SUBFUNCTIONS

sendNACK: This is used to send a NACK whenever the message received is corrupted. One of
the reasons for calling this function can be the difference of the key used by the sender and
receiver.

fill2bytes: This function is used to fill an array when the number to pack is out of the range
-128 to 127.

fillLength: This is used to fill the length part of the packet with the data length information.

fillType: This is used to fill the type part of the packet with the message type.

readContentsNdetermineArrSizes: This function determines the type and length of the data,
creates an array for the received and to be sent data.

processPacket: This function gets the type information and with switch case structure,
executes the corresponding action mentioned in modules part.

reassemblePackets: Whenever a message with length more than 64 bytes is sent by the
computer, the message is reconstructed by this function since the buffer size of the board is
64 bytes.

sendPacket: This function is used to send the packets.

3.3.2.MAIN FUNCTION

Main function consists of an initialization part and a while(1) loop. The hardware is
initialized once and the loop runs until the program is halted. Various functions are called to
initialize the hardware such as BOARD_InitPins, BOARD_BootClockRUN,
BOARD_I2C_ReleaseBus, BOARD_I2C_ConfigurePins. BOARD_InitPins initializes pins
belonging to all of the modules. I2C functions are used for accelerometer and magnetometer
modules. Then modules are individually initialized.
In the while(1) loop, firstly buttons are checked to see if they were pressed. Then it is
checked whether a message is received. If not, loop ends. If a message is received it goes
through CRC and if it is corrupted sendNACK is called. If the message is not corrupted, length
and type are found with readContentsNdetermineArrSizes. If the length is more than 64,
reassemblePackets is called. If length was less than 64 or after message is reassembled,
processPackets is called. After array to send is filled, sendPacket is called. If the array length
is larger than 64, sendPacket is called in a loop.

12
Finally, we added Cyclic Redundancy Check (CRC) to verify our data transmission
reliability.

3.4.CYCLIC REDUNDANCY CHECK

Error detection algorithms are generated for the receiver to check if the message has
been corrupted. Sender and receiver agree on a function to use for error detection. Sender
uses this function to generate a number with the message and appends it to the message.
After receiver gets the message, the use the same function with the received message.
According to the result, receiver decides whether the message was corrupted.
To implement Cyclic Redundancy Check, sender and receiver agree on a key. This key
is a binary number made up of k bits. CRC treats the message as also a binary number made
up of n bits. As the first operation, k-1 zeros are appended to message. Then, by making use
of modulo-2 binary division, appended message gets divided by the key. Remainder is
appended to the original message and the message is sent.
After the message is received, receiver divides the message by the key using module-
2 binary division. If the remainder is 0, the message has been transmitted successfully. If not
the message has been corrupted [7], [8].
For example, in the division that can be seen in Fig. 7 key is 1101, the message is
100100. After the operation, remainder is 001. The data sent is 100100001.

Figure 7: Modulo-2 division of 100100000 by 1101

When receiver gets the message, they apply the operation that can be seen in Fig. 8.
In this example, there was not any corruption so the remainder is zero.

13
Figure 8: Modulo-2 division of 100100001 by 1101

We implemented byte-wise version of CRC. According to our version, the key is an


unsigned integer. Numbers in range 0-255 is XORed with the key and bitwise shifted to right
by one bit to create a table. To send the message, remainder is added as follows: a loop is
constructed to bitwise XOR the current remainder and current byte of the message through
all bytes. The result is used to find the next remainder by looking up the CRC table. The
result is the index of the next remainder. Initial value of remainder is 0, final value is found
after the loop finalizes. The remainder is appended to the message and is sent. Receiver
checks the message with the same method. If the remainder is 0, transmission is successful.

4.CONCLUSION

I completed my summer practice in ASELSAN. I had the chance to work in a field I was
highly interested in. I was able to finish my project with satisfying results. I have improved
my C skills. I learned about headers, pointers, structs, global variables and implemented
them successfully.
I learned about error detection check, connection types, communications protocols,
their advantages and disadvantages. I faced some problems such as low buffer size and
connectivity problems. Overcoming those problems and finding solutions for them helped
me to see how engineers deal with difficulties.
All in all, I gained valuable experience and information throughout my summer
practice. I was able to become more competent on a field that I am highly interested in. This
internship was very useful and it motivated me to constantly improve my skills and
knowledge.

14
5.REFERENCES

[1] https://www.aselsan.com.tr

[2]https://www.nxp.com/design/development-boards/freedom-development-
boards/mcu-boards/freedom-development-platform-for-kinetis-kl43-kl33-kl27-
kl17-and-kl13-mcus:FRDM-KL43Z

[3]https://www.nxp.com/design/software/development-software/mcuxpresso-
software-and-tools/mcuxpresso-integrated-development-environment-
ide:MCUXpresso-IDE

[4]https://erg.abdn.ac.uk/users/gorry/course/intro-pages/protocols.html

[5]https://i2c.info/

[6]https://www.nxp.com/docs/en/user-guide/FRDM-KL43Z_QSG.pdf

[7]https://www.geeksforgeeks.org/modulo-2-binary-division/

[8] R. N. Williams, A Painless Guide to CRC Error Detection Algorithms, 1993

15
6.APPENDIX
MAIN_CODE.C

16
17
18
SUBFUNCTIONS.C

19
20
21
22
23
24
25
26
27
28
MAGNETOMETER.C

29
CRC.C

30

Вам также может понравиться