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

Two timed inputs?

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



Joined: 20 Aug 2006
Posts: 12

View user's profile Send private message

Two timed inputs?
PostPosted: Sat Aug 16, 2008 5:43 pm     Reply with quote

I have a project where product is fed to two different conveyor belts via an alternating mechanical diverter. I want to add a photocell on each of the two conveyor belts so that when product backs up, the diverter will only shift to the non-backed up conveyor. If both photocells are covered for a certain length of time, the machine will quit feeding product altogether. I figure an operator-controlled adjustable timing (0.0 to 9.9 seconds, in 0.1 second increments) will be able to allow the various product to pass through, then when the photocell(s) is covered for the set time, the software will control the diverter or stop feeding. Then, continue normal diverter operation or restart feeding when the backed up condition clears.

Here's my question: If I use TIMER0 and TIMER1 to measure the time that the photocells are on, then interrupts at the set time, won't there be a time when the TIMER1 interrupt tries to come in while I am trying to handle the TIMER0 interrupt, and vice versa?

Or because we're talking about 0.1 sec (100 msec) increments, instead of interrupts, should I just poll a timer every program scan cycle and just do the math?
newguy



Joined: 24 Jun 2004
Posts: 1903

View user's profile Send private message

PostPosted: Sat Aug 16, 2008 6:30 pm     Reply with quote

I wouldn't worry about the time difference as it's honestly 'pee' in the ocean. Yes, a timer0 interrupt can occur while timer1 is being serviced, and vice-versa, but the time it takes to finish one and service the other is absolutely tiny compared to the resolution of 0.1 sec.

The other option is to set up a single timer to 'tick' at 100 msec or 50 msec. When a photocell becomes blocked, make note of the time (which could be a 16 or 32 bit integer). In the timer interrupt routine, increment a 'blocked' counter for each photocell as long as each is blocked. If that counter exceeds the operator preset value, take action. When the photocell becomes unblocked, reset its counter. I'd use either the external 0 and external 1 interrupts to detect photocell block/unblocking or the port B high nibble interrupt-on-change (pins B4-B7).
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