Alarm RTC Logic

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hello Mr. Dana

   

I need some information about the document that you posted in my previous post ''  set many alarm using psoc RTC ''

   

what should be inside  int Main function ( ) ? also please check the sequence that I am describing in below code

   

my answer :

   

int main( )
{

   

Q1. can we initializ two alarm here ?   /* Alarm1 and Alarm2 structure initialization */

   

RTC_Start();     /* Starts RTC component */

   

 LCD_Start();    /* Starts LCD  */

   

 RTC_SetDateAndTime(TIME_HR_MIN_SEC,DATE_MONTH_DAY_YEAR);    /* Set Date and Time */

   

    /* Set alarm mask */
    RTC_SetAlarmMask(RTC_ALARM_SEC_MASK   | RTC_ALARM_MIN_MASK        |
                       RTC_ALARM_HOUR_MASK  | RTC_ALARM_DAYOFMONTH_MASK |
                       RTC_ALARM_MONTH_MASK | RTC_ALARM_YEAR_MASK);

   

Q.2 now I have two different alarm times and dates

   

my answer : 

   

set time and date

   

set mask

   

set alarm1 time and date

   

set  mask

   

set alarm2 time and date

   

 

   

Q3.  where to place following line ?

   

if (  ( Alarmflag1 == 1 ) && ( Alarm1serviced == 0 ) &&  ( Alarmflag2 == 0 ) ) {     // Only service if conditions met

   

    service alarm1

   

    Alarm1serviced = 1;

   

}

   

 

   

if (  ( Alarmflag2 == 1 ) && ( Alarm2serviced == 0 )  && ( Alarm1serviced == 1 ){

   

    service alarm2

   

   Alarm1flag =Alarm1serviced = Alarm2flag =Alarm2serviced = 0;     // Reset all flags

   

}

   

 

   

}

   

}

   

end main function

0 Likes
23 Replies
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

I have a program running with 4 alarms. I am working on a few clean up issues today.

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Vead: Are you going to use Sleep mode to save battery power?

0 Likes
Anonymous
Not applicable

Hello Mr. bobgoar

   

Yes I want to use sleep mode

   

can you upload your work so that I can get idea that  how are you making program. also I will try to fix the issues 

0 Likes
Anonymous
Not applicable

Hello Mr. bobgoar

   

have you fixed that problem  ?  If you are watching my post , please reply, If your work is incomplete its ok.  at least tell me the way so that I can try  as you are doing. 

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

I am studying the Sleep mode.  I don't think the code we are using will run correctly in the sleep mode.  I have downloaded a group of programs that allow the end user to analyze the different types of sleep modes. I plan to use one of these programs to see if our code would run on it. Also I have 4 alarms working one using the RTC component and the rest using a string compare for the time and date vrs the returned information from the RTC component. They all work well. I also had two using the Alarm ISR handler.  I consider this very hard to make work but if you need sleep we may need ot use it.

0 Likes
Anonymous
Not applicable

Hello Mr. bobgoar

   

Can you please upload the code that you tested without Sleep mode. If you upload your work , so that I can check result on the board  ,my clock was running very fast. I want to see that how did you fix the clock problem. In my work , LCD connected to port P2 , its working , I can see the data on LCD. so why I need to change port,  also I want to see how does your alarm execute one by one

   

please reply, Can you please upload your code that you tested without Sleep mode. I just want to see that how dose your program work practically ?

   

thank you very much

   

vead

0 Likes
Anonymous
Not applicable

somebody please help me ,

   

Still I don’t understand what should be inside int main function including while loop ?

   


int main ()
{
Start RTC
Start LCD
Set current time and date
Call Alarm handler
 
while(1) {
if (Alarm1serviced = 0)
 
Get RTC time and date
Set mask
Set Alarm1 Time and date
Set Alarm flag1
Turn on LED
Wait 50 ms second
Turn of LED
Clear Alarm flag1
 
}
{
if (Alarm2serviced = 0)
 
Get RTC time and date
Set mask
Set Alarm2 Time and date
Set Alarm flag2
Turn on LED
Wait 50 ms second
Turn of LED
Clear Alarm flag2
}

   

}

