$30
The final project will integrate a design that will have the following functions:
• A TFT panel used as a main display.
• An ambient temperature in degree C and F is displayed on the screen
• A digital clock shows the time and date
• A fan support with full function control – On/Off and speed
• An indicator of the duty cycle for the fan control
• An alarm function is available to activate a multicolor LED when the alarm set time is reached
• A remote control used to setup the actual time, the alarm time and the set temperature for a heater control (represented by the fan).
• A push-button switch used to enable the Alarm functions
The hardware schematics is provided on a separate pdf file.
Here are the descriptions of the fields:
• ‘25C/77F’ : Actual Temperature display in degree C and degree F
• ’11:11:31’ : Time display
• ‘11/20/21’ : Date display
• ‘Alarm Time’ : Time set for the Alarm
• ‘Alarm Sw’ : Switch to turn On or Off the Alarm
• ‘HTR Set Temp’ : Temperature set to control how high the heater should be running (heater being emulated by the fan – high rpm would represent high output on the heater)
• ON or OFF depending on the Alarm push-button switch to toggle the function
• ‘HTR Sw’ : Switch to turn ON or Off the Heater(Fan) (controlled by the remote control)
• ‘DC’: Actual level of Duty Cycle
• ‘RM’ : RTC Match status used for Alarm (active high)
• ‘Volt’: Actual Readout of the voltage of the light sensor
• ‘RPM’: Actual RPM of the fan
Three setup screens are available to allow changes to the system variables:
1) Time Setup Screen:
2) Alarm Setup Screen:
3) Heater Temp Setup:
A) Setup Operations
Three ‘Setup’ buttons on the remote control are used to select one of three different setup screens. From the main screen, the following three buttons will force the system to go to different setup screens:
1) ‘Ch-‘ : Time Setup Screen
2) ‘Ch’ : Alarm Setup Screen
3) ‘Ch+’: Fan Temperature Setup Screen.
Time Setup Mode:
The screen will show the first line as the time and the second line as the date. The time line has three fields hour:minute:second while the date line shows the fields month/day/year. A cursor is shown on the screen to indicate what field is active. A total of 6 fields can be updated. Two buttons are used to move from one field to another:
• ‘Prev’ is to move backward. If the cursor is at the first field, then pressing this button will move the cursor to the last field.
• ‘Next’ will move the cursor forward. If the cursor is at the last field, then it will be move to the first field.
To increase or decrease the content of each field, two buttons are used for this purpose. Button ‘+’ will do the increase while button ‘-‘ will decrease the value.
To exit this Time Setup screen without saving the new data, button ‘EQ’ will facilitate this choice.
To exit and save the new time, the button ‘Play/Pause’ is to use for this purpose.
Alarm Setup Mode:
This mode is similar to the Time Setup Mode but it only changes three time fields for the alarm function. It affects the three time registers of the alarm function of the DS3231. The same buttons of the Time Setup Mode are used in this screen.
Heater Set Temperature Mode:
This mode is used to program the temperature level that will trigger the heater to be turned on when the ambient temperature is below that level. The difference between that level temperature and the ambient temperature will be multiplied by 2 and be used as the duty cycle to control the heater’s (fan’s) speed. Any temperature above that level will force a 0 duty cycle. The set temperature cannot go lower than 50F and cannot go higher than 110F.
Since there is only one field, only the ‘-‘ and ‘+’ buttons are used to increase/decrease the temperature level. The ‘Prev’ and ‘Next’ are illegal buttons while ‘Play/Pause’ is still used to save the new data and ‘EQ’ is to exit without saving.
Standard Operations:
1) Heater Operation
When not in any of the Setup mode, the ‘Play/Pause’ button is used to switch the fan monitoring operation. .
When the heater is in the ‘OFF’ mode, the FAN_EN signal must be set to 0 to disable the FET controlling the fan and the duty cycle ‘DC’ must be set to 0. The FAN_LED is also turned off.
When the heater is toggled to ‘ON’, the ‘Heater_Set_Temp’ variable is compared against the ambient temperature. If the ambient temperature is greater than the set temperature, then the fan must be treated as in the ‘OFF’ condition; both the FAN_EN and the FAN_LED must be turned off.
If lower, take the difference between those two temperatures and multiply it by 2 and use it as the duty cycle. Apply that duty cycle to the fan. Measure the RPM of the fan and show it on the display. FAN_EN and FAN_LED must be turned on to activate the fan. If the difference is greater than 50, make the duty cycle to be 100.
2) Alarm Operation
The Alarm can be enabled or disabled by the Alarm Mode push-button switch. The status of the Alarm operation can be seen under the ‘Alarm SW’ with the display of either ‘OFF’ or ‘ON’. When enabled, the time set under the ‘Alarm Time’ will be programmed into the DS3231 chip and the Alarm interrupt operation must be enabled in the DS3231 so that the signal ‘RTC_ALARM#’ will be set to the logic 0 when the alarm time matches with the actual time. When that event happens, the buzzer will be activated and the RGB LED will change to a different color every second from No color, RED, GREEN, YELLOW, BLUE, PURPLE, CYAN and WHITE. The value under ‘RM’ should show the value of 1 when the time matches. The buzzer and the RGB LED will stay active until the Alarm is turned off or when the light sensor is blocked momentary in order to clear the match. This later event will not disable the Alarm.
Guidance:
1) A base sample of the code is provided to the student to allow shorter development time for the project.
Here is the list of files in the sample code:
Main.c : this is where the main program resides
o Main_Screen.c : this is the file that will generate the main screen on the LCD o Setup_Time.c : this is where all the functions to support the setup of the time o Setup_Alarm_Time.c : all the functions to support the setup of the alarm time are handled in this file
o Setup_Heater_Temp.c : the functions to allow the setup of the temperature for the heater are in this file
o Interrupt.c : this is where the interrupt handler and the code for the IR remote control function
o I2C.c : this is the original library file for the basic functions to handle the I2C protocol. o I2C_Support.c : this is all the functions needed to interface to the DS1621 and DS3231 ICs
o Fan_Support.c : all the functions to support the fan operations should be included in this file
o ST7735_TFT.c : this is the original library file to support the LCD o Utils.c : utility functions are included in this files
2) The file ‘Main.h’ contains all the assignments for the pin signals. Modify them based on the schematics before testing the board.
3) The ‘Setup_Time.c’ is provided as a startup example to modify the time. The routine will start to read the actual time and uses it to setup the startup screen. It will then stay in a while loop to receive incoming buttons from the remote. Based on the inputs, it will call appropriate functions to execute the commands. More detail information will be discussed on the lecture on the implementation.
4) The other two files ‘Setup_Alarm_Time.c’ and ‘Setup_Heater_Temp.c’ are as their names indicate to change the time for the alarm and the set temperature for the heater function.
5) The main routine has the following tasks in its ‘while (1)’ loop:
a. Check for the time change on every second. When that happens, it will:
i. Measure the fan’s rpm
ii. Measure the ambient temperature
iii. Measure the voltage of the light sensor
iv. Call the function Monitor_Heater() where :
1. The duty cycle is always calculated based on the following conditions:
a. If the set fan temp is lower than the ambient temperature, then the duty cycle is 0.
b. If it is higher or equal, then the duty cycle is 2 times the difference between the two temperatures
2. The variable FAN is checked. If 0, then turn off the fan. Else, turn on the fan
v. Check if the Clock Alarm function by calling the function
‘Test_Alarm()’ (see below) vi. Output the information on TeraTerm
vii. Update the information on the LCD screen
b. Check the INT1_flag or INT2_flag (depending where the push-button is connected) is set to detect that the Alarm_Enable/Disable push-button switch is pressed
c. Check if a button is received. If that happens, it will:
i. Check if button is valid. If not, generate a bad beep tone. If yes, then generate good beep tone and process the button. Here are the allowed buttons:
1. ‘Ch-’ for Setup_Time()
2. ‘Ch’ for Setup_Alarm_Time()
3. ‘Ch+’ for Setup_Fan_Temperature()
4. ‘Play/Pause’ for Toggle_Fan_Monitor()
6) The Clock Alarm allows the user to set a desired time for the alarm to sound and to generate a continuous light changing sequence on a RGB LED. When the Alarm switch is activated (by pushing on INT1/INT2 on the main page), the unit will program the RTC chip to compare between the actual time and the alarm time. When the time matches, the signal RTC_ALARM# will be set to 0. The buzzer will be activated and a RGB LED will be changing its color every second. To reset the alarm, either the ALARM SW is toggled or the light to the photo sensor is blocked off.
The routine ‘Test_Alarm()’ in main.c program is the place to implement this function. Follow the basic steps provided in that routine.
1) The Alarm mode can be toggled by pushing on the INT1/INT2 push-button. When INT1/INT2 is detected to be 1, it indicates that the push-button has been pressed. This will change the logic state of a variable ALARMEN (initially at logic 0).
2) Need to have a variable called alarm_mode to retain the actual state of the alarm operation.
3) We will have to handle the following situations:
a. alarm_mode is 0 and ALARMEN = 1. This means that no alarm operation was on and now it is activated. Need to call
DS3231_Turn_On_Alarm(); to do the activation and set alarm_mode to 1
b. alarm_mode is 1 and ALARMEN = 0. This forces the alarm mode to be disabled. Need to call DS3231_Turn_Off_Alarm(); to turn off the alarm. Next, set alarm_mode to 0, clear out any RGB LED and deactivate the buzzer
c. alarm_mode is 1 and ALARMEN = 1. This is when the program is waiting for the alarm time to match with the actual time. The signal ‘RTC_ALARM_NOT’ must be checked to be at logic 0 to indicate that the time matches. When that happens, activate the buzzer and start the RGB LED to show the event. To keep the buzzer going and the RBG LED changing the color for every second, use a variable ‘MATCHED’ to show that the matching event did happen. This will continue until the voltage sampled from the light sensor is detected to be above 3.0V because that is when the photo sensor is blocked. At that time, ‘MATCHED’ will be cleared and the buzzer will be deactivated as well as the RGB LED will be turned off.