Delayed output 10 secs


Closed Thread
Results 1 to 38 of 38

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lilimike View Post
    Well I guess this must be a tough one as no one commented or maybe I didn't explain clearly my issue.
    I think it's just one of those, "you can't get there from here" kind of things.
    Trying to time things with pauses makes it so you can't do anything else at the same time, so 6 buttons would be difficult with the example given.

    However, if you do it a little differently, it's a piece of cake.
    Using a timer to measure even 1ms time periods, and running the main loop freely (without pauses), you can do it like this...
    Code:
    <font color="#008000"><b>CLEAR
    DEFINE </b></font><b>OSC </b><font color="#800000"><b>20
    </b></font><font color="#008000"><b>INCLUDE </b></font><font color="#FF0000">&quot;AllDigital.pbp&quot;         </font><font color="#0000FF"><b><i>; Disable Analog functions
    
    </i></b></font><b>SW1   </b><font color="#008000"><b>VAR </b></font><b>PORTB</b>.<font color="#800000"><b>0
    </b></font><b>SW2   </b><font color="#008000"><b>VAR </b></font><b>PORTB</b>.<font color="#800000"><b>1
    </b></font><b>SW3   </b><font color="#008000"><b>VAR </b></font><b>PORTB</b>.<font color="#800000"><b>2
    </b></font><b>SW4   </b><font color="#008000"><b>VAR </b></font><b>PORTB</b>.<font color="#800000"><b>3
    </b></font><b>SW5   </b><font color="#008000"><b>VAR </b></font><b>PORTB</b>.<font color="#800000"><b>4
    </b></font><b>SW6   </b><font color="#008000"><b>VAR </b></font><b>PORTB</b>.<font color="#800000"><b>5
    
    </b></font><b>LED1  </b><font color="#008000"><b>VAR </b></font><b>PORTC</b>.<font color="#800000"><b>0
    </b></font><b>LED2  </b><font color="#008000"><b>VAR </b></font><b>PORTC</b>.<font color="#800000"><b>1
    </b></font><b>LED3  </b><font color="#008000"><b>VAR </b></font><b>PORTC</b>.<font color="#800000"><b>2
    </b></font><b>LED4  </b><font color="#008000"><b>VAR </b></font><b>PORTC</b>.<font color="#800000"><b>3
    </b></font><b>LED5  </b><font color="#008000"><b>VAR </b></font><b>PORTC</b>.<font color="#800000"><b>4
    </b></font><b>LED6  </b><font color="#008000"><b>VAR </b></font><b>PORTC</b>.<font color="#800000"><b>5
    
    </b></font><b>Counters   </b><font color="#008000"><b>VAR WORD</b></font>[<font color="#800000"><b>6</b></font>]           <font color="#0000FF"><b><i>; 6 words, for 6 buttons
    </i></b></font><b>DelayTime  </b><font color="#008000"><b>CON </b></font><font color="#800000"><b>10000             </b></font><font color="#0000FF"><b><i>; 10 seconds
    </i></b></font><b>T0IF       </b><font color="#008000"><b>VAR </b></font><b>INTCON</b>.<font color="#800000"><b>2          </b></font><font color="#0000FF"><b><i>; TMR0 overflow flag   
    </i></b></font><b>X          </b><font color="#008000"><b>VAR BYTE
    
    </b></font><b>OPTION_REG </b>= <font color="#800000"><b>%01010100           </b></font><font color="#0000FF"><b><i>; WPU on, TMR0 1:32 prescaler, internal clk
    </i></b></font><font color="#008000"><b>PAUSE </b></font><font color="#800000"><b>50                         </b></font><font color="#0000FF"><b><i>; let everything settle
    
    </i></b></font><b>Main</b>:
        <font color="#008000"><b>WHILE </b></font>!<b>T0IF </b>: <font color="#008000"><b>WEND           </b></font><font color="#0000FF"><b><i>; wait for timer to overflow
        </i></b></font><b>TMR0 </b>= <font color="#800000"><b>100                   </b></font><font color="#0000FF"><b><i>; load timer for 1ms
        </i></b></font><b>T0IF </b>= <font color="#800000"><b>0                     </b></font><font color="#0000FF"><b><i>; reset the overflow flag
    
        </i></b></font><font color="#008000"><b>IF </b></font><b>SW1 </b>= <font color="#800000"><b>0 </b></font><font color="#008000"><b>then </b></font><b>Counters</b>[<font color="#800000"><b>0</b></font>] = <b>DelayTime </b>: <font color="#008000"><b>HIGH </b></font><b>LED1
        </b><font color="#008000"><b>IF </b></font><b>SW2 </b>= <font color="#800000"><b>0 </b></font><font color="#008000"><b>then </b></font><b>Counters</b>[<font color="#800000"><b>1</b></font>] = <b>DelayTime </b>: <font color="#008000"><b>HIGH </b></font><b>LED2
        </b><font color="#008000"><b>IF </b></font><b>SW3 </b>= <font color="#800000"><b>0 </b></font><font color="#008000"><b>then </b></font><b>Counters</b>[<font color="#800000"><b>2</b></font>] = <b>DelayTime </b>: <font color="#008000"><b>HIGH </b></font><b>LED3
        </b><font color="#008000"><b>IF </b></font><b>SW4 </b>= <font color="#800000"><b>0 </b></font><font color="#008000"><b>then </b></font><b>Counters</b>[<font color="#800000"><b>3</b></font>] = <b>DelayTime </b>: <font color="#008000"><b>HIGH </b></font><b>LED4
        </b><font color="#008000"><b>IF </b></font><b>SW5 </b>= <font color="#800000"><b>0 </b></font><font color="#008000"><b>then </b></font><b>Counters</b>[<font color="#800000"><b>4</b></font>] = <b>DelayTime </b>: <font color="#008000"><b>HIGH </b></font><b>LED5
        </b><font color="#008000"><b>IF </b></font><b>SW6 </b>= <font color="#800000"><b>0 </b></font><font color="#008000"><b>then </b></font><b>Counters</b>[<font color="#800000"><b>5</b></font>] = <b>DelayTime </b>: <font color="#008000"><b>HIGH </b></font><b>LED6
    
        </b><font color="#008000"><b>FOR </b></font><b>X </b>= <font color="#800000"><b>0 </b></font><font color="#008000"><b>to </b></font><font color="#800000"><b>5                      </b></font><font color="#0000FF"><b><i>; cycle thru counters
          </i></b></font><font color="#008000"><b>IF </b></font><b>Counters</b>(<b>X</b>) &gt; <font color="#800000"><b>0 </b></font><font color="#008000"><b>THEN           </b></font><font color="#0000FF"><b><i>;  if counter is counting
             </i></b></font><b>Counters</b>(<b>X</b>) = <b>Counters</b>(<b>X</b>) - <font color="#800000"><b>1  </b></font><font color="#0000FF"><b><i>;    decrement counter
             </i></b></font><font color="#008000"><b>IF </b></font><b>Counters</b>(<b>X</b>) = <font color="#800000"><b>0 </b></font><font color="#008000"><b>THEN        </b></font><font color="#0000FF"><b><i>; if counter timed out
               </i></b></font><font color="#008000"><b>SELECT CASE </b></font><b>X                </b><font color="#0000FF"><b><i>;  turn off the appropriate LED
                 </i></b></font><font color="#008000"><b>CASE </b></font><font color="#800000"><b>0 </b></font>: <font color="#008000"><b>LOW </b></font><b>LED1
                 </b><font color="#008000"><b>CASE </b></font><font color="#800000"><b>1 </b></font>: <font color="#008000"><b>LOW </b></font><b>LED2
                 </b><font color="#008000"><b>CASE </b></font><font color="#800000"><b>2 </b></font>: <font color="#008000"><b>LOW </b></font><b>LED3
                 </b><font color="#008000"><b>CASE </b></font><font color="#800000"><b>3 </b></font>: <font color="#008000"><b>LOW </b></font><b>LED4
                 </b><font color="#008000"><b>CASE </b></font><font color="#800000"><b>4 </b></font>: <font color="#008000"><b>LOW </b></font><b>LED5
                 </b><font color="#008000"><b>CASE </b></font><font color="#800000"><b>5 </b></font>: <font color="#008000"><b>LOW </b></font><b>LED6
               </b><font color="#008000"><b>END SELECT
             ENDIF
          ENDIF
        NEXT </b></font><b>X
    </b><font color="#008000"><b>GOTO </b></font><b>Main
    </b>
    No Interrupts required.

    HTH,
    DT

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    I should add ... the counters in the previous example are retriggerable. So the delay would be from the Last button Release.

    If the delay should be from the first press, wait 10 seconds, non-retriggerable,
    then replace the switch test lines with these ...
    Code:
    <font color="#000000">    <font color="#008000"><b>IF </b></font>(<b>Counters</b>[<font color="#800000"><b>0</b></font>]=<font color="#800000"><b>0</b></font>) <font color="#008000"><b>AND </b></font>(<b>SW1</b>=<font color="#800000"><b>0</b></font>) <font color="#008000"><b>THEN </b></font><b>Counters</b>[<font color="#800000"><b>0</b></font>] = <b>DelayTime </b>: <font color="#008000"><b>HIGH </b></font><b>LED1
        </b><font color="#008000"><b>IF </b></font>(<b>Counters</b>[<font color="#800000"><b>1</b></font>]=<font color="#800000"><b>0</b></font>) <font color="#008000"><b>AND </b></font>(<b>SW2</b>=<font color="#800000"><b>0</b></font>) <font color="#008000"><b>THEN </b></font><b>Counters</b>[<font color="#800000"><b>1</b></font>] = <b>DelayTime </b>: <font color="#008000"><b>HIGH </b></font><b>LED2
        </b><font color="#008000"><b>IF </b></font>(<b>Counters</b>[<font color="#800000"><b>2</b></font>]=<font color="#800000"><b>0</b></font>) <font color="#008000"><b>AND </b></font>(<b>SW3</b>=<font color="#800000"><b>0</b></font>) <font color="#008000"><b>THEN </b></font><b>Counters</b>[<font color="#800000"><b>2</b></font>] = <b>DelayTime </b>: <font color="#008000"><b>HIGH </b></font><b>LED3
        </b><font color="#008000"><b>IF </b></font>(<b>Counters</b>[<font color="#800000"><b>3</b></font>]=<font color="#800000"><b>0</b></font>) <font color="#008000"><b>AND </b></font>(<b>SW4</b>=<font color="#800000"><b>0</b></font>) <font color="#008000"><b>THEN </b></font><b>Counters</b>[<font color="#800000"><b>3</b></font>] = <b>DelayTime </b>: <font color="#008000"><b>HIGH </b></font><b>LED4
        </b><font color="#008000"><b>IF </b></font>(<b>Counters</b>[<font color="#800000"><b>4</b></font>]=<font color="#800000"><b>0</b></font>) <font color="#008000"><b>AND </b></font>(<b>SW5</b>=<font color="#800000"><b>0</b></font>) <font color="#008000"><b>THEN </b></font><b>Counters</b>[<font color="#800000"><b>4</b></font>] = <b>DelayTime </b>: <font color="#008000"><b>HIGH </b></font><b>LED5
        </b><font color="#008000"><b>IF </b></font>(<b>Counters</b>[<font color="#800000"><b>5</b></font>]=<font color="#800000"><b>0</b></font>) <font color="#008000"><b>AND </b></font>(<b>SW6</b>=<font color="#800000"><b>0</b></font>) <font color="#008000"><b>THEN </b></font><b>Counters</b>[<font color="#800000"><b>5</b></font>] = <b>DelayTime </b>: <font color="#008000"><b>HIGH </b></font><b>LED6</b>
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Thanks for the quick response Darrel,

    I tried your code and I feel like I am getting closer but...
    first the delay was over 1 minute so by making DelayTime CON 1500 it is close to 10 seconds. Not sure if it is because I am using the internal oscilator and it is not as accurate as it should be but this is no isue.

    Instead of turning off LEDs 1-5 after 10 seconds I need to turn on another set of Leds so I added TR1 VAR PORTA.0 up to TR6 VAR PORTA.5 and I used those in the select case and so far its all good.

    I now face the following issues:
    if I hold down any of the switches (SW1 to SW6) for 3 seconds, it should cancel the Delaytime that was going to turn on TRx and branch to a different label to do something else.

    If I press and release a switch, 10 seconds later TRx turns on, I need to be able to press and release the same switch to turn off LEDx and TRx at once.

    Another aspect I didn't mention because I will deal with it later is that when TRx turns on, if I don't manually press and release the switch to turn them off, after a set timed period (written in EEPROM) it will eventually turn off both LEDx and TRx

    I have a feeling I am going to spend a few months on this...

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lilimike View Post
    I tried your code and I feel like I am getting closer but...
    first the delay was over 1 minute ... Not sure if it is because I am using the internal oscilator ...
    OK, not a problem. You didn't specify an OSC earlier so I chose 20mhz.

    Let's go with 8Mhz internal.
    Change the OSC define and add this line ...
    Code:
    DEFINE OSC 8
    OSCCON = %01110001               ; 8Mhz Internal
    And change TMR0 = 100 to ...
    Code:
    <font color="#000000">    <b>TMR0 </b>= <font color="#800000"><b>193                   </b></font><font color="#0000FF"><b><i>; load timer for 1ms</i></b></font>
    And put DelayTime back to 10000.

    The values for different OSC and Timer reload periods can be found easily with ...

    PicMultiCalc - (Timer Helper)
    http://www.picbasic.co.uk/forum/atta...7&d=1225550328

    My example was trying to show how to deal with 6 different timers without needing 6 Timers.

    I'm affraid the "Instead of"'s will be your job.
    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Fair enough,
    This has brought me to a level beyong what I had expected and its given me tons of ideas for the rest.

    Thank you for your help.

    Mike

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


    Did you find this post helpful? Yes | No

    Default

    Darrel,

    I was able to mix the code example you provided with my previous code and I have almost completed my project. I have one final step to acomplish and it is to trigger off LED1 to 6 based on a time period. the time period is between 1 to 12 hours and can occur only every 60 minutes from the time LEDx was set high.

    I came accros your example "Elapsed Timer" using Timer1 and I think this is suitable for what I need to do. I have saved the 3 files "DT_INTS-14.bas", "ReEnterPBP.bas" and "Elapsed_INT.bas" and used your example but I am getting the following errors:

    [224] local directive only for use in macro
    [225] undefined symbol 'iflafreg'
    [226] numeric constant or symbol name expected
    [201] ')' expected
    [300] too many errors

    Could it be that chip 16F883 is not supported with this code ?
    I am using PBP 2.50c

    Thanks

    Mike

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    You need to use MPASM for the assembler.

    It doesn't work with PBP's default PM assembler.
    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Default

    I did a bit of code in ASM with MPLAB but If I create a project with MPLAB using MPASM, it will not compile my .bas code. I have tried using PBP within MPLAB but its not working.

    Can you give me an overview (or a link) of how to do this?

    Thanks

    Mike

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