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 CCS Technical Support

How to deal with RTCC in apps with timing constraints?

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



Joined: 12 Jul 2011
Posts: 18
Location: El Salvador

View user's profile Send private message

How to deal with RTCC in apps with timing constraints?
PostPosted: Fri Jul 22, 2011 8:45 pm     Reply with quote

Let's make an specific post for this doubt:

I'm programming an application that has to around 2 seconds of consecutive ADC measures each 10 minutes.

I think I do understand (hopefully) how to create an internal RTCC using timer0, but...

How long does it takes to the PIC to perform all the timer0() interruption attention routine?

The point is that once the measures have started, I can't allow the timer0() to interrupt or its execution time will affect to my measures, in correlating them in time (i.e. If it interrupts and takes 10 ms to run its attention code once it returns the measure It'll take won't be the next to the previous one but one 10 ms later).

So, the solution would be disable interruptions each time the measures start, before calling the measuring routine, and enable them again once they've finished, but the problem is that as the measuring & sending process last for, let say, 5 seconds, I'll be losing 5 seconds on my RTCC in each measuring cycle.

Any idea of how can I deal with this?

Thank you!

Pablo
temtronic



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

View user's profile Send private message

PostPosted: Sat Jul 23, 2011 12:07 pm     Reply with quote

1) It'll help if you specify the PIC you're using...

2) there's a Real Time Clock in the Code section that works very well. Easy,simple as pie , to use it to 'trigger' your ADC routine every 10 minutes.
temtronic



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

View user's profile Send private message

PostPosted: Sat Jul 23, 2011 12:10 pm     Reply with quote

I think this is the link....

http://www.ccsinfo.com/forum/viewtopic.php?t=26177
krugger



Joined: 12 Jul 2011
Posts: 18
Location: El Salvador

View user's profile Send private message

PostPosted: Sat Jul 23, 2011 7:51 pm     Reply with quote

Thank you Temtronic for your answers,

I'm using PIC16F1827, but I don't have problems with designing a clock, but with dealing with it together with my measures.

I need 2.4 seconds of continuous measures (they'll be used to calculate FFT once received in the master node), so during those 2.4 secs, I need to disable interruptions to avoid losing measures while the clock timer interruption routine is being treated.

The question is, how can I do for not losing the correct time in each measuring process? Maybe I can calculate how long does it takes to measure and send the measures and sum this time to the clock variables before enabling interrupts again...

Thanks again!

Pablo
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

View user's profile Send private message Visit poster's website

PostPosted: Sat Jul 23, 2011 9:46 pm     Reply with quote

The rule of thumb I've seen is that interrupts take about 60 cycles, plus whatever processing you're doing in the handler. I haven't needed to measure it myself. That means your interrupt handler should execute in microseconds, not milliseconds. If timing is critical to your application, you really need to do some tests to measure things.

If you really need to disable interrupts but keep the clock ticking, then poll the interrupt flag while interrupts are disabled and increment a counter. Then 'catch up' when interrupts are re-enabled.
_________________
Andrew
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Jul 24, 2011 12:37 am     Reply with quote

If you are able to perform exactly timed AD data acquisition for 2 seconds (are you?), then it's no problem to stop the RTCC timer meanwhile. You know the time amount and can add it to the timer variables.

You can also switch to polling the timer instead of getting interrupted by it for a while. It effectively reduces the latency.
temtronic



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

View user's profile Send private message

PostPosted: Sun Jul 24, 2011 10:44 am     Reply with quote

another way is to have a hardware RTC

or have your software RTC only interrupt say every 5 seconds that way the ADC code will NOT get interrupted as it only needs 2 seconds to complete.
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