course project self-calibrating prayers clock

35
Course Project Self-Calibrating Prayers Clock Khaled A. Al-Utaibi [email protected]

Upload: berg

Post on 17-Feb-2016

33 views

Category:

Documents


4 download

DESCRIPTION

Course Project Self-Calibrating Prayers Clock. Khaled A. Al- Utaibi [email protected]. Agenda. Microprocessors Microcontrollers Embedded Systems. Introduction. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Course Project Self-Calibrating  Prayers Clock

Course ProjectSelf-Calibrating Prayers ClockKhaled A. [email protected]

Page 2: Course Project Self-Calibrating  Prayers Clock

Agenda

Microprocessors

Microcontrollers

Embedded Systems

Page 3: Course Project Self-Calibrating  Prayers Clock

To help Muslims everywhere to know the prayer times accurately, local and international companies have manufactured many models for prayer clock

Most of these can display the following information:1. Current time and date.2. Room temperature.3. ATHAN times for the five

prayers.4. Time to the IQAMA.

Introduction

Page 4: Course Project Self-Calibrating  Prayers Clock

The existing prayer clocks have the following features:1. Preprogrammed prayer times for large set of cities

around the world.2. Ability to program prayer times for other cities by

entering latitude and longitude coordinates.3. Ability to program prayer times according to

different Islamic calendars such as Umm Alqura, International Islamic University and University of Islamic Sciences.

4. Ability to alarm prayer time using sound alarm or by flashing the prayer time display.

Introduction

Page 5: Course Project Self-Calibrating  Prayers Clock

The existing prayer clocks have the following limitations:1. Require programming of date, time, location and

calendar for the first time (auto –detect setting is not supported).

2. Some models require reprogramming of date, time, location and calendar each time the power is disconnected.

3. Require manual adjustment (calibration) of date and time at regular intervals to account of internal timer errors.

4. Do not provide any means of synchronization between individual devices.

Introduction

Page 6: Course Project Self-Calibrating  Prayers Clock

The objective of this project is to design a self-calibrating prayer clock based on Arduino board that overcomes the limitations of the existing models.

Project Objective

Page 7: Course Project Self-Calibrating  Prayers Clock

Specifically, the self-calibrating clock will have the following features:1. Display date, time, temperature,

prayer times and time to IQAMA.2. Auto-detect settings (i.e., location,

date, time and prayer times).3. Automatic calibration of date and

time at predefined regular intervals to account of internal timer errors.

4. Auto synchronization between individual devices at the same city.

Design Features

Page 8: Course Project Self-Calibrating  Prayers Clock

The interface of the self-calibrating prayer clock (Figure 1) consists of the following component:−6 seven-segment display digits to display the current time.−2 seven-segment display digits to display the room temperature as well

as the time to IQAMA.−4 seven-segment display digits to display the ATHAN time for FAJR

prayer.−4 seven-segment display digits to display the SUNRISE time.−4 seven-segment display digits to display the ATHAN time for DHUHR

prayer.−4 seven-segment display digits to display the ATHAN time for ASR prayer.−4 seven-segment display digits to display the ATHAN time for MAGHREB

prayer.−4 seven-segment display digits to display the ATHAN time for ISHA

prayer.−7 LEDs to display the current day of the week.

Design Interface

Page 9: Course Project Self-Calibrating  Prayers Clock

Figure 1: Prayer clock interface.

Page 10: Course Project Self-Calibrating  Prayers Clock

The required component of the complete project can be grouped as follows:1. Microcontroller board.2. Location detection system.3. Configuration and calibration system.4. Display system.

Design Component

Page 11: Course Project Self-Calibrating  Prayers Clock

The self-calibrating prayer clock will be designed based on Arduino Uno board shown in Figure 2.

Design ComponentMicrocontroller Board

Figure 2: Arduino Uno board.

Page 12: Course Project Self-Calibrating  Prayers Clock

In order to configure /calibrate the self-calibrating clock, we need a mechanism to automatically determine the location where the clock is installed.

One option is to use a GPS shield (Figure 3).

Design ComponentLocation Detection System

Figure 3: GPS shield form Sparkfun.

Page 13: Course Project Self-Calibrating  Prayers Clock

After determining the location of the self-calibrating prayer clock, it can be automatically configured/calibrated by accessing a dedicated server that will provide the clock with the required information (i.e., current date and time as well as prayer times).

In order to access the server, we need to use a WiFi shield shown in Figure 4.

Design Component Configuration/Calibration System

Figure 4: WiFi shield.

Page 14: Course Project Self-Calibrating  Prayers Clock

The display system consists of two types of digital outputs:1. Simple LEDs to indicate the current day of the week.2. Seven-segment display digits to display date, time, temperature,

ATHAN times, and time to IQAMA. The display system requires a large number of display

digits (40 seven-segment display digits). Hence, we need to use an efficient implementation of

display digits in order to minimize the required connections and simplify the display control.

