Delayed output 10 secs


Closed Thread
Results 1 to 38 of 38

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lilimike View Post
    Some days I feel dumber than others and today is one of those!


    All I really need is to have a counter that counts the minutes up to 720 and then cycle to 0 and start over endlessly. I don't need an interupt as I can test compare by branching from the main loop (in one minute I have plenty of time to test) Accuracy is not really important + or - 10 minutes over 720 is ok. I am already using timer0 so I guess I need to use timer1 or timer2.
    Mike
    Hi Mike,
    Welcome to My World!
    Code:
    counter var byte
    minutes var word
    clear  ' zero variables at start
    loop:
    
    PortB  = %00000000
    TRISB  = %00000000
    counter = counter + 1
    Pause 1000
    If counter >= 60 then minutes  = minutes + 1 : counter = 0
    
    if minutes >= 720 then gosub action
    goto loop
    
    Action:
    minutes = 0
    Toggle PortB.1 ' change this to do what you need done
    return
    A great clock this will not be, it does (should do) what you asked, you may need to juggle the numbers if you have a bunch of code to stuff in.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  2. #2
    Join Date
    May 2009
    Location
    Montreal, QC, Canada
    Posts
    118


    Did you find this post helpful? Yes | No

    Default

    Thank you Joe,

    Unfortunately the PAUSE 1000 within my main loop is making the response too slow.
    This is my main loop ( added your example) when I press on any of the 6 switches it needs to react faster than a second later. This is why I am thinking I probably need to use timer1.

    Code:
    Main:
        
        l=0: y=0
        WHILE !T0IF : WEND           ; wait for timer to overflow
        TMR0 = 193                   ; load timer for 1ms
        T0IF = 0                     ; reset the overflow flag
    
    
        IF (SW1=0) THEN Counters[0] = DelayTime : goto Channel1
        IF (SW2=0) THEN Counters[1] = DelayTime : goto Channel2
        IF (SW3=0) THEN Counters[2] = DelayTime : goto Channel3
        IF (SW4=0) THEN Counters[3] = DelayTime : goto Channel4
        IF (SW5=0) THEN Counters[4] = DelayTime : goto Channel5
        IF (SW6=0) THEN Counters[5] = DelayTime : goto Channel6
    
        FOR X = 0 to 5                      ; cycle thru counters
          IF Counters(X) > 0 THEN           ; if counter is counting
             Counters(X) = Counters(X) - 1  ; decrement counter
             IF Counters(X) = 0 THEN        ; if counter timed out
               SELECT CASE X                ; turn on the appropriate LED
                 CASE 0 : if led1 = 1 then gosub StartCharge1 
                 CASE 1 : if led2 = 1 then gosub StartCharge2
                 CASE 2 : if led3 = 1 then gosub StartCharge3
                 CASE 3 : if led4 = 1 then gosub StartCharge4
                 CASE 4 : if led5 = 1 then gosub StartCharge5
                 CASE 5 : if led6 = 1 then gosub StartCharge6
               END SELECT
             ENDIF
          ENDIF
        NEXT X
    ;-------------------------------------------------/
    ;               update counter                    /
    ;-------------------------------------------------/
        counter = counter + 1
        Pause 1000
        If counter >= 60 then minutes  = minutes + 1 : counter = 0
       
        ; trigger off if it is time
       
        if minutes >= 720 then minutes = 0
        
    GOTO Main

Similar Threads

  1. How to drive the Vinculum VDIP1 in UART mode
    By BrianT in forum Code Examples
    Replies: 41
    Last Post: - 23rd May 2013, 12:34
  2. USB-FTDI[UM232R] with PIC16f877a
    By bjox in forum USB
    Replies: 1
    Last Post: - 23rd February 2008, 22:40
  3. Serious Serial Situation Setbacks...
    By Dansdog in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 7th February 2007, 03:46
  4. Serial Output 10 Bits
    By GEEZER in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th May 2005, 02:14
  5. Using 4 input to control 10 output
    By cibotsan in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 5th November 2004, 12:08

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts