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

Sequential lighting design problem

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







Sequential lighting design problem
PostPosted: Wed Jun 25, 2003 7:52 am     Reply with quote

I am building a prayer candle lamps box for a catholic church. The box has 3 slots to insert coin or paper money. After power up, when some one want to pray he/she insert coin(s) into a slot and the first of 10 of candle lamp lights up for 5 minutes. When this period has not been elapsed you can add one more coin, and the second lamp lights up, and so on. So each lamp light will distinguish 5 minutes after it is triggered by coin insertion. After the 10th lamp, coin insert will trigger back the first lamp. I intend to use PIC micro 16f84, use one of port A as trigger input, use the rest of port A and port B as outputs to be fed to driver like ULN 2003 to drive relays which in turn activate the lamps. If anyone has any ideas how to program the timer in the 16f84 for this application I will be very grateful. Thank you very much for your help !
Jusman Sulaiman
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515559
R.J.Hamlett
Guest







Re: Sequential lighting design problem
PostPosted: Wed Jun 25, 2003 9:09 am     Reply with quote

:=I am building a prayer candle lamps box for a catholic church. The box has 3 slots to insert coin or paper money. After power up, when some one want to pray he/she insert coin(s) into a slot and the first of 10 of candle lamp lights up for 5 minutes. When this period has not been elapsed you can add one more coin, and the second lamp lights up, and so on. So each lamp light will distinguish 5 minutes after it is triggered by coin insertion. After the 10th lamp, coin insert will trigger back the first lamp. I intend to use PIC micro 16f84, use one of port A as trigger input, use the rest of port A and port B as outputs to be fed to driver like ULN 2003 to drive relays which in turn activate the lamps. If anyone has any ideas how to program the timer in the 16f84 for this application I will be very grateful. Thank you very much for your help !
:=Jusman Sulaiman

The 'key', is that the timer in the 16F84, is only very simple (doesn't support the large dividers available on the latter chips, with multiple timers). The largest division value available to you, is 1/262144 of the incoming clock. My first thought therefore, would be, that I'd chose a clock, that was a multiple of this value. If you use a 4.194MHz crystal (these are readily available, and the 4MHz part is specified to run to this rate - Microchip told me this some years ago, when I needed an accurate time), with the prescaler set to 256, and the clock set to free run, you will get an interrupt every 1/16th second.
This then makes interval timing relatively easy, with something like:

unsigned long countdown;

#int_timer0
void int_handler(void) {
static int tick=16;
if (! --tick) {
tick=16;
if (countdown!=0) --countdown;
}
}

Then in your main code, if you want to wait for five minutes, this will do what is needed:

countdown=300; //Count is in seconds
while (countdown) ;
//you will only arrive here, when 'countdown' gets to
//zero.

The nice thing about this approach, is that you can execute other code while waiting, and when the countdown reaches zero, it will stop, making it impossible to 'miss' the zero, if you happen to be doing something else at the time. Since the countdown value is a 'long', the maximum time supported, is just over 1000 minutes. Also because you are testing for zero, there is no problem with 'granularity', which could apply if you test for any other value in the main code - remember that the test will test each byte of the two byte value, at a slightly different time (unless the interrupt is disabled for the test), and if you looked for a value like 1000, then the possibility exists that if the value is counting when tested, the correct pattern might be seen 'by accident', with certain numbers, if the counter changes between the two halves being read. The only time both bytes can test as zero at the same time, is when the counter has genuinely reached zero. :-)

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515562
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: Sequential lighting design problem
PostPosted: Wed Jun 25, 2003 12:05 pm     Reply with quote

Sounds like you just need to measure time. Have a look at the RTC discusions in this forum by doing a search. You can get accurate time measurement with any crystal speed.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515565
Sherpa Doug
Guest







Re: Sequential lighting design problem
PostPosted: Thu Jun 26, 2003 6:59 am     Reply with quote

:= with the prescaler set to 256, and the clock set to free run, you will get an interrupt every 1/16th second.