One option is to use the MAX7219 based serial seven segment display module which allows you to add 8 digits of seven segment displays to your project using (Figures 5-6)

Design ComponentDisplay System

Page 15: Course Project Self-Calibrating  Prayers Clock

Figure 5: SPI 7-Seg Display.

Figure 6: Interfacing the SPI display with Arduino

Page 16: Course Project Self-Calibrating  Prayers Clock

The project consists of three main phases:1. Designing the clock interface and operation system.2. Designing a tentative clock configuration/calibration

system by reading required information from an SD card file.

3. Designing the final clock configuration/calibration system using GPS and WiFi shields.

In this semester, students will design and program the first and second phases.

The third phase will be designed and programmed by another group of students in the next semester.

Design Phases

Page 17: Course Project Self-Calibrating  Prayers Clock

The main design requirements of the first and second phases of the project are given below:1. Designing the interface of the self-calibrating clock

according.2. Interfacing and programming the temperature

sensor system. 3. Programming the tentative clock configuration and

calibration logic.4. Programming the time logic.5. Programming the ATHAN times logic.6. Programming the time to IQAMA logic.

Design Requirements (Phase I & II)

Page 18: Course Project Self-Calibrating  Prayers Clock

Design the interface of the self-calibrating clock according to Figure 1.

The MAX7219 based serial seven segment display modules can be interfaced to the Arduino board as shown in Figure 7.−The module has three control inputs: CLK, Din, and CS.−Each module requires a separate CS connection.−All modules will share the same CLK and Din

connections.−It is recommended to consecutive pins starting from pin

0 (i.e., 0, 1, 2, …, etc.) to control the CS lines of the modules.

Design Requirements (Phase I & II)Interface Design

Page 19: Course Project Self-Calibrating  Prayers Clock

Figure 7: Interfacing two modules of the MAX7219 based serial 7-segment display.

Module 0

Module 1

1 2 3 4 5 6 7 8-------------------------------------

digits

Page 20: Course Project Self-Calibrating  Prayers Clock

Programming The MAX7219 based modules is very simple:−The Maxim-Integrated company provided the necessary

codes to initialize and control these modules as shown in Figure 8 (a-e).

−The parameters that needs to be adjusted by the user are the first three global variables: maxInUse din clk

−In your program, you can use the following function to display the value 5 on the 3rd digit of the 1st module (module 0):

Design Requirements (Phase I & II)Interface Design

maxSingle(0, 3, 5);

Page 21: Course Project Self-Calibrating  Prayers Clock

// global variables for the MAX7219 modules

int maxInUse = 2; // number of MAX7219 modules to be usedint din = 2; // Arduino pin connected to Din of the MAX7219int clk = 3; // Arduino pin connected to CLK of the MAX7219

// define max7219 registersbyte max7219_reg_noop = 0x00;byte max7219_reg_digit0 = 0x01;byte max7219_reg_digit1 = 0x02;byte max7219_reg_digit2 = 0x03;byte max7219_reg_digit3 = 0x04;byte max7219_reg_digit4 = 0x05;byte max7219_reg_digit5 = 0x06;byte max7219_reg_digit6 = 0x07;byte max7219_reg_digit7 = 0x08;byte max7219_reg_decodeMode = 0x09;byte max7219_reg_intensity = 0x0a;byte max7219_reg_scanLimit = 0x0b;byte max7219_reg_shutdown = 0x0c;byte max7219_reg_displayTest = 0x0f;

Figure 8 (a): Global variables of the MAX7219 modules.

Page 22: Course Project Self-Calibrating  Prayers Clock

// sends one byte serially through Din of the MAX7219 modules void putByte(int data) {

int i = 8;int mask;while(i > 0) {

mask = 0x01 << (i - 1);digitalWrite(clk, LOW);if ( ( data & mask ) != 0 ){

digitalWrite(din, HIGH);}else{

digitalWrite(din, LOW);}VBBWait();digitalWrite(clk, HIGH);VBBWait();--i;

}}

Figure 8 (b): Function to send one byte serially to MAX7219 modules.

Page 23: Course Project Self-Calibrating  Prayers Clock

// writes to a single MAX7219 module void maxSingle(int cs, int reg, int col) {

digitalWrite(cs, LOW); putByte(reg);putByte(col); digitalWrite(cs, HIGH); VBBWait();

}

Figure 8 (c): Function code to write to a single MAX7219 module.

// writes to all MAX7219 modules in the system void maxAll (int reg, int col) {

for (int cs = 0; cs < maxInUse; cs++) {digitalWrite(cs, LOW); putByte(reg); putByte(col);digitalWrite(cs, HIGH);VBBWait();

}}

Figure 8 (d): Function code to write to all MAX7219 modules.

Page 24: Course Project Self-Calibrating  Prayers Clock

// initializes the MAX7219 modules void initMAX7219(){

