how to execute two alarms in different flags

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

   

Define current time and date
Define first alarm time and date
Define second alarm time and date
Define alarm flag1
Define alarm flag2

   

        If alarmFlag1 is set   alarmFlag1 = 1u;

   

      and  If first alarm time ,date match with current time,date  

   

            Then perform following task    

   

              Alarm_LED_Write(1);

   

       CyDelay (100);

   

       alarmFlag1  = 0u;

   

      Alarm_LED_Write(0);

   

 

   

    alarmFlag2 = 1u;

   

      If second  alarm time ,date match with current time,date  

   

            Then perform following task    

   

   Alarm_LED_Write(1);

   

       CyDelay (5000);

   

       alarmFlag2  = 0u;

   

      Alarm_LED_Write(0);

   

how to execute two alarm in different flags ?

0 Likes
16 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

As I understand RTC there is only one alarm at a time. So you will have to install the next alarm in sequence when the first has finished.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

that's the problem,I did cypress forum search but not getting much information  I don't understand  how to  set next alarm ? 

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Set the next alarm just like you did setting the first. Set it  when the first Alarm finished.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

I am not getting starting point , I don't understand what should be after ALarmISRHandler function

   

1. where to define next Alarm time and date , before or after the ALarmISRHandler function ?

   

2. where to declare  Alarm structure, before or after the ALarmISRHandler function ?

   

3.I Think I don't need to start    LCD , RTC after the ALarmISRHandler function, because the already ON ?

   

4. I think I have to set mask again after ALarmISRHandler function

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

1. where to define next Alarm time and date , before or after the ALarmISRHandler function ?

   

 

   

Set a flag in ISR that indicates a new alarm is needed, service outside ISR, setup the

   

new alarm, and reset the flag.

   

 

   

2. where to declare  Alarm structure, before or after the ALarmISRHandler function ?

   

 

   

Describe it in main() as a basic part of startup for the system.

   

 

   

3.I Think I don't need to start    LCD , RTC after the ALarmISRHandler function, because the already ON ?

   

 

   

Correct.

   

 

   

4. I think I have to set mask again after ALarmISRHandler function

   

 

   

If the alarm properties change yes, like next alarm on just year vs prior alarm on year, month, hours.....

   

 

   

Regards, Dana.

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

can you please check the project ,what's wrong why second alarm does not work ?

0 Likes
lock attach
Attachments are accessible only for community members.
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

See attached. I think you should do a flow chart to confirm logic is what you

   

want.

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

when I put following code I am getting some error

   

volatile uint8 Alarm1flag = Alarm1serviced = Alarm2flag =Alarm2serviced = 0;

   

/* Interrupt prototypes */
CY_ISR_PROTO(AlarmIsrHandler);

   

CY_ISR (AlarmIsrHandler);

   

 {
     If ( ( Alarm1flag == 0 ) && (Alarm2flag == 0 ) ) {               // Only set Alarm1flag if both it and Alarm2flag clear

   

              Alarm1flag == 1;
             return;
     }

   

     If ( ( Alarm1flag == 1 ) && (Alarm2flag == 0 ) ) {             // Only set Alarm2flag if Alarm1flag has been set

   

              Alarm2flag == 1;
             return;
     }
}

   

int main()
{

   

 

   

line 63  volatile uint8 Alarm1flag = Alarm1serviced = Alarm2flag =Alarm2serviced = 0;

   

error  undeclared  Alarm1serviced

   

error   undeclared Alarm2flag

   

error  undeclared Alarm2serviced

   

line 74 {

   

error expected identifier '('

   

 

   

how to remove errors

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

Vead I am reporting to you that after 1 week the sys tick of the PSOC 4 without a crystal has lost about 5 minutes.  Also I thought I told you that it is not a good ideal to use Port 2 of the PSOC 4 for digital signals as these pins are for Analog functions.  I have moved the LCD to Port 0. Also for testing purposes you should have the time and date set to current time.  Everytime I get one of your programs it is set to 3/22/2016.  Why are you setting the date and year in 2016? The Alarm will trigger but you should be setting it to current time just to make it easier to debug.

0 Likes
Anonymous
Not applicable

Hello bobgoar

   

 I was waiting for your reply  I just wanted to see result. yes you told me  Port 2 of the PSOC 4 for digital signals as these pins are for Analog functions.

   

Why are you setting the date and year in 2016?

   

that was just example. next Time I will set correct time and date 

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Not sure why this is not working, declare each one on a separate line.

   

 

   

line 63  volatile uint8 Alarm1flag = Alarm1serviced = Alarm2flag = Alarm2serviced = 0;

   

 

   

Note my code is for you to work around, to check by drawing a flow chart that the

   

logic is right. It was just for example.

   

 

   

Regards, Dana.

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

VEAD: I am working on your new file. Your time is still running at high speed.  Also you should leave the UART in the program it makes it easier to debug and also you do not need the LCD.  So I have installed the UART and have changed the ALARM_LED drive and that is working however the Alarm is working but only on the first alarm. I'll be checking the code to see what needs to be done.  The issue with this program is in the while loop.  The program is in that loop at all times and does not return to the main section at all.  That means the Alarm ISR handler needs to be set in the AlarmISrHandler and the new alarm time needs to be set in that function also.  The current program compiles.  I do not know what you did to the program to make it run so fast. 

0 Likes
Anonymous
Not applicable

Hello Mr. Bobgoar

   

thank you for helping me , thank you very much bobgoar and dana  for your time

   

actually I want to set the many alarm for device. when alarm is happen the device should be On and when alarm is off device should be OFF

   

I looked Project example in Psoc creator , Then I tried to modified , also I don't know why my clock is running very fast. also I am trying to find out reason , but first I am trying to execute second alarm

   

I am using LCD to see the current time and date. so that some one can know, on which time and date, alarm is happening , that's why I am using LCD , 

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

Hello Mr. Dana

   

I saw your attachment . please look Project workspace. my code is incomplete but I tried to make sequence. what I need to do ?

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

Vead : I have fixed the fast time issue and I am now ready to try to fix the multi-alarms.

0 Likes
Anonymous
Not applicable

that's very good news Mr. bobgoar.  can you please  tell me what was wrong with my code 

0 Likes