Also if you set the prescaller to 4 instead of 256 you get 4.7 seconds instead of 5 minutes. This makes testing much faster.

___________________________
This message was ported from CCS's old forum
Original Post ID: 144515573
R.J.Hamlett
Guest







Re: Sequential lighting design problem
PostPosted: Thu Jun 26, 2003 7:49 am     Reply with quote

:=:= with the prescaler set to 256, and the clock set to free run, you will get an interrupt every 1/16th second.
:=
:=Also if you set the prescaller to 4 instead of 256 you get 4.7 seconds instead of 5 minutes. This makes testing much faster.
:=

A man after my own heart. :-)
There is nothing worse than trying to debug problems with 'long' timer code, that only happen at massive intervals. Turning the divider down, is a very nice debugging tool.

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515576
adrian



Joined: 08 Sep 2003
Posts: 92
Location: Glasgow, UK

View user's profile Send private message

Re: Sequential lighting design problem
PostPosted: Fri Jun 27, 2003 6:00 am     Reply with quote

I intend to use PIC micro 16f84....... If anyone has any ideas how to program the timer in the 16f84 for this application I will be very grateful. Thank you very much for your help !
:=Jusman Sulaiman

Are you sure you want to use a 16F84? They are getting long in the tooth now. The 16F627/8 are pin compatible and cheaper. An advantage of using the 16F627/8 is you can add a 32khz crystal and a couple of caps to PB6/7 and use timer 2 (I think - I dont have my code here) and get 1 second ticks.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515595
Jusman Sulaiman
Guest







Re: Sequential lighting design problem
PostPosted: Fri Jun 27, 2003 9:38 am     Reply with quote

:= I intend to use PIC micro 16f84....... If anyone has any ideas how to program the timer in the 16f84 for this application I will be very grateful. Thank you very much for your help !
:=:=Jusman Sulaiman
:=
:=Are you sure you want to use a 16F84? They are getting long in the tooth now. The 16F627/8 are pin compatible and cheaper. An advantage of using the 16F627/8 is you can add a 32khz crystal and a couple of caps to PB6/7 and use timer 2 (I think - I dont have my code here) and get 1 second ticks.

Adrian,
I have no choice. Here in Jakarta electronic components shops it's only 16F84 and 16C54 available. From Microchip internet site I know that they have a very wide range of chips nowadays. The fact that 16F627/8 is cheaper proves that the 16F84 is now obsolete.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515602
Jusman Sulaiman
Guest







Re: Sequential lighting design problem
PostPosted: Fri Jun 27, 2003 9:41 am     Reply with quote

:=Sounds like you just need to measure time. Have a look at the RTC discusions in this forum by doing a search. You can get accurate time measurement with any crystal speed.


Neutone,
Actually the exact time delay for my design is not important, instead I just think about adding jumper setting to choose different time delay like 6 seconds, 7 seconds etc. However, if the time delay is 5.2 seconds, from time to time it must consistent, so the earlier lamp triggered will extinguish earlier as well. The real problem is how to manage the timer interrupt of 16F84 single timer to update 10 variable with different period of inter-triggering. Thanks to your advice and certainly I will search for timer discussions in this forum.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515603
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: Sequential lighting design problem
PostPosted: Fri Jun 27, 2003 9:42 am     Reply with quote

:=:= I intend to use PIC micro 16f84....... If anyone has any ideas how to program the timer in the 16f84 for this application I will be very grateful. Thank you very much for your help !
:=:=:=Jusman Sulaiman
:=:=
:=:=Are you sure you want to use a 16F84? They are getting long in the tooth now. The 16F627/8 are pin compatible and cheaper. An advantage of using the 16F627/8 is you can add a 32khz crystal and a couple of caps to PB6/7 and use timer 2 (I think - I dont have my code here) and get 1 second ticks.
:=
:=Adrian,
:=I have no choice. Here in Jakarta electronic components shops it's only 16F84 and 16C54 available. From Microchip internet site I know that they have a very wide range of chips nowadays. The fact that 16F627/8 is cheaper proves that the 16F84 is now obsolete.