VBBInit(6);maxAll(max7219_reg_scanLimit, 0x07); maxAll(max7219_reg_decodeMode, 0xFF);maxAll(max7219_reg_shutdown, 0x01);maxAll(max7219_reg_displayTest, 0x00);for (int e = 1; e <= 8; e++) {

maxAll(e, 0);}maxAll(max7219_reg_intensity, 0x0f & 0x0f);

}

Figure 8 (e): Function to initialize the MAX7219 modules.

Page 25: Course Project Self-Calibrating  Prayers Clock

Interface a temperature sensor (TMP36) to one of the analog pins of the Arduino board as done in Experiment 08.

Program the Arduino board to read the temperature sensor and display room temperature using two 7-segment display digits.

Note that the same two 7-segment display digits will be used to display the time to IQAM at each prayer time (i.e., ATHAN time).

After IQAMA, the two 7-segment display digits will be used again to display the room temperature until the next prayer time.

Design Requirements (Phase I & II)Display Room Temperature

Page 26: Course Project Self-Calibrating  Prayers Clock

Program a tentative clock configuration and calibration system by reading the required information from a file on the SD card.

An example of the file format is given in Figure 9:−Line 1: current time−Line 2: FAJR prayer time−Line 3: SUNRISE time−Line 4: DHUHR prayer time−Line 5: ASR prayer time−Line 6: MAGHREB prayer time−Line 7: ISHA prayer time−Line 8: current day index (0-6: Sunday – Friday)−Line 9: current date

Design Requirements (Phase I & II) Tentative Clock Configuration/Calibration

Page 27: Course Project Self-Calibrating  Prayers Clock

03:03:4904:3505:5712:1603:4706:3508:05107/04/2014

Figure 9: Format of the prayers data file.

Page 28: Course Project Self-Calibrating  Prayers Clock

The code required to read configuration and calibration information file is given in Figure 10 (a-e).

The self-calibrating prayer clock system needs to read the file at startup time as well as on some predefined interval (say every 24 hours).

After reading the file, the system will start running the time, ATHAN and IQAM logics (i.e., design requirements 4, 5, and 6).

The user needs only to call the calibration function, and then use the variables: time, date, day, and prayers.

Design Requirements (Phase I & II) Tentative Clock Configuration/Calibration

Page 29: Course Project Self-Calibrating  Prayers Clock

// global variables for configuration/calibration

// current time variableint [] time = {0,0,0,0,0,0};// prayer times variableint [][] prayers = {

{0,0,0,0},{0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}

};// current date variableint [] date = {0,0,0,0,0,0,0,0};// current day index variableint day;// file variableFile f;

Figure 10 (a): Global variables for configuration/calibration.

Page 30: Course Project Self-Calibrating  Prayers Clock

// initialize SD fileboolean initSDFile() {

if( !SD.begin(4)) { return false;

}f = SD.open(“prayers.txt”);if( f == null) {

return false;}return true;

}

Figure 10 (b): Function to initialize SD file.

// close SD filevoid closeSDFile() {

f.close(); }

Figure 10 (c): Function to close SD file.

Page 31: Course Project Self-Calibrating  Prayers Clock

// converts character to integerint toInt(char c) {

int number = 0;switch(c) {

case '0': number = 0; break;case '1': number = 1; break;case '2': number = 2; break;case '3': number = 3; break;case '4': number = 4; break;case '5': number = 5; break;case '6': number = 6; break;case '7': number = 7; break;case '8': number = 8; break;case '9': number = 9; break;default: number = 0;

}return number;

}

Figure 10 (d): Function to convert character to integer.

Page 32: Course Project Self-Calibrating  Prayers Clock

// reads configuration/calibration informationvoid calibrate(){

initSDFile();// read timefor (int i = 0; i < 6; i++) {

time[i] = readInt();}// read prayer timesfor (int i = 0; i < 6; i++) {

for (int j = 0; j < 4; j++) {prayers[i][j] = readInt();

}}// read dayday = readInt();// read datefor (int i = 0; i < 8; i++) {

date[i] = readInt();}closeSDFile();

}

Figure 10 (e): Function to read configuration/calibration information.

Page 33: Course Project Self-Calibrating  Prayers Clock

After calibration, the self-calibrating prayer clock system will display the time, date, temperature, and prayer times.

Then, the system will update and display the time every second.

Design Requirements (Phase I & II) Time Logic

Page 34: Course Project Self-Calibrating  Prayers Clock

After calibration, ATHAN logic will display the ATHAN time for every prayer.

When it is the ATHAN time for a particular prayer, ATHAN logic will start blinking the display of the particular prayer time (Figure 11).

At the same time, IQAMA logic will start by displaying time to IQAMA.

IQAMA logic will decrement time to IQAMA every minute and display the remaining time.

Once the time to IQAMA reaches 0, ATHAN logic will stop blinking the prayer time and IQAMA logic will display the temperature.

Design Requirements (Phase I & II) ATHAN and IQAMA Logics

Page 35: Course Project Self-Calibrating  Prayers Clock

Figure 11: ATHAN and IQAMA logics