November 22, 2024, 04:52:17 AM

News:

You can now use Vixen to program your Prop-1 and Prop-2 controllers!  Get started quickly and easily, without having to learn PBASIC.  Details in the Library forum.


60 second relay timer

Started by Jadams, August 27, 2010, 11:56:38 AM

Previous topic - Next topic

Jadams

I can't seem to get this to run past 25 seconds.  I want the relay to be on for 1 sec. and off for 60 sec.

Thanks for your help

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


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

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


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

SYMBOL  Relay          = PIN0


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

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0

SYMBOL  Yes             = 1
SYMBOL  No              = 0


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

SYMBOL  tix             = B2



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

Reset:
  PINS = %00000000                              ' clear all
  DIRS = %00000001                              ' set outputs


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

Main:

                                                ' 1 tix = .1 sec

  Relay = IsOn
  tix = 10                                      ' set for 1.0 second
  GOSUB Run_Timer

  Relay = IsOff

  tix = 600                                     ' set for 60 seconds
  GOSUB Run_Timer                               ' start the timer


  GOTO Main






' -----[ Subroutines ]-----------------------------------------------------
Run_Timer:
  IF tix = 0 THEN Timer_Done                    ' check for end of timer
    PAUSE 100                                   ' hold for 1 tic
    tix = tix - 1                               ' update tix count
    GOTO Run_Timer                              ' re-check for end of timer

Timer_Done:
  RETURN                                        ' go back to main program

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


' -----[ User Data ]-------------------------------------------------------
Jim Adams

JonnyMac

You need to make 'tix' a W (word) variable (use W5) so that you can have values greater than 255.  Right now the upper bits of your value are getting truncated (by the B variable) so when your code says 600 it's actually loading tix with 88 (it's a binary math thing).
Jon McPhalen
EFX-TEK Hollywood Office

Jadams

Thank you Jon.  It works perfectly.

What is the max time that can be used with this method?  Also, could I have used 'Pause' to accomplish the same thing?

Jim Adams

JonnyMac

Using your first program the maximum timing is 65535 (max value for a W variable) x 100ms = 6553500 milliseconds, or 655.35 seconds, a little over 10 minutes.

Yes, you could have used PAUSE directly as your longest value is less that 65535:

Main:
  Relay = IsOn
  PAUSE 1000
  Relay = IsOff
  PAUSE 60000
  GOTO Main
Jon McPhalen
EFX-TEK Hollywood Office