Assignment-1 NG4S903 Embedded System Design Student ID 30090931
Assignment-1 NG4S903 Embedded System Design Student ID 30090931
1. Abstract 3
2. Aims and Objectives 3
3. Methodology 4
4. Testing and Results 18
5. Conclusion 23
6. Appendix 25
7. References 34
2
ABSTRACT
The word Embedded system is referred to an application specific computer system which is built into a
standalone device or act as a part of a larger integrated system. It is very powerful and cost-effective way
of design when hardware and software deigned and properly integrated. Currently, embedded systems are
found in many applications in our day-to-day life. For example, from our smart wrist watches, washing
machines, televisions, cars to smart homes are controlled by embedded systems.
This report discusses, the design and development of an embedded system for the given requirement and
Specification of a digital alarm clock using Renesas S7G2 -SK development kit. The main benefit for using
This platform is it comes with integrated LCD display and a touch screen. It consists of many more
peripherals integrated to it which are useful for this design. Also, the S7G2-SK flatform is powered by
“Arm Cortex M4 microcontroller” and the Renesas synergy Software Support Package that comes with
Cortex Microcontroller Software Interface Standard (CMSIS) gives the freedom of using a high-level
programing language like C by doing all the configurations required in Hardware Abstraction Layer (HAL)
using the synergy configurator. This will save the time and reduce the complexity of the programming
required because there is no need to configure the special function registers manually.
In this design, a Real time Operating system (RTOS) based on thread X is used to manage the resources
effectively between the tasks for the alarm clock operation and touch screen operation. The digital alarm
clock is controlled by only two touch buttons, which are capable of set and reset the alarm, set and adjust
both the clock time and alarm time using a state machine design approach which is further explained in the
report. The alarm can be set or deactivated only in the normal display state and indicated by the Red LED.
If the alarm is set, when the current time is matched to alarm set time, it will ring. This can be visually
indicated by toggling Green and Yellow LED s. When Alarm is ringing it can be deactivated either touching
any of the two buttons. Also, if no button is pressed during the alarm then it will automatically stop and
deactivate after one minute.
The purpose of this task is to design and development of a digital alarm clock using SKS7G2 Development
Platform using C language.
After successfully completing this assignment of designing an embedded application for a digital alarm
clock, it is expected to demonstrate the following outcomes.
1. Ability to analyze, critically evaluate and design reliable embedded application according to the
requirements.
2. To design and critically evaluate real time embedded solutions considering real time constraints as cost
and sustainability.
3
METHODOLOGY
Initially, the given user requirement was analyzed to identify the functional requirements for the design.
This was achieved by following the process which is shown below.
Firstly, we would underline the nouns, noun phrases, verbs and verb phrases of the complete user
requirement which that given below.
You are required to design a digital alarm clock using the S7G2-SK. The basic clock’s functionality follows
the State Transition Diagram in Figure 1. As there are no audible outputs on these boards, use two LEDs
that flash alternately to signify an alarm condition. Use a third LED to give a visual output as to when the
alarm is in a set condition. The alarm clock is limited to using two buttons to change the mode of operation,
as indicated in State Transition Diagram.
You are required to implement the alarm functionality in addition to the normal clock where the alarm
clock’s alarm can only be set or cleared in the ‘Normal Display’ state;
this is the only state that the alarm condition can be activated, which would require the alarm to be set and
the actual time to match the alarm time. (The alarm functionality is not indicated in the state transition
diagram) If the alarm has been activated then any of the two buttons will stop the alarm, taking it out of the
set condition. If the alarm is not stopped by user interaction, then after one minute the alarm clock will
automatically stop the LEDs toggling, again taking it out of a set condition.
[Ref 3]
4
Then We tabulate and sort out the nouns and verbs to extract the important entities and attributes. this was
done by eliminating nouns and verbs that deemed to be irrelevant, duplicated or have a similar meaning to
others. Additionally, some were renamed to more (software) relevant terminology.
Key Nouns, Adjectives and Noun Phrases Key Verbs, Adverbs and Verb Phrases
Actual time – (u_rtc_clk) LED toggling – (LED_toggle)
Alarm time – (u_alarm_clk) Alarm has been activated – (Alarm_Ring)
Mode of operation – (state) Normal clock – (RTC_clock)
Flash Alternatively – (toggle) Alarm can be set – (Alarm_set)
Two buttons – (Button1_flag, Button2_flag) Reset – (System_Initialize)
Alarm is in a set condition – (Alarm_set_flag)
Alarm condition – (Alarm_active_flag)
One Minute – (one_minute_flag)
From above table, the key Nouns represent important variables and most of the time they are global
variables. The key verbs represent the functions. There were used in the algorithm development and source
code generation on the later stage of this project.
Then according to the given requirement, the complete design of the state transition diagram is shown
below.
Button 1
Normal
Alarm Button 2
Display
RTL Set
Clock Display
Set Set
Normal Alarm
Hour Hour
+ +
1 1
Set Set
Normal Alarm
Minutes Minute
+
s +
Set
Set
Normal
Alarm
Seconds
Seconds
+ +
1
Figure 2 5
Initial set up and the import of the templates into project
As per the Specification given in the URS above, this project should be developed on the Renesas S7G2-
SK development platform. To develop the embedded software to this we use Renesas E2 studio ISDE and
C language. The advantage of using the Synergy SSP is it comes with Preloaded software like CMSIS
package which include all the drivers and API to control the ARM Cortex M4 Microcontroller and all other
Integrated peripherals to the board. Also, it includes “Thread X’’ RTOS. The use of APIs in SSP make it
easier to configure the board and its peripherals as per the reqiremet using synergy configuration
perspective. The board is integrated with 2.4” QVGA TFT LCD Display with the capacitive touch screen
which will be utilizing for our project as display and two touch screen buttons as user inputs to our digital
alarm clock.
A pre-configured project template with the use of RTOS Threads for the clock function and display and
touch screen function named “S7G2_AlarmClock.zip” was given and which need further developments.
However, in this project the RTOS threads were pre-configured and all the drivers and integration for the
LCD display and touch screen has done. Firstly, we would import this file to our E2 Studio development
environment as shown below.
File > Import > Select project from folder or Archive > Click Next > Click Archive > Browse and select
the “S7G2_AlarmClock.zip” from the directory > Click open > Click Finish.
Then the project will be imported and shown in the project explorer view. Then we will open the “Synergy
Configuration.xml” and check the project summery is matching with our bard support files and device and
tool chain versions.
Figure 3
There are two source files in this project which need to edit and develop to design this digital alarm clock.
One is “RTC_thread_entry.c” and other one is “gui_event_handler.c”. In this design all the clock and alarm
functionality were implemented and handled inside the “RTC_thread_entry.c” and all the GUI events were
controlled in “gui_event_handler.c” source files.
6
Then check for the configuration and “generate Project Content Button” clicked to generate the
configuration file for the project. This updates all the configuration registers as per our design requirement.
For the design of user interface, an additional third-party software called GUIX Studio I needed. However,
partially completed GUI template is also included in this template. That is “guix_alarmclock_gxp”.
it can open and complete that design in the GUI Studio as shown below.
Once change or modified the design of the GUI it should generate all output files for the GUI as shown in
the path below.
In GUIX Studio > Projects > Generate all output files > Click Generate.
Then the project template is “Build” and checked for any errors.
As per the requirement, two touch screen buttons were needed for the operation of the clock. For this
purpose, two buttons were created in the GUIX Studio window and their ID s were ID_BUTTON1 and
ID_BUTTON2 and generated all output files. Then in the “gui_event_handler.c” these button IDs were
called into GX Signal Event. That means each time the button ID is called that GX Event Click will be
triggered. To use it we will create two global variables called Button1_flag and Button2_flag and make
those flags to 1 when the event triggered.
7
Functional Implementation of State Transition Operation.
For both of the alarm clock and real time clock operation there were total 8 states were created as shown in
the Strate Diagram in figure 2. The state change operation from each state illustrated in the following flow
chart. The left diagram shows transition operation inside each clock state and the right shows state transition
between RTC clock & Alarm Clock as per the state diagram above.
Start Start
Current State Current State
if if
Button1_flag Button2_flag
== 1 No == 1 No
Yes Yes
End End
Figure 3 Figure 4
Functional Implementation of the keeping and adjusting the time for both RTC and alarm clock
For the time keeping variable for each RTC and alarm clock the user defined data structure called “clock_t”
was used and this structure was pre-configured in the project template. For each clock there are two time
keeping variables “u_rtc_clk” and “u_alarm_clk” were created. If any of the clocks is in a time adjust state,
the button 2 will update corresponding variable of the time as per the following flow chart.
8
Start Start
Time Set State Time Set State
if if
Button2_flag Button2_flag
== 1 == 1
Ye Yes
s
Yes Yes
Increment Increment
Hour by 1 Minute by 1
Figure 4 Figure 5
Start
Time Set State
if
Button2_flag
== 1
Yes
Yes
Increment
9
seconds by 1
Figure 6
Functional Implementation of the Real Time Clock – Time Keeping mechanism
To keep the RTC clock showing the correct time, it is required to generate clock signal for the RTC clock
and update the time at the same time. For the clock signal generation, a one second period general purpose
timer was created on the RTC Thread using synergy configuration perspective. The timer configuration is
shown below.
After creation of timer0, the “generate project content” was clicked to setup the configuration registers in
BSP layer. Then the timer is initialized and started in the initialization function. The timer calls back
function will generate a hardware interrupt at every one second. Therefore, the time keeping function
(RTC_clock) was called and triggered at every one second. Then the normal clock time will update as
shown in the below flow chart in Figure 7.
10
Start
No
Reset Seconds to 00
No
Reset Minutes to 00
No
Reset Hours to 00
Figure 7
11
Functional Implementation of the Alarm Set Function
A per the given requirement, it should be able to activate or deactivate the alarm. For that purpose, alarm
set function has been implemented. The purpose of this function is to indicate the alarm set state by visually
lighting the LED 2 and keep checking the alarm activate condition to activate the alarm using
“Alarm_Active_flag”.
Start
if
No Turn off Red
Alarm_set_fla
LED
g is == 1
Yes
Turn on Red
LED
if RTC clock
time == Alarm
No
time
Yes
Alarm_active_flag = 1
Figure 8
“Alarm_set_flag” is set or reset by the Button2_flag event each time it switches from “rtc_clk” state to
“alarm_clk” state assuming the alarm time is set after transition.
12
Functional Implementation of the “LED_toggle” function.
As per the requirement, since there are no audible outputs available, alarm ring condition should be
visualized by tow toggling LEDs. In this design, the toggle function was implemented as per the given flow
diagram. LED 1(GREEN) and LED3 (Yellow) were selected for the indication.
Start
Toggle Delay
Toggle
Invert Toggle 100 ms
Yes
According to the requirement, to activate the alarm, the clock should be in Normal Clock state, therefore
“Alarm_Set” and “Alarm_Ring” functions only be called in “rtc_clk” state.to activate and deactivate the
ringing condition, separate variable called “Alarm_Active” flag is used. The functional flow chart for the
“Alarm_Ring” function is shown below Figure 10.
13
Start
if Alarm active No
flag is == 1
Yes
Timer 1 Start
Yes Yes
Figure 10
End
14
Alarm should be automatically Turned off if no button was pressed after its activation. For that purpose, in
this design, we have created another hardware timer called timer 1 with 1 minute period inside the RTC
Thread. This timer was configured as a one-shot timer and each time the timer overflow happens and the
timer needs to be manually started again. The configuration of this timer is shown below.
15
The above discussed models were implemented using the Embedded C language. The complete copy of the
source code is attached to the appendix section. The developed program code was built successfully without
any bugs.
Then using the debug configuration perspective, the source code was downloaded to the S7G2 SK Board
via the micro-USB cable connected to the PC and the J19 “debug_usb” port on the board.
16
17
TESTING AND RESULTS
The operation of the RTC clock was tested using the watch expression’s view in debug perspective.
The real time clock was compared with the PC clock and both were showing the same time 10 minutes after
setting the time. that means our RTC clock functioning properly.
18
Testing the state transition of the clock using the watch expressions variable. All 8 states were traced
properly and shown below.
19
Time Adjusting function was physically tested on the board and working successfully. Adjusted alarm clock
is shown below.
20
Activation of the alarm was tested using a hardware break point called and on actual board itself, which is
shown below.
21
Alarm stop condition for both automatic and mannual was checked and verified on the debug perspective
as well as on the actual board. below shows the breakpoint testing of automatic alarm stop.
22
EVALUATION OF THE DESIGN & CONCLUSION
After Implementing all the functions and variables in the source code using the C language, the successful
program was compiled and tested using both J-Link ARM debugger and physical Hardware Itself. It can be
observed that all the functions designed and were working as expected and the Digital Alarm Clock
Prototype was working Successfully to the Given Requirements. So, it can be concluded that a project is
successful, and the intended objectives were achieved.
The Real time Clock implemented in the design was working accurately enough as it seems in our testing,
However, to assure its accuracy, more time the testing needs to be conducted and should be observed for
any differences in the time actual time. It could be possible to calculate the accuracy of the clock based on
the System Clock Frequency (Crystal Parameters like PPM) Of S7G2-SK board, but it is difficult to exactly
calculate it because of the use of High-level Language Like because the exact instruction execution timing
was hidden from the user.
In this Design Approach of designing a Digital Alarm clock, there were some Advantages using S7G2-SK
platform. One is that the Renesas Synergy ISDE which intergrade all the software and drivers in to a one
single Package. This will help the designer to develop the design in a single platform like S7G2-SK without
looking for different vendors for different peripherals and integrating them into final Design.
Other one is Using a GUI integrated with a touch screen buttons for this design. It allows the designer to
design and customize the User interface as they please and improve the end user experience. Also, this can
be beneficial in the final production version because it omits the physical switches as user inputs.
Other advantage of this design approach and the template is the use of real time operation system RTOS.
The Synergy SSP comes with an integrates the RTOS called “ThreadX” and it has been used in the design
template crating two different threads for the Clock functionality and GUI update. The main benefit of using
the RTOS is that the threads can be set to sleep to save power. If this design is intended to produce as a
battery powered device, it is important to save the power and improve the battery life. Also, Use of RTOS
allows the limited system resources to be shared between the tasks based on the priority in real time and it
is advantages to manage the constrains like cost and size of the embedded system.
Although the project was giving the intended outcome, there were several drawbacks were identified in this
design as well.
Although it was advantageous to use the S7G2-SK developments flatform as requested int the URS, first
drawback comes from the board itself since it does not contain the hardware necessary to make sound. How
ever this can be overcome by integrating an amplifier with buzzer or a speaker to a J16 AUDIO port with a
3.5mm audio jack.
Also Using an all-in-one software package with built in hardware also limit the possibility of using hardware
and software peripherals like Displays and touch screens from other vendors which are more flexible or
cost-effective.
Using only Two buttons for the entire clock operation also introduce few issues to the design as well.
Because of this many variables and flags needed to be implementing the operations for different scenarios
of the same button press. This cause increases the memory usage of the program. However, if the memory
usage can be optimized by different efficient programing methods, there were other ways to implement
different scenario of working from the same button like Long & Short Press, or Single, Double or Triple
press in a same time period are the ways. This can be implemented in the final version of the design if we
further develop.
23
During the testing of the time adjust function for the clock and the alarm, one huge flaw of this current
design was identified. And that is there is no way to observe the time setting state of the clock. Because of
this, if the user needs to adjust the time, they need to know the number of times to press the
button_1(MODE) to set a certain time digit to its update condition. This can be easily rectified by
implementing a GUI representation of “Blinking” or “Highlighting” of the relevant digit while in the time
set state. Due to the tight constrains of time and GUIX design knowledge requirements, this function was
not included in the current design and can be added later.
24
APPENDIX
The alarm clock functionality and all other clock functionality implemented “RTC_thread_entry.c”
25
26
27
28
29
30
31
32
33
State definition and the clock structure defined in “u_rtc_clk.h”
34
All the GUI display update and other UI functions are included in the gui_event_handler.c
35
36
37
38
GUIX Deign for Screen 1 and screen 2
39
REFERENCE
[1] Renesas SynergyTM Starter Kit SK-S7G2 User’s Manual Synergy S7G2 MCU User’s Manual.
(2015). Available at: https://www.renesas.com/us/en/document/mat/s7g2-starter-kit-sk-s7g2-users-manual
[Accessed 20 Jan. 2024].
[2] Oed, R. (2020). BASICS OF THE RENESAS SYNERGY TM PLATFORM. [online] Available at:
https://www.renesas.com/us/en/document/gde/basics-renesas-synergy-platform?r=479891 [Accessed 20
Jan. 2024].
[3] NG4S903_CW4P1M_Cover_2023-2024 by Shivagunalan Shivanathan
[4] S7G2_AlarmClock.Zip template by Shivagunalan Shivanathan
[5] NG4S903-Lec2 -SyLec IOs and clock by Shivagunalan Shivanathan
[6] NG4S903-Lec5 Timers by Shivagunalan Shivanathan
[7] NG4S903-Lec3 Syfirmware design practiceRv2 by Shivagunalan Shivanathan
[8] NG4S903-Lec5 Timers by Shivagunalan Shivanathan
40