Delay without using pause


Closed Thread
Results 1 to 40 of 43

Hybrid View

  1. #1
    Join Date
    Oct 2014
    Location
    Lagos Nigeria
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Re: Delay without using pause

    THANKS TO YOU ALL FOR TRYING TO HELP.

    I have thrown together some wobbly code to try and explain what i'm trying to do.

    I know it might not be the best way, but i can't seem to wrap my head around the whole idea. I just want to be able to use pause in a way that I won't sit and wait for the time to elapse.

    in the mainloop here, i have 4 blocks (which could be doing many different things aside from toggling pins). Each block has a pause somewhere set by the value loaded in DELAYREGx

    Then in the ISR INTERUPTING EVERY 1ms;

    MYISR1:
    IF DELAYREG1>0 THEN
    DELAYREG1=DELAYREG1-1
    IF DELAYREG1=0 THEN
    DELAY1flag=1
    ENDIF
    ENDIF

    IF DELAYREG2>0 THEN
    DELAYREG2=DELAYREG2-1
    IF DELAYREG2=0 THEN
    DELAY2flag=1
    ENDIF
    ENDIF

    IF DELAYREG3>0 THEN
    DELAYREG3=DELAYREG3-1
    IF DELAYREG3=0 THEN
    DELAY3flag=1
    ENDIF
    ENDIF

    IF DELAYREG4>0 THEN
    DELAYREG4=DELAYREG4-1
    IF DELAYREG4=0 THEN
    DELAY4flag=1
    ENDIF
    ENDIF

    ; END OF ISR
    ;

    Then in the mainloop,

    MAINLOOP:

    BLOCK0:

    IF LED0_UPDATE THEN
    HIGH PORTB.0 ;IS IT TIME TO UPDATE LED0?
    @ myPAUSE 1000,1 ;MAKE PORTB.0 HIGH FOR 1000 ms USING DELAYREG1
    LED0_UPDATE=0 ;BUT DON'T WAIT FOR THE TIME TO ELAPSE
    GOTO BLOCK1
    ENDIF

    IF DELAY1flag THEN ;WILL BE SET IN THE ISR ATFTER 1 SECOND
    LOW PORTB.0 ;HAVE WE COME TO THE END OF 1 SECOND?
    ENDIF ;END OF myPAUSE


    BLOCK1:

    IF LED1_UPDATE THEN
    HIGH PORTB.1 ;IS IT TIME TO UPDATE LED1
    @ myPAUSE 4000,2 ;MAKE PORTB.1 HIGH FOR 4000 ms USING DELAYREG2
    LED1_UPDATE=0 ;BUT DON'T WAIT FOR THE TIME TO ELAPSE
    GOTO BLOCK2
    ENDIF

    IF DELAY2flag THEN ;WILL BE SET IN THE ISR ATFTER 4 SECOND
    LOW PORTB.1 ;HAVE WE COME TO THE END OF 4 SECOND?
    ENDIF ;END OF myPAUSE

    BLOCK2:
    IF LED2_UPDATE THEN
    HIGH PORTB.2 ;IS IT TIME TO UPDATE LED2
    @ myPAUSE 2000,3 ;MAKE PORTB.2 HIGH FOR 2000 ms USING DELAYREG3
    LED2_UPDATE=0 ;BUT DON'T WAIT FOR THE TIME TO ELAPSE
    GOTO BLOCK3
    ENDIF

    IF DELAY3flag THEN ;WILL BE SET IN THE ISR ATFTER 2 SECOND
    LOW PORTB.2 ;HAVE WE COME TO THE END OF 2 SECOND?
    ENDIF ;END OF myPAUSE

    BLOCK3:
    IF LED3_UPDATE THEN
    HIGH PORTB.3 ;IS IT TIME TO UPDATE LED3
    @ myPAUSE 400,4 ;MAKE PORTB.3 HIGH FOR 400 ms USING DELAYREG4
    LED3_UPDATE=0 ;BUT DON'T WAIT FOR THE TIME TO ELAPSE
    GOTO BLOCK0
    ENDIF

    IF DELAY1flag THEN ;WILL BE SET IN THE ISR ATFTER 0.4 SECOND
    LOW PORTB.3 ;HAVE WE COME TO THE END OF 0.4 SECOND?
    ENDIF ;END OF myPAUSE

    GOTO MAINLOOP

    Here is what i mean by using pbp within ASM macro;

    ASM
    MACRO myPAUSE msec,subID
    movlw msec
    movwf delay_temp
    movlw subID
    movwf KeepTrack
    ENDASM

    SELECT CASE KeepTrack

    CASE 1
    DELAYREG1=delay_temp
    DELAY1flag=0

    CASE 2
    DELAYREG2=delay_temp
    DELAY2flag=0

    CASE 3
    DELAYREG3=delay_temp
    DELAY3flag=0

    CASE 4
    DELAYREG4=delay_temp
    DELAY4flag=0

    CASE ELSE

    @ NOP
    END SELECT

    @ ENDM

    I hope someone might understand and help me...

    thanks.

  2. #2
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: Delay without using pause

    Stanon1, I see where you are clearing: LED0_UPDATE=0 but where are you setting it to TRUE? I think you are on the right track but it could be made much more simplistic.
    Dave Purola,
    N8NTA
    EN82fn

  3. #3
    Join Date
    Oct 2014
    Location
    Lagos Nigeria
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Re: Delay without using pause

    Exactly! It could be made simpler. That is the crux of the matter.

    You are right i didn't show where i am setting LED0_UPDATE. these flags themselves, at the right time based on certain parameters, are set by other isr running in parrallel with the heartbeat timer

    thanks for the reply

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: Delay without using pause

    I can suggest a little different approach which I have used...... its similar to how operating systems work ... and since you are using interrupts, you already are doing most of the work...
    I will explain more unless your intent on proceeding with what you have been doing.
    don

  5. #5
    Join Date
    Oct 2014
    Location
    Lagos Nigeria
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Re: Delay without using pause

    Quote Originally Posted by amgen View Post
    I can suggest a little different approach which I have used...... its similar to how operating systems work ... and since you are using interrupts, you already are doing most of the work...
    I will explain more unless your intent on proceeding with what you have been doing.
    don
    hi amgen, pls any suggestions you have is welcome. my aim was to let you guys understand what i'm trying to do; i am not good at coding so that is where i need help: how best to go about it to get the expected results... i will be glad if you would explain

  6. #6


    Did you find this post helpful? Yes | No

    Default Re: Delay without using pause

    before adding your code, set up a real time loop with interrupt every 100 milliseconds (that gives 10 times per second and allows for many microsecond instructions to run within main timing loop) don't use any pauses....just set/start/check counters in loop sections as each pass is exactly .1 seconds.
    So program runs main loop including your individual code parts..... then waits at the bottom in a while command until the interrupt sends it back to main loop ......
    as long as all your code operates within 100 milliseconds (that's many 1 and 2 microsecond machine code instructions) then the loop will always wait until retriggered after looping through your code in the while loop.
    You set up a few flag type bits or bytes that get set/reset/checked for program flow.
    sorry if explanation is messy.
    First get the main .1 second loop working (blink/toggle an led as an indicator) then add in your code relying on the .1 second looping time.


    http://www.picbasic.co.uk/forum/asse...1&d=1311957346
    Attached Images Attached Images  

Similar Threads

  1. Replies: 6
    Last Post: - 28th October 2014, 06:08
  2. Do I need a pause?
    By tazntex in forum Serial
    Replies: 21
    Last Post: - 29th August 2008, 04:32
  3. 1 us delay
    By Pedro in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th February 2006, 17:28
  4. Pause
    By blue in forum General
    Replies: 7
    Last Post: - 29th December 2005, 14:24
  5. pause 0.5
    By detail in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 27th June 2005, 11:32

Members who have read this thread : 2

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