1 2 Previous Next 23 Replies Latest reply on Oct 4, 2015 11:26 AM by user_242978793

    Alarm RTC Logic

    user_444739275

      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

        • 1. Re: Alarm RTC Logic
          user_242978793

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

          • 2. Re: Alarm RTC Logic
            user_242978793

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

            • 3. Re: Alarm RTC Logic
              user_444739275

              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 

              • 4. Re: Alarm RTC Logic
                user_444739275

                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. 

                • 5. Re: Alarm RTC Logic
                  user_242978793

                  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.

                  • 6. Re: Alarm RTC Logic
                    user_444739275

                    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

                    • 7. Re: Alarm RTC Logic
                      user_444739275

                      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
                      }

                         

                      }

                      • 8. Re: Alarm RTC Logic
                        user_242978793

                        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. 

                        • 9. Re: Alarm RTC Logic
                          user_444739275

                          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 ?

                          • 10. Re: Alarm RTC Logic
                            user_242978793

                            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. 

                            • 11. Re: Alarm RTC Logic
                              user_242978793

                              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. 

                              • 12. Re: Alarm RTC Logic
                                user_444739275

                                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 ?

                                • 13. Re: Alarm RTC Logic
                                  user_242978793

                                  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.

                                  • 14. Re: Alarm RTC Logic
                                    user_242978793

                                    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?

                                    1 2 Previous Next