Request samples of the parts you want to use from digikey. They even deliver for free.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515605
Jusman Sulaiman
Guest







Re: Sequential lighting design problem
PostPosted: Fri Jun 27, 2003 9:43 am     Reply with quote

:=:=I am building a prayer candle lamps box for a catholic church. The box has 3 slots to insert coin or paper money. After power up, when some one want to pray he/she insert coin(s) into a slot and the first of 10 of candle lamp lights up for 5 minutes. When this period has not been elapsed you can add one more coin, and the second lamp lights up, and so on. So each lamp light will distinguish 5 minutes after it is triggered by coin insertion. After the 10th lamp, coin insert will trigger back the first lamp. I intend to use PIC micro 16f84, use one of port A as trigger input, use the rest of port A and port B as outputs to be fed to driver like ULN 2003 to drive relays which in turn activate the lamps. If anyone has any ideas how to program the timer in the 16f84 for this application I will be very grateful. Thank you very much for your help !
:=:=Jusman Sulaiman
:=
:=The 'key', is that the timer in the 16F84, is only very simple (doesn't support the large dividers available on the latter chips, with multiple timers). The largest division value available to you, is 1/262144 of the incoming clock. My first thought therefore, would be, that I'd chose a clock, that was a multiple of this value. If you use a 4.194MHz crystal (these are readily available, and the 4MHz part is specified to run to this rate - Microchip told me this some years ago, when I needed an accurate time), with the prescaler set to 256, and the clock set to free run, you will get an interrupt every 1/16th second.
:=This then makes interval timing relatively easy, with something like:
:=
:=unsigned long countdown;
:=
:=#int_timer0
:=void int_handler(void) {
:= static int tick=16;
:= if (! --tick) {
:= tick=16;
:= if (countdown!=0) --countdown;
:= }
:=}
:=
:=Then in your main code, if you want to wait for five minutes, this will do what is needed:
:=
:=countdown=300; //Count is in seconds
:=while (countdown) ;
:=//you will only arrive here, when 'countdown' gets to
:=//zero.
:=
:=The nice thing about this approach, is that you can execute other code while waiting, and when the countdown reaches zero, it will stop, making it impossible to 'miss' the zero, if you happen to be doing something else at the time. Since the countdown value is a 'long', the maximum time supported, is just over 1000 minutes. Also because you are testing for zero, there is no problem with 'granularity', which could apply if you test for any other value in the main code - remember that the test will test each byte of the two byte value, at a slightly different time (unless the interrupt is disabled for the test), and if you looked for a value like 1000, then the possibility exists that if the value is counting when tested, the correct pattern might be seen 'by accident', with certain numbers, if the counter changes between the two halves being read. The only time both bytes can test as zero at the same time, is when the counter has genuinely reached zero. :-)
:=
:=Best Wishes


R.J. Hamlett,
Thank you for your detailed explanation on using C program approach to the design. Since the 5 minutes time delay is not necessarily accurate (but stable all the time) I will choose the 4 MHz instead of the precise 4.194 MHz crystal. Unfortunately for designing with the PIC micro I can only program with Assembly language and the MPLAB. I believe that C for most application is more convenient and easy so I feel that I have to begin learning it. Please advise a starter book about C programming for PIC micro, will you ? Yes, the 16F84 is maybe almost obsolete among new abundant range from Microchip, but here in Jakarta, only 16C53 and 16F84 are available in the electronic component shops so I have no choice. Anyway I will study your code and trick to manage the interrupt, hopefully I could translate it to the Assembly. I have to tell you that actually the original goal for the design is for 50 lamps, not 8. But before searching solution in this forum I decide to make the problem simpler due to ports limitation of the 16F84. When I have programmed it successfully with 8 lamps, I can easily make the port not as a sequencer, but as a binary counter whose outputs can be fed to decoders like 74HC154s and get the same result for 50 lamps.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515606
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