timeCounter
j.m.krell
Posts: 14
Hi,
I'm working on a project (drowning prevention system) and was wondering if there is a way to have more than one timeCounter or a way to keep time (more than one) on how long a pin is high or low.· If this isn't detailed enough post back an I'll delve into more details.· Thank you very much, I greatly appreciate it.
Jordan
I'm working on a project (drowning prevention system) and was wondering if there is a way to have more than one timeCounter or a way to keep time (more than one) on how long a pin is high or low.· If this isn't detailed enough post back an I'll delve into more details.· Thank you very much, I greatly appreciate it.
Jordan
Comments
Without an external counter you wouldn’t have accuracy, but internally you could run two passive counters within the loop that count while the pin is in the target state and stop when it changes and you can get a relative value. Of course, this really depends on the length of time and resolution required. Do you have any more details?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
Jordan M. Krell
It sounds like you will need an external timer or RTC such as the DS1302. When reset to 00:00:00 you can use it as a counter. You can have multiple counters in variables based on the contents read from the RTC. They don’t even need to be relative to 00:00:00 if you convert to raw and it will be easier to compare values. You limit will be 65535 seconds minus any offset from 00:00:00. I could go into a little more detail if you need. I hope this helps. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
I have trouble understanding what you want to do or how this system would work. My guess is that these timers do not have to have subsecond accuracy and that you can probably get more than one timer running at the same time in software. Here is a little program that counts up by seconds on two independent counters. It counts up if the associated pin p0 is at zero and resets to zero if the pin is 1.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Just out of curiosity, what kind of sensors or devices are attached to the two input pins to provide these signals? Depending on your answer, there may be a potential problem with the way you presently have it designed. It's by NO means an insurmountable problem, however.
Many years ago I designed a pool use alarm, that's why I ask. Once SET, it would detect anyone who might have fallen or jumped into the pool. It really prevented unauthorized use, and was NOT a pool safety device as yours seems to be.
regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
Jordan
See "Simple Multi-Tasking" on that page. The co-processor (a $12, 8-pin processor) would enable you to set a 10 mSec 'tick'. In your BS2 code, you can then use that 'tick' to implement multiple counters. This will get you a much more accurate timer than the BS2 alone.
And if 10 mSec doesn't give you enough time, you can implement a 20 mSec or 50 mSec 'tick' instead.
I've used this, and it's really liberating to have a 'hard' real-time tick source for the BS2.
Post Edited (allanlane5) : 1/29/2007 6:41:45 PM GMT
· This could be done, however you should know that the more tasks you add inside your loop the more it will affect the number of counts within the same period of time. Also keep in mind that 8 counters using Word variables will consume 16 of your 26 variables. A highly simplified sample of how this could be done is listed below. This shows 4 pins/counters but you could add more at the cost of variable space and speed. Bear in mind this doesn’t cover reading the variables at any given time to see how high they go before being reset. I presume this is something you have already thought out. I hope this helps. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
The program counts up if pin p0 is at 1 and resets the counter to 0 when pin0 is at 0. Same for pin p1. Here is a program that does it for 8 pins, p0 to p7:
Are your radios going to work underwater?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Thank you very much
Jordan
x·VAR·Byte
cnt0·VAR·Byte
cnt1·VAR·Byte
cnt2·VAR·Byte
cnt3·VAR·Byte
cnt4·VAR·Byte
cnt5·VAR·Byte
cnt6·VAR·Byte
cnt7·VAR·Byte
DO
··x·=·~·inL····'·complement·of·8·inputs·p0·to·p7
··cnt0·=·cnt0·+·x.bit0·*·x.bit0···'·channel·0·increment·when·p0=0,·reset·when·p0=1
··cnt1·=·cnt1·+·x.bit1·*·x.bit1···'·ditto,·channel·1
··cnt2·=·cnt2·+·x.bit2·*·x.bit2···'·ditto,·channel·2
··cnt3·=·cnt3·+·x.bit3·*·x.bit3···'·ditto,·channel·3
··cnt4·=·cnt4·+·x.bit4·*·x.bit4···'·ditto,·channel·4
··cnt5·=·cnt5·+·x.bit5·*·x.bit5···'·ditto,·channel·5
··cnt6·=·cnt6·+·x.bit6·*·x.bit6···'·ditto,·channel·6
··cnt7·=·cnt7·+·x.bit7·*·x.bit7···'·ditto,·channel·7
··IF·x·THEN·GOSUB·alarms··'·some·pin·is·low
··PAUSE·995···'·to·make·it·1·second·ticks,·hold·here·995·milliseconds
LOOP
alarms:
··IF·cnt0·=·30·THEN·DEBUG·CR,"Alarm0!"
··IF·cnt1·=·15·THEN·DEBUG·CR,"Alarm1!"
··'·and·so·on
··RETURN
Are your radios going to work underwater?
Tracy Allen
www.emesystems.com
x = inL ' state of 8 inputs p0 to p7
instead of
x = ~ inL ' complement of 8 inputs p0 to p7
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com