CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Alarm

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








Alarm
PostPosted: Fri Apr 29, 2005 8:34 am     Reply with quote

Hello,

i use a PIC18LF458 and a DS1306 RTC.

i wondered if someone could help me to understand the alarms on DS RTC, like DS1302 or DS1306.

What i want to do is to put a buzzer on (on the pic) when for example a door sensor (on the PIC as well) is true for 30 seconds.

Before it does nothing, after 30 seconds it puts the alarm on.

How can i count with this alarm using the interrupts pins of the DS ?

Thanks a lot.
global



Joined: 01 Feb 2005
Posts: 21
Location: Paris

View user's profile Send private message

PostPosted: Fri Apr 29, 2005 9:14 am     Reply with quote

Sorry !

I was not logged on ! Maybe i was disconnected !

Yes it is me =)

I need to have an interrupt on my PIC when the RTC matches with the alarm.
When the SENSOR_PIN is 1, i read the time and then add 1 minute to set the alarm one minute later. When the alarm is on interrupt on the PIC, is switch on all the leds.

One minute later, the DS1306 sends an interruption on the PIC.
What is wrong ? My problem is to use if (!input(SENSOR_PIN)), to check if it is on during this one minute ... and to set the alarm once when SENSOR_PIN is 1.

Here is my code :

Code:

#INT_EXT
ext_isr()
   {
   output_high(LED_1);
   output_high(LED_2);
   output_high(LED_3);
   output_high(LED_4);
   output_high(LED_5);
   output_high(LED_6);
   output_high(LED_7);
   output_high(LED_8);
   }

void main(void)
   {

    while(1)
         {
         
         if (!input(SENSOR_PIN))
            {
            rtc_get_time(heure, min, sec); // get the time

            // initialize the alarm 1 minute later
            write_ds1306(0x8F,0x01);         // control register
            write_ds1306(0x89,heure);        // hour
            write_ds1306(0x88,min + 0x01);   // minute + 1 minute
            write_ds1306(0x87,sec);          // second
            write_ds1306(0x8A,0x80);         // day

            enable_interrupts(global);
            enable_interrupts(int_ext);
            ext_int_edge(L_TO_H);
            disable_interrupts(global);
            disable_interrupts(int_ext);
            }


Thanks for your help.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon May 02, 2005 10:03 am     Reply with quote

How did you define SENSOR_PIN?
Beware that you can't use a variable as parameter to the input() function.

A few more remarks:
1) I guess a sleep() call is missing after you enabled the interrupts?
2) You'll have to add a check for the minute count to be 59, or your code will fail. Also keep in mind the 23:59 hour situation, last day of the month and last day of the year....
global



Joined: 01 Feb 2005
Posts: 21
Location: Paris

View user's profile Send private message

PostPosted: Tue May 03, 2005 8:36 am     Reply with quote

Hello ! You are right, i'll have to check that.

I am looking for some code that will check time : If seconds, minutes and hours are over 59.

For example if i want to add 30 seconds when it is 23:59:59 ?

Does someones have any code for that ?

I don't mind of the day and date.

Thank you.
global



Joined: 01 Feb 2005
Posts: 21
Location: Paris

View user's profile Send private message

PostPosted: Fri May 06, 2005 2:03 am     Reply with quote

Hello,

I did this which seems to work :

Code:
min = min + 1;

               if(min > 59)
                  {
                  min = min - 60;
                  if (heure == 24) heure = 0;
                  else heure = heure + 1;
                  }

Is that ok ? Do you think i forget something ?


Last edited by global on Mon May 09, 2005 7:10 am; edited 1 time in total
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun May 08, 2005 11:46 am     Reply with quote

For another example you can check this thread: http://www.ccsinfo.com/forum/viewtopic.php?p=39216#39216
global



Joined: 01 Feb 2005
Posts: 21
Location: Paris

View user's profile Send private message

PostPosted: Wed Oct 19, 2005 6:21 am     Reply with quote

Hello,

i need to use the DS1306 again, and i thought i found the way to make it work but it seems that the interrupt generated by the DS1306 is not seen by the PIC. I am sure that it is generated because the alamr is well configured and the registers are correct when it is generated.

I checked if it was a hardware problem but nothing ...

I checked the register that shows if the alarm works on the DS1306, it is fine.
the trouble is i can't make it work properly with the #INT_EXT interruption.

What do you mean for this suggestion :

Quote:
1) I guess a sleep() call is missing after you enabled the interrupts?


I wrote it this way :

Code:
   enable_interrupts(INT_RTCC);
   enable_interrupts(INT_TIMER1);
   //enable_interrupts(INT_TIMER2);
   //enable_interrupts(INT_TIMER3);

   enable_interrupts(GLOBAL);
   enable_interrupts(INT_EXT); // interruptions alarme
        ext_int_edge(L_TO_H);


and the interrupt is just like this, for the moment :

Code:
#INT_EXT
ext_isr()
   {
        output_high(LED_RED);
        }

Any suggestion ?

Many thanks.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 19, 2005 1:24 pm     Reply with quote

Quote:
it seems that the interrupt generated by the DS1306 is not seen by the PIC
I checked if it was a hardware problem but nothing ...

You didn't say what interrupt pin you're using on the DS1306.
The \INT0 pin on the DS1306 is open-drain and requires a pull-up
resistor. Also, it's active low.
global



Joined: 01 Feb 2005
Posts: 21
Location: Paris

View user's profile Send private message

PostPosted: Thu Oct 20, 2005 7:52 am     Reply with quote

Hello,

many thanks, you are correct but i already added the pull-up :p

It is the INT0.

I putted ext_int_edge(H_TO_L);

I think it was a hardware problem, i just soldered the PIC pin on B0 and it works !

Thanks again.

Best regards.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group