Delay without using pause


Closed Thread
Results 1 to 40 of 43

Hybrid View

  1. #1
    Join Date
    Oct 2009
    Posts
    583

    Default Delay without using pause

    I'm developing one of my old projects and I've hit a stumbling block. The old code simply read 4 x DS18B20's and use the data to control the out put to a heat via Henrik's PID routine. It's been working fine for 5 years now, but I want to add 4 x AM2302's to monitor the humidity and also monitor the temperature in its location. The code includes DT's interrupts, DS18B20, and all digital "library files", and thus a lot of the timings for the period each heater is on is done in the background, and the main code consists of a simple loop that reads the sensors and does the maths.

    However with four sets of information for each of the four viavriums the 20 x 4 LCD is becoming a little crowded. So what I really want to do is to display Viv(x), temp1, humidity1, temp2 on a single line on the LCD. No problem in coding the line to do this, but as the program runs so fast through the data it's impossible to read. The simple way is to add a pause statement so for example the code pauses for 2 seconds before retuning to the main program loop and advancing on to the next set of data. But this then delays the speed at which the probes are monitored and by the time the loop is back to probe 1 the temperature could of gone past the set point, as it's not monitored in real time.

    My hair is now white, and I'm half bald trying to resolve this - the nearest I came was to use some form of counting loop within the main loop, that when it tripped over a set value it increased the value of viv(x) by one, so in essence the main code ran at real time speed, but the LCD was only updated every second or so and thus wouldn't hold up the realtime monitoring. Unless any of you guys can come up with a better suggestion

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


    Did you find this post helpful? Yes | No

    Default Re: Delay without using pause

    Hi Malcom,
    Real time in Human terms is as fast as you can read. Who cares if the machine detects something faster, you cannot respond that fast, so the LCD is much like watching the evening news. What you "might" do is allow "the machine" to run several cycles and then report via LCD the average of those cycles.
    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.

  3. #3
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: Delay without using pause

    Malcolm,

    I think you're on the right track.

    something like this?

    Code:
    LCDCount_Max con 3000   'Set to what you want
    
    LCDCount var word
    LCDUpdate var bit
    
    goto Main
    
    UpdateLCD:
        'do your LCD Update stuff here
        
        return
    
    Main:
        LCDCount = 1    'Used to display the first time        
    
    CycleLoop:
        if LCDUpdate then
            gosub UpdateLCD
            LCDUpdate = 0
        endif
        
        ''do your normal polling stuff here
       
       '' Then do the LCD test stuff here
        LCDCount = LCDCount - 1
        if LCDCount = 0 then
            LCDCount =  LCDCount_Max
            LCDUpdate = 1
        endif 
    
    
        goto CycleLoop
    Regards,
    TABSoft

  4. #4
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Delay without using pause

    Cheers Ken,

    I'll have a play..... failing that I'll look for an 40 x 4 LCD which might make things easier

  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

    Thanks so much amgen, i want to give this a try, looks much simpler. i am trying to convert the flowchart you posted to code, i will let u know how it turns out.

    i will see if my original trial will even compile at all :-), then i will make comparisms

    i want to be able to write more efficient code. one nice tool that has helped me to compare execution times of various methods of coding is DARREL TAYLOR's instruction time calculation code...

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default Re: Delay without using pause

    Hi, Malc

    I don't remember your program, but why not use the time the DS1820s make their measure/conversion to update the LCD, instead of waiting for conversion complete ???

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  7. #7
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: Delay without using pause

    Malcolm,

    You could also do this via a Timer Interrupt using DT's Instant Interrupts.
    Say, Timer2 (8bit timer) with both a Prescaler and Postscaler, then in the ISR decrement a word variable that is preset to a number that gets you to 3 seconds or whatever time you want. When the var reaches zero set a flag to run the display routine and reset the word var back to your preload value. In your main loop test for the flag and call the display routine if set and then clear the flag.

    This would allow you to hit a time-based delay much easier.
    Regards,
    TABSoft

  8. #8
    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

    Why not just count the number of data updates and after so many, Update the display with a different set of data? That way you won't slow down the data taking and control timing and you will get a "cycling" data display you want. That way there is no need for a delay of any type.
    Dave Purola,
    N8NTA
    EN82fn

  9. #9
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Delay without using pause

    Thanks for the suggestions guys.

    Dave, your suggestions sounds simple enough for me to understand. I guess I could have a variable that is updated every time the program goes around the main loop, then when it reaches a certain value display one set of data for the 1st probe, then when reaches another it displays the second set etc... I'll have a look at implementing that. I guess that provided the program doesn't loop more than 65535 times in 8 seconds then I will be able to use a word variable and each update would be visible for 2 seconds

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


    Did you find this post helpful? Yes | No

    Default Re: Delay without using pause

    Quote Originally Posted by Scampy View Post
    Thanks for the suggestions guys.

    Dave, your suggestions sounds simple enough for me to understand. I guess I could have a variable that is updated every time the program goes around the main loop, then when it reaches a certain value display one set of data for the 1st probe, then when reaches another it displays the second set etc... I'll have a look at implementing that. I guess that provided the program doesn't loop more than 65535 times in 8 seconds then I will be able to use a word variable and each update would be visible for 2 seconds
    And . . . . if you average several samples of each you would see it displayed longer, side bonus a "flier" reading would not upset you as much when averaged than it will if not averaged or discarded.
    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.

  11. #11
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    644


    Did you find this post helpful? Yes | No

    Default Re: Delay without using pause

    Quote Originally Posted by Scampy View Post
    I guess that provided the program doesn't loop more than 65535 times in 8 seconds then I will be able to use a word variable and each update would be visible for 2 seconds
    Since you are using DT interrupts, another approach would be to use a variable to count every time the program goes to the interrupt routine. After so many hits, then you update the LCD display. Depending on how long you set the time intervals for the interrupts, this might be a "cleaner" solution.
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

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


    Did you find this post helpful? Yes | No

    Post Re: Delay without using pause

    hi all, i have been scratching my head thinking of how to avoid pbp pause in my routines bcos the command;

    1) seems to change system registers (correct me if i'm wrong),
    2) is the main cause of many problems i have had with ISR's in the past
    3) is blocking, i dont want to waste cycles

    i have been trying to make sense of the previous posts in this thread. pls can someone help with a robust snippet.

    i think of a delay based on an interrupt timer that serves as the heartbeat with a resolution of say 1us. in the isr, multiple regs (each loaded when needed from various routines) are decremented to act as counters, when anyone hits zero a corresponding flag is set etc...

    am i making any sense? i think this is simillar to how some rtos work. is there a better way?

  13. #13
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Delay without using pause

    Hi,

    > 1) seems to change system registers (correct me if i'm wrong),

    What do you mean with system registers? If you mean the PBP system variables then yes, it has to use something to keep track of time - in the same way as you suggest in your method and the compiler uses its internal variables for that. But I don't really see the problem, are you using the system variables in your code?


    > 2) is the main cause of many problems i have had with ISR's in the past

    How are you "doing" your interrupts and what problems are we talking about?
    If you're spending a lot of cycles in your ISR then a PAUSE in the main program won't be accurate because the main program isn't really executing at the desired speed due to the interrupt "stealing" time away from it. If you're using a PAUSE in the ISR then of course the main program will "halt" during that period.

    > 3) is blocking, i dont want to waste cycles

    It is. Just like all PBP commands.

    > i think of a delay based on an interrupt timer that serves as the heartbeat with a resolution of say 1us. in the isr, multiple regs (each loaded when needed from various routines) are decremented to act as counters, when anyone hits zero a corresponding flag is set etc...

    The overall idea is doable but forget 1us resolution. Even at 64MHz there would only be 16 instructions between each interrupt - perhaps you could manage ONE timer if written in tight ASM but then there wouldn't be much time left for anything else. Depending on the oscillator speed and the number of timers you want to maintain 100us or 1ms might be more appropriate, 10ms certainly doable.

    /Henrik.

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


    Did you find this post helpful? Yes | No

    Default Re: Delay without using pause

    Thank so much Henrick,

    i am so glad that someone understood what i was trying to say. Elated to hear that it is doable even in the ms range.

    But to answer some of your questions:

    1) By system registers i was thinking that pbp must setup some timers for counting during pause. And this might affect my timers usage.

    2) how i am doing my interrupts. I use DEFINE INTHAND _MYISR1

    Then after saving contexts in asm i do an endasm and gosub a pbp routine. I don't know how to upload a code yet. I would have shown you.

    But at any rate, the results are usually erratic and it seems as if the code is making jumps to the wrong places. On certain ocassions i found out that if i use a timer interupt to delay something rather than pause, the system will work better.

    3) Now since pause is blocking, "just like all pbp commands" (never thought if this) if i can get a way to rig up a macro that i can use such as

    @ myPAUSE msec,SUBNAME

    where msec is the no of ms to delay and SUBNAME is used to keep track of the specific registers to use (i.e the sub that is calling for a delay).

    My problem is: can i call a pbp routine inside asm macro.

    I like to use pbp if statements to in a state-machine-like manner, makes programming more structured. If i can have another type of PAUSE that will simply load a reg and move... i think this will make code more efficient

    Thanks so much.

  15. #15
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Delay without using pause

    Hi,
    1) By system registers i was thinking that pbp must setup some timers for counting during pause. And this might affect my timers usage.
    No, not at all. The PAUSE and PAUSEUS commands does not use any hardware peripherals (ie timers) on the PIC, it's done in software which is why it's blocking. Basically it sits in a loop, counting cycles.

    2) how i am doing my interrupts. I use DEFINE INTHAND _MYISR1

    Then after saving contexts in asm i do an endasm and gosub a pbp routine. I don't know how to upload a code yet. I would have shown you.

    But at any rate, the results are usually erratic and it seems as if the code is making jumps to the wrong places. On certain ocassions i found out that if i use a timer interupt to delay something rather than pause, the system will work better.
    OK, so there's your problem I think. If you use ASM for your interrupt service routines you can (generally) not use PBP code within the ISR (using a GOSUB does not matter). Why? Because PBP uses its internal system variable for its various commands, if your main program is in the middle of comlex math operation it stores intermediate results in its internal variables and along comes an interrupt. If you then place PBP commands in the ISR chanses are that code wants to use the same internal system variables which will the corrupt the complex math operation that the main program was in the middle of calculating.

    If you want to use PBP within your interrupt servie routine you need to either:

    A) Use ON INTERRUPT - with its drawbacks.
    B) Write the code for the handler, compile and assemble it. Examine the .lst file and determine which of the system variables are being used and then add code to save and restore those registers on ISR entry/exit.
    C) Use Darrel Taylors Instant Interrupt routines. What it does is save and restore ALL PBP system variables on entry/exit. It comes at a cost of interrupt latency (it takes time to save all the registers).

    I've used all three of the above aproaches. By far, option C is "the best". I very very rarely use A. B I've used for stuff where the ISR is simple and I've really needed the speed. Just remember that with option B you need to be very careful, any change to ISR and you need to re-examin the generated code to see if any new PBP system variables are beinng used.

    3) Now since pause is blocking, "just like all pbp commands" (never thought if this) if i can get a way to rig up a macro that i can use such as

    @ myPAUSE msec,SUBNAME

    where msec is the no of ms to delay and SUBNAME is used to keep track of the specific registers to use (i.e the sub that is calling for a delay).

    My problem is: can i call a pbp routine inside asm macro.
    I don't quite follow you with the macro thing (I truly suck at the ASM stuff) but if you mean calling a PBP subroutine from within an ASM interrupt service routine then generally NO, absolutely not.

    /Henrik.

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


    Did you find this post helpful? Yes | No

    Default Re: Delay without using pause

    THIS IS AN EYE OPENER.

    Thanks so much for explaining. Now i understand why it didnt work. I have learn a great deal from your post.

    Thanks for the tips, i think option B is what I will go for. Its worth the effort.
    But how can i determine from the .lst, the system variables in use.

    I have used DT Interrupts and they work well (apart from inadvertenly enabling unwanted interrupts sometimes). But to avoid saving every variable all the time and save time is my goal. I need to have more speed.

    Lastly, my question about macros. Can i do something like this;

    Asm
    MACRO myPAUSE msec,subID
    movlw msec
    movwf delay1
    movlw subID
    movwf KeepTrack
    Endasm

    ; then concote any kind of PBP code here

    @ Endm

  17. #17
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: Delay without using pause

    Lastly, my question about macros. Can i do something like this;

    Asm
    MACRO myPAUSE msec,subID
    movlw msec
    movwf delay1
    movlw subID
    movwf KeepTrack
    Endasm

    ; then concote any kind of PBP code here

    @ Endm
    no

    macro is a assembler feature and will not accept pbp code.
    pbp code needs to be compiled and then assembled

    post some code and explain what you are trying to achieve

  18. #18
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: Delay without using pause

    I modified dt's Elapsed_INT-18.bas file so I could use the "Ticks" as a millisecond counter function (like millis() in arduino C ) it rolls over every 65 seconds but using unsigned integer subtracts its very handy for short interval timing and has no blocking issues . the fairly low interrupt rate minimises effect on normal pgm throughput.

    I'm sure Elapsed_INT-14.bas is easily adapted to match , but I have no copy of it




    Code:
    '***************************************************************************
    '*  Name    : Elapsed_INT-18.bas                                           *
    '*  Author  : Darrel Taylor                                                *
    '*  Date    : JUL 11, 2006 : 7/11/2010                                     *
    '*  Version : modified to use ticks useable  as a millisecond   counter                                                      *
    '*  Notes   : Must have DT_INTS-18.bas loaded first                        *
    '*   ver 1.2: Now works at any OSC frequency without using the prescaler   *
    '***************************************************************************
    DISABLE DEBUG
    
    ; syntax =     Handler  IntSource,        Label, Type, ResetFlag?
    DEFINE  Elapsed_Handler  TMR1_INT,  _ClockCount,  asm,  yes
    ; the above define can be used in the INT_LIST macro, if desired (optional)
    
    Ticks            VAR word   ; Counts timer Overflows
    T1Post           VAR BYTE   ; Timer1 postscaler
    Seconds          VAR BYTE
    Minutes          VAR BYTE
    Hours            VAR BYTE
    Days             VAR WORD
    
    SecondsChanged   VAR BIT    ; idicates that the value has changed
    MinutesChanged   VAR BIT
    HoursChanged     VAR BIT
    DaysChanged      VAR BIT
    
    GOSUB ResetTime             ; initialize the Elapsed Timer
    
    Goto OverElapsed            ; skip over the routines
    
    ' -------------- calc timer reload Constants -------------------------------
    ASM
    T1PS = 1                             ; start with 1:1 postscaler
    TimerConst = ((OSC*1000000)/4/100)   ; how many timer ticks will it take
      while TimerConst > 65400           ; if it's more than the timer can count
    T1PS = T1PS * 2                      ;   double the postscaler
    TimerConst = TimerConst / 2          ;   halve the count
      endw
    TimerConst = 65536 - TimerConst + 6  ; final reload value   !!!!! was 8 but clk runs fast
      
      
    ; -----------------  ADD TimerConst to TMR1H:TMR1L -------------------------
    ADD2_TIMER   macro
        BCF     T1CON,TMR1ON, 0       ;  1 Turn off timer
        MOVLW   LOW(TimerConst)       ;  1
        ADDWF   TMR1L,F, 0            ;  1    
        BTFSC   STATUS,C              ;  1/2
        INCF    TMR1H,F, 0            ;  1
        MOVLW   HIGH(TimerConst)      ;  1
        ADDWF   TMR1H,F, 0            ;  1
        endm
    
    ; -----------------  ADD TimerConst to TMR1H:TMR1L and restart TIMER1 ------
    RELOAD_TIMER  macro
        ADD2_TIMER
        BSF     T1CON,TMR1ON, 0       ;  1   Turn TIMER1 back on  (8 cycles)
        endm
    
    ; -----------------  Load TimerConst into TMR1H:TMR1L ----------------------
    LOAD_TIMER  macro
        MOVE?CT  0, T1CON,TMR1ON
        MOVE?CB  0, TMR1L
        MOVE?CB  0, TMR1H
        ADD2_TIMER
        endm
    ENDASM
    
    ' ------[ This is the Interrupt Handler ]-----------------------------------
    T1PS  CON EXT
    ClockCount:
    @ RELOAD_TIMER                   ; Reload TIMER1
    
        T1Post = T1Post + 1
       
        IF T1Post = T1PS THEN
      
         T1Post = 0
        
        Ticks = Ticks + 1
          
           IF Ticks //100 ==0 THEN
          
    '          Ticks = 0           Seconds = Seconds + 1
               SecondsChanged = 1
               IF Seconds = 60 THEN
                  Seconds = 0
                  Minutes = Minutes + 1
                  MinutesChanged = 1
               ENDIF
               IF Minutes = 60 THEN
                  Minutes = 0
                  Hours = Hours + 1
                  HoursChanged = 1
               ENDIF
               IF Hours = 24 THEN
                  Days = Days + 1
                  DaysChanged = 1
                  Hours = 0
               ENDIF
           ENDIF
        ENDIF
    @ INT_RETURN                     ; Restore context and return from interrupt
    
    '-----====[ END OF TMR1 Interrupt Handler ]====-----------------------------
    
    StartTimer:
        T1CON = 1                    ; 1:1, FOSC4, TMR1ON
    RETURN
    
    ; --------------------------------------------------------------------------
    StopTimer:
        T1CON.0 = 0                  ; Turn OFF Timer1
    RETURN
    
    ; --------------------------------------------------------------------------
    BitSave  VAR  BIT
    
    ResetTime:
        BitSave = T1CON.0            ; Save TMR1ON bit
    @   LOAD_TIMER                   ; Load TimerConst
        T1CON.0 = BitSave            ; Restore TMR1ON bit
        T1Post = 0                   ; clear the postscaler
        Ticks = 0
        Seconds = 0
        Minutes = 0
        Hours = 0
        Days = 0
        SecondsChanged = 1           ; indicate everything has changed
        MinutesChanged = 1           ; so that 00:00:00 is processed
        HoursChanged = 1
        DaysChanged = 1
    RETURN
    
    
    OverElapsed:
    ENABLE DEBUG

  19. #19
    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.

  20. #20
    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

  21. #21
    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

  22. #22


    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

  23. #23
    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

  24. #24


    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