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

Problem getting built in RTC alarm to work on PIC18F47J13

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



Joined: 02 Aug 2015
Posts: 16
Location: Australia

View user's profile Send private message

Problem getting built in RTC alarm to work on PIC18F47J13
PostPosted: Mon Feb 24, 2020 4:08 am     Reply with quote

I have a problem getting the on board RTC Alarm to operate in the manner I would like.
The project in essence is very simple. The devices are battery operated and are part of a network of over 100 devices communication over a radio link.
The devices wake from sleep every xx minutes, gather some data and report to the base station and then go to sleep.
My problem is there is a repeater in the system, and I need to synchronise the wake up event across all modules to ensure they don’t miss the working window of the repeater. Because of the congestion around the repeater link every device will go to sleep at different times so all the sleep delays will most likely be different between the devices.
I thought I could put a time of day in the alarm registers and an interrupt would be generated when it occurred, but it doesn’t seem to operate that way
I must have a blind spot as I can’t seem to figure out how to do it.
The code below toggles the led each 10 second alarm cycle
As a start, how do I make it alarm at 15 seconds?
Can anybody point me in the right direction?

Code:
 
#include <18F47J13.h>
#fuses INTRC_IO, NOWDT
#fuses SOSC_HIGH, RTCOSC_T1
#use delay(clock=4M)

//!#include <time.h>
//!#include <_rtcperipheral.c>

#define     LED_Green      PIN_A5   
#define     LED_Blue       PIN_B5 
#define     LED_Red        PIN_E1 
 

rtc_time_t wizardTempTime;

#INT_RTC
void RTC_isr(void)
{
output_toggle(LED_Red);
}

//==============================
void main(){
   int1 _sleep = FALSE;

   setup_rtc(RTC_ENABLE, 0);
   
   wizardTempTime.tm_year = 20;
   wizardTempTime.tm_mon  = 1;
   wizardTempTime.tm_mday = 24;
   wizardTempTime.tm_wday = 5;
   wizardTempTime.tm_hour = 13;
   wizardTempTime.tm_min  = 54;
   wizardTempTime.tm_sec  = 46;
   rtc_write(&wizardTempTime);
   
   //setup_rtc_alarm(RTC_ALARM_ENABLE, RTC_ALARM_10_SECONDS, 0);
   
   wizardTempTime.tm_year = 0;
   wizardTempTime.tm_mon  = 0;
   wizardTempTime.tm_mday = 0;
   wizardTempTime.tm_wday = 0;
   wizardTempTime.tm_hour = 0;
   wizardTempTime.tm_min  = 0;
   wizardTempTime.tm_sec  = 0;
   rtc_alarm_write(&wizardTempTime);
   
   
   enable_interrupts(INT_RTC);
   enable_interrupts(GLOBAL);
   
   while(TRUE){
      // Do some stuff  /////////////
      delay_ms(500);
      output_toggle(LED_blue);
      _sleep = TRUE; // check to see if all work is done and if so set sleep flag
      ///////////////////////////////
     
     
     
      if(_sleep){
         // all opperational tasks done so off to sleep
         _sleep = FALSE;

         
         /////////////////////////////////////////////////////////////
         // calculate time to next wake up
         // set the rtc to wake  in x seconds ?????
         
         
         setup_rtc_alarm(RTC_ALARM_ENABLE, RTC_ALARM_10_SECONDS, 1);
         sleep();
         
      }
   }
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19451

View user's profile Send private message

PostPosted: Mon Feb 24, 2020 7:12 am     Reply with quote

The masks for the alarm are what the hardware supports. No option for
15 seconds.
However what you can do is set a 'once a day' alarm for a time 15 seconds
in the future. When it triggers this, you then reset the alarm again for a
new time 15 seconds further in the future.
I hope your devices receive an updated clock as some part of the data.
Otherwise the clocks will drift apart.....
HaveAchat



Joined: 02 Aug 2015
Posts: 16
Location: Australia

View user's profile Send private message

PostPosted: Mon Feb 24, 2020 3:43 pm     Reply with quote

I think you are confirming my read of the RTC operation.
It would have been nice to magically wake at the precise time, no such luck.

Yes I have a beacon ping to synchronise "time" across the range and if everybody can get up and running within a few seconds of each other the "funding" model may work.
I am also planning to steal the clock time from system traffic which might be more reliable than the beacon.

That is a lower order bug to resolve.

Many thanks for the support.
temtronic



Joined: 01 Jul 2010
Posts: 9205
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Feb 26, 2020 6:11 am     Reply with quote

hmm, have you considered using an external RTC like the DS3231 ? I know, adds a little cost and a bit of PCB area BUT.... you get a battery backed high acurate RTC WITH alarm capabilty.
You may find the additional HW cost more than offsets the R&D time ( and $$$) trying to code around your current problem.
Say it costs $2 for the HW, 100 units = $200. At $50/hr R&D, that's 4 hrs. I'll wager you've spent MORE than 4 hrs already and still haven't got a good solution....that works.
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