0 Likes
lock attach
Attachments are accessible only for community members.
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Vead Since you don't want the low power design at this time. I am sending you the program. I have commented the area of the second alarm code because I feel that using the API of the RTC for multi alarms  is too complicated for what you get.  My design uses less code and runs faster.  The LCD has been moved to port 0 per Cypress design Specification. Have you added Headers to your CY8CKIT-049-42XX board by doing this it makes your design debug quick and changes very easy.  I am sending you a picture of a Solderless breadboad so you can see how easy this makes the designs. I am also including the board layout design specs for the PSOC 4 devices for your review. I also have the UART added to the design for an on screen display. You can read this by downloading a program called PUTTY.exe and setting it up to read the Uart signal.  This is necessary with the CY8CKIT-049-42XX boards as you have no way to debug this board except using the Uart or the Cypress Mini Prog device. When you are done with the Debugging of the design you can disable the Uart. This program is your RTC_Alarm.bundle01 program modified to keep correct time and has 4 alarms you could add as many as you like however.  By the way I tried to use this code Alarm_LED_Write((uint8)~(Alarm_LED_Read()));  to toggle the LED but for some reason after about 3 alarms the pin stuck in the high position leaving the led on.  So I went back to the original code. 

0 Likes
Anonymous
Not applicable

Hello Mr. bobgoar

   

first Thank you very much  for your  time and response  

   

I have  Headers to my board.  also I have breadbord , psoc 4200 board , LCD.

   

I don't understand  what do you mean by original code , you mean, your code including uart component. I think you tried  code with and without uart component. If you use code without uart , 4 alarm does not work. and if you add the uart then the many alarms are working , Am I right ?

   

If I add the uart component in design than I have to download PUTTY.exe  so we can read the uart signal on LCD /computer.  ok I download PUTTY.exe,  and I try as you told me. Are you sure that psoc RTC work with multiple alarm ?

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Vead:  I meant that I used your original Program and modified it.  No you do not need the Uart for the alarms to work. The Board will run fine with out the Uart being hooked up. I had the RTC API alarms working for two alarms  but I commented that code with the // marks to remove the 2nd one.   I only had Two alarms working using the RTC API.  I switched to the other alarms using strcmp commands in C code because I feel making the RTC Multi alarms using the API  is way to much code and unnecessary for what we are doing here. I am using one Alarm using the RTC API that is the first one.  I hope you have not change the times of the alarms to some date in 2016 as you will have to wait till 2016 for the alarms to be displayed on the LED.  I have checked this program for quite a few days and it works every time. 

0 Likes
Anonymous
Not applicable

Do you mean I can use my original Program. I just need to  modified it. as you did for  two alarms. I have to remove uart code. we can set mutli alarm with and  without uart ?

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Vead : If you want to change the alarm time you must do it in the result = strcmp("10:08:00",timeBuffer) ; and date for the alarm in result1 = strcmp("09/28/2015",dateBuffer); for each of these code areas.  The RTC alarm is set in the original place at the top of the program.  The alarms are set for 10:05:00 and 10:07:00 and 10:08:00 and 10:12:00 on 09/28/2015. 

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Vead right now my clock reads 03:45:00 and 10/02/2015 So all my alarms have expired. I didn't set the time to the exact time but the date was correct.  Now I am going to unplug the board and that will reboot the program back to the original date and time of 10:00:00 and date of 9/28/2015  and the alarm will start in 5 minutes from now.

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Vead Well the alarm is now on and it has been 5 minutes since I reconnected the power.  Then the next  alarm will start at 7 minutes after the unit was plugged in it did and at 8 minutes and 12 minutes.   The program works fine on this end.  What wrong on your end?

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable
        I just saw your program and tried to make new project using PSoCCreatorSetup_3.2_es10-4_4-2-15. I just modified old program. but there is only one Alarm ON , I don't know why All alarms are not happening please look workspace and tell me what's wrong with program   
