350 likes | 515 Views
Course Project Self-Calibrating Prayers Clock. Khaled A. Al- Utaibi alutaibi@uoh.edu.sa. Agenda. Microprocessors Microcontrollers Embedded Systems. Introduction.
E N D
Course ProjectSelf-Calibrating Prayers Clock Khaled A. Al-Utaibi alutaibi@uoh.edu.sa
Agenda • Microprocessors • Microcontrollers • Embedded Systems
Introduction • 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: • Current time and date. • Room temperature. • ATHAN times for the five prayers. • Time to the IQAMA.
Introduction • The existing prayer clocks have the following features: • Preprogrammed prayer times for large set of cities around the world. • Ability to program prayer times for other cities by entering latitude and longitude coordinates. • Ability to program prayer times according to different Islamic calendars such as Umm Alqura, International Islamic University and University of Islamic Sciences. • Ability to alarm prayer time using sound alarm or by flashing the prayer time display.
Introduction • The existing prayer clocks have the following limitations: • Require programming of date, time, location and calendar for the first time (auto –detect setting is not supported). • Some models require reprogramming of date, time, location and calendar each time the power is disconnected. • Require manual adjustment (calibration) of date and time at regular intervals to account of internal timer errors. • Do not provide any means of synchronization between individual devices.
Project Objective • 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.
Design Features • Specifically, the self-calibrating clock will have the following features: • Display date, time, temperature, prayer times and time to IQAMA. • Auto-detect settings (i.e., location, date, time and prayer times). • Automatic calibration of date and time at predefined regular intervals to account of internal timer errors. • Auto synchronization between individual devices at the same city.
Design Interface • 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 Component • The required component of the complete project can be grouped as follows: • Microcontroller board. • Location detection system. • Configuration and calibration system. • Display system.
Design ComponentMicrocontroller Board • The self-calibrating prayer clock will be designed based on Arduino Uno board shown in Figure 2. Figure 2: Arduino Uno board.
Design ComponentLocation Detection System • 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). Figure 3: GPS shield form Sparkfun.
Design Component Configuration/Calibration System • 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. Figure 4: WiFi shield.
Design ComponentDisplay System • The display system consists of two types of digital outputs: • Simple LEDs to indicate the current day of the week. • 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)
Figure 5: SPI 7-Seg Display. Figure 6: Interfacing the SPI display with Arduino
Design Phases • The project consists of three main phases: • Designing the clock interface and operation system. • Designing a tentative clock configuration/calibration system by reading required information from an SD card file. • 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 Requirements (Phase I & II) • The main design requirements of the first and second phases of the project are given below: • Designing the interface of the self-calibrating clock according. • Interfacing and programming the temperature sensor system. • Programming the tentative clock configuration and calibration logic. • Programming the time logic. • Programming the ATHAN times logic. • Programming the time to IQAMA logic.
Design Requirements (Phase I & II)Interface Design • 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.
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
Design Requirements (Phase I & II)Interface Design • 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): maxSingle(0, 3, 5);
Figure 8 (a): Global variables of the MAX7219 modules. // global variables for the MAX7219 modules intmaxInUse = 2; // number of MAX7219 modules to be used int din = 2; // Arduino pin connected to Din of the MAX7219 intclk = 3; // Arduino pin connected to CLK of the MAX7219 // define max7219 registers byte 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 (b): Function to send one byte serially to MAX7219 modules. // sends one byte serially through Din of the MAX7219 modules voidputByte(int data) { inti = 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 (c): Function code to write to a single MAX7219 module. // writes to a single MAX7219 module voidmaxSingle(intcs, intreg, intcol) { digitalWrite(cs, LOW); putByte(reg); putByte(col); digitalWrite(cs, HIGH); VBBWait(); } Figure 8 (d): Function code to write to all MAX7219 modules. // writes to all MAX7219 modules in the system voidmaxAll (intreg, intcol) { for (intcs = 0; cs < maxInUse; cs++) { digitalWrite(cs, LOW); putByte(reg); putByte(col); digitalWrite(cs, HIGH); VBBWait(); } }
Figure 8 (e): Function to initialize the MAX7219 modules. // 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); }
Design Requirements (Phase I & II)Display Room Temperature • 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) Tentative Clock Configuration/Calibration • 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
Figure 9: Format of the prayers data file. 03:03:49 04:35 05:57 12:16 03:47 06:35 08:05 1 07/04/2014
Design Requirements (Phase I & II) Tentative Clock Configuration/Calibration • 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.
Figure 10 (a): Global variables for configuration/calibration. // global variables for configuration/calibration // current time variable int [] time = {0,0,0,0,0,0}; // prayer times variable int [][] 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 variable int [] date = {0,0,0,0,0,0,0,0}; // current day index variable int day; // file variable File f;
Figure 10 (b): Function to initialize SD file. // initialize SD file booleaninitSDFile() { if( !SD.begin(4)) { returnfalse; } f = SD.open(“prayers.txt”); if( f == null) { returnfalse; } returntrue; } Figure 10 (c): Function to close SD file. // close SD file voidcloseSDFile() { f.close(); }
Figure 10 (d): Function to convert character to integer. // converts character to integer inttoInt(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 (e): Function to read configuration/calibration information. // reads configuration/calibration information void calibrate(){ initSDFile(); // read time for (inti = 0; i < 6; i++) { time[i] = readInt(); } // read prayer times for (inti = 0; i < 6; i++) { for (int j = 0; j < 4; j++) { prayers[i][j] = readInt(); } } // read day day = readInt(); // read date for (inti = 0; i < 8; i++) { date[i] = readInt(); } closeSDFile(); }
Design Requirements (Phase I & II) Time Logic • 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) ATHAN and IQAMA Logics • 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.