November 22, 2024, 01:31:53 PM

News:

Got VSA?  Want to use your Prop-SX?  Now you can!  See the VSA section of the Library forum for Prop-SX code that works with VSA.


Long Timer or Counter Advice

Started by Tim-M, January 24, 2008, 08:23:04 AM

Previous topic - Next topic

Tim-M

I have a Prop-1 project that I need a long timer for and I'd like some advice about the best way to go about that.

The program watches a couple of proximity sensors and when their states change, action is taken.  This is nailed down and working well.  I would like to add the function that if the sensor states do not change for a long period of time, (non-critical, about 1-2 hours) then I'd like to take action again.  If the states do change within that timed period, then reset the timer and start again.

My question is what's the best way to to set up a long timing or counting cycle like this with the Prop-1?  I haven't found much in the manuals or help on this.

Thanks,

Tim

JonnyMac

January 24, 2008, 09:07:25 AM #1 Last Edit: January 24, 2008, 11:02:55 AM by JonnyMac
Since you didn't post your code ( :( ) I can only give you an example -- you'll have to adjust the scanning section for your application.

Update: You make a copy of the present input states at Reset and then watch for a change -- if a change is detected then you jump back to Reset to clear everything.  If there is no change on the scan, delay a bit, then add that delay into a counter that ultimately propagates through successively larger counters to get the timing you need.


' =========================================================================
'
'   File......
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  Sensor2         = PIN1
SYMBOL  Sensor1         = PIN0


' -----[ Constants ]-------------------------------------------------------

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0


' -----[ Variables ]-------------------------------------------------------

SYMBOL  oldScan         = B2
SYMBOL  newScan         = B3
SYMBOL  tix             = B4
SYMBOL  secs            = B5
SYMBOL  mins            = B6


' -----[ Initialization ]--------------------------------------------------

Reset:
  oldScan = PINS                                ' initialize scan
  tix = 0                                       ' clear timing elements
  secs = 0
  mins = 0


' -----[ Program Code ]----------------------------------------------------

Main:
  newScan = PINS
  IF newScan <> oldScan THEN Reset              ' reset on inputs change
  PAUSE 10

Update_Tix:
  tix = tix + 1
  IF tix < 100 THEN Main                        ' 100 x 0.01s = 1 second

Update_Secs:
  tix = 0
  secs = secs + 1
  IF secs < 60 THEN Main

Update_Mins:
  secs = 0
  mins = mins + 1
  IF mins < 240 THEN Main                       ' take action @ 2 hours

Take_Action:
  ' do something about inputs here
  GOTO Reset


' -----[ Subroutines ]-----------------------------------------------------


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office

Tim-M

Sorry about not posting code Jon.  The project is prototype and the company is very sensitive about that.  They don't want any more information known about it than necessary, just generic snipits.  What I've written is loaded with comments describing the whole project from stem to stern.

What you describe is a bit backwards of what I'm looking for, but it tells me how to do the long timing and that's where I need the advice.  My explaination was poor.  I need the timer to start whenever the sensor states change and to reset or restart for each change after that.  It's only if the states remain in any  unchanged condition for the length of the approximate 2 hours, that I want to take some action.  Again, that goes for any state the sensors are in.

What I have written now is monitoring the state changes and is working well, so all I need to do is to add the timing stuff to it.

Thanks for your help,

Tim

JonnyMac

Day 1

Patient: Doctor, I'm sick.
Doctor: What's the matter?
Patient: I work for the government so I can't tell you.
Doctor: Okay, then, take these.

Day 2

Patient: Doctor, those pills didn't really help.
Doctor: You didn't really tell me what was wrong....

;D

Okay, I'm being jokey, but the truth is I can only help you to the degree you give me complete and accurate information.  Having programmed the BS1 since 1994 I'm pretty sure I can figure things out IF I'm given all the information I need.

I've updated the listing [above] to reflect the additional information you provided in your second post.
Jon McPhalen
EFX-TEK Hollywood Office

Tim-M

No doubt...  I understand that working this way is lousy at best, and I appreciate your efforts despite the situation.

Your programming experience shines daily Jon, so let me assure you that, that is not what's in question here.  In fact, I think it comes so naturally to you that I (and most of us) have to study quite a bit to even understand some of the details within the help that you giving!  You have the distinct advantages of having been both the developer of the product and programming it, and others, every day.

I'll be the first to say that programming does not come very easily to me... what I've written for this project works and would be reliable, but it's long and clumsy in comparison to the short, sleek version you've given here.  This forum and the access to you as the product developer are wonderful resources for your customers to have available.

Thank you again,

Tim

JonnyMac

Well, if a yutz like me (remember, I'm a professional actor) can do it, then you can too.  The only advantage I have on my side is experience but that is easily gained by anyone who will devote a little time.  I promise that if you will make 15-20 minutes a day available to playing with and learning to program, within a few months it will come as naturally to you as it does me.
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

Oh, and just a reminder... HAVE FUN while you're learning.  That's why we're doing this stuff.   ;D
Jon McPhalen
EFX-TEK Hollywood Office

Tim-M

Thanks for the encouragement Jon.... practice, practice, practice.