0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Vead Why do you want to remove the UART part at this time? It is a great way to troubleshoot the program. It has no bearing on the alarm function so it will work with out it   No I would not modify any of the programs you have been using as they all run at high speed.  You should use this program as a baseline as it is working well.  To remove the Uart part just go to the topdesign.cysch  and right click on the Uart icon and select disable on the drop down list.  Then comment all the UART code in the program do not comment the result1 = strcmp("10:07:00) ect. Also as far as it goes you can leave the UART in the program and you will never notice it.  I was stating you could remove it if you started to run out of resources.
 

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Vead Also you can only set the alarms and time and date in the program not with a keyboard or another way.  That is a whole other issue.

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

I can't open your project because I have PSoCCreatorSetup_3.2_es10-4_4-2-15. you are using PSoC Creator  3.2 SP1 (3.2.0.6175)

   

I can only see the program , I try to download your version but I did not find , I am downloading psoc creator 3.3 , may be it can open project

   

yes you are right ,your design  uses less code,  using the API of the RTC for multi alarms  is too complicated

   

I try to make new project using PSoCCreatorSetup_3.2_es10-4_4-2-15. I just modified old program but its not working , there is only one alarm happen , I don't know why All alarms are  not working

   

please look project workspace , whats wrong with program

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Vead Always run the latest PSOC Creator program they fix issues with each release.  Yes this program will only work in PSOC Creator 3.3. It can be run in 3.2 but you have to do a lot of work.  I always update to the latest program every time Cypress announces a new release.  One of the reasons I had to update was my computer was having issues with PSOC 3.2 stopping and I would have to reboot.  I was running XP Service pack 3 but felt that it was time to update the computer to Windows 8 when I did this I installed 3.2. I'll look at your program and see what is going on. 

0 Likes
lock attach
Attachments are accessible only for community members.
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Vead I found the following errors in the program.

   

  1) Both the RTC alarm and the New alarm method set for the same time.  I changed the RTC alarm to 10:05:00.

   

  2 ) The manual update box  was not set in the RTC configure screen.

   

  3) The CY8Ckit -049-42XX can not be debugged by normal PSOC Creator methods and was giving an error of Flash locked for first 100 blocks.  I made this change in the .CYDWR screen.  I changed to the System tab and set the debug to GPIO from Serial debug this fixes the warning in the notice list.  Sometimes you may need to adjust the Heap and Stack here for more resources.

   

 4) Dana told you on Sept 14 at 10:27 am that you should remove long CyDelays to save CPU cycles and reduce power.  However when you are working with real world devices you may need to delay the operation of the program to give the real world devices time to respond.  I removed your comments on the CyDelay(200); This loop was very fast and it didn't allow the LCD and the UART to respond.

   

5) These changes fixed the program and it is working fine. 

   

6) Did you Read App note AN57821 that I sent you Oct 2. If you look at Section 7.2 PSOC 4 and Figure 16 you will see that port two is for analog devices and I know your lcd works on this port but what if you want to add an analog signal of use the ADC devices.  Please move the LCD to Port 0 the correct Port and you will not have issue in the future when you need to add analog devices,

   

7) I am moving the LCD back to the correct port.

   

😎 Here is the program with the changes and it is working.  By the way I left the Uart in it for debugging purposes.

   

BobGoar

0 Likes
Anonymous
Not applicable

I have downloaded psoc creator 3.3.  finally All alarms are working fine. I have commented the  part of uart , All alarms are working on right time Now I am trying to debug your program (including uart code ) but I don't have Miniprog kit 

   

1. Should I need Miniprog kit to debug your program ?

   

2. where does  we need to use MiniProg ?

   

3. where to connect pin P4[1]   /uart: tx/ ?

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Vead : MiniProg3 CY8CKIT002 cost about $89.00 US dollars  from Cypress store  and if you want to use it  to debug you need a 5 pin right angle Molex connector attached to the lower left side of the board where is SWIO and SWDCLK and RESET and GND  and VDD  pins are located. You don't need to connect anything to P4[1] as it is already connected to the USB Serial port on the top of the board. I  don't think it is worth paying this much to debug a $4.00 board.  What you do is print the debug variable data out using Sprintf() to the Serial UART to the terminal program such as PUTTY or some other terminal program  and then you can check your Variables that way. I am glad the program is working for you.  You might want to upgrade to the PSoC 4 M-Series Prototyping Kit CY8CKIT-043 this board cost $10.00 and has the programmer and debug built-in and it also has pads for the PSOC ble module to make you design wireless with Bluetooth. Or go for the full CY8CKIT-044 PSOC 4 M Pioneer kit with a clock crystal and other sensors already on the board.

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Vead: One thing I forgot to mention is that in order to determine what com port you need to open. Open the device manager in windows and go to Ports com and LPT and open that an you will see your com devices then unplug the PSOC 4 Prototyping kit and it will disappear in the window and then plug it in it will reappear.  That is your com port for the Prototyping kit.  Then you go to putty and  from the configuration screen click on serial in the list on the left of the window.  When that window opens it should say options controlling local serial lines.  In The box serial line to connect to enter the com port number like this COM3 or whatever port it is. 
Next enter the speed (baud) box  9600 in the data bites enter 8 in the stop bits enter 1 in the parity box select none from the pull down menu. in the Flow control box enter XON/XOFF.  Now in the left menu box click on Session and that will return you to the main screen.  Then click on the serial button in connection type and your configured COM port will appear in Serial line box and the Speed will read 9600. Then click on the Saved Sessions box and enter the name of you configuration. You can use any name you want.  Then press the Save button and it will be saved for you.  Then click on the open box at the bottom of the box next to the cancel button and the Putty screen will appear with your clock information being displayed.

0 Likes