Shop OBEX P1 Docs P2 Docs Learn Events
More Delay Problems — Parallax Forums

More Delay Problems

John WhitfieldJohn Whitfield Posts: 42
edited 2005-06-26 18:23 in General Discussion
This code is supposed to delay for about seven seconds, but it seems to delay closer to four seconds, does anybody know why that might be?

Thanks,
-John Whitfield

Comments

  • David BDavid B Posts: 592
    edited 2005-06-15 21:57
    Well, something is not right with the code. I plugged 1,1,1 into d1, d2 and d3, expecting that the delay would run 10101 loops, but it returned right away. Maybe somebody smarter than me can explain what this code is doing.

    But why not code a delay in a form that is easier to understand and debug, like these? They're not real accurate, especially with interrupts running, but they may be close enough for your purposes:

    delay5s
    mov d4, #50
    :loop call delay100ms
    djnz d4, :loop
    retp

    delay100ms
    mov d3, #100
    :loop call delay1ms
    djnz d3, :loop
    retp

    delay1ms ; delay 1007 usec @ 50 mHz
    mov d2, #49
    :loop1 mov d1, #0
    :loop2 djnz d1, :loop2
    djnz d2, :loop1
    retp

    David
  • NateNate Posts: 154
    edited 2005-06-16 02:38
    Basic Math:·

    50Mhz resonator.

    25,000,000·clock cycle·delay routine (_delay_0s5) gives 0.5 sec delay.

    Call _delay_0s5·eleven times (as is done in _delay_5s5) and you get a 5.5 second delay.·

    This code has the spagetti look of something that was produced by SX/B, but still, why in the world·did you·expect to get a 7 second delay from this code?



    Nate

    PS The code is fine.· A '1' put in d1, d2, d3 will cause the delay routine to drop straight through and return immediately.·



    ·*****EDIT··· I think perhaps I'm being a little harsh.· If you put a $ in front of the 11 in the _delay_5s5 it would give you a 17 (decimal), which would then give you a 8.5 second delay.·· *******




    Post Edited (Nate) : 6/16/2005 3:00:19 AM GMT
  • John WhitfieldJohn Whitfield Posts: 42
    edited 2005-06-20 00:14
    The reason I was saying the total delay should be around seven seconds is because I call the 0.5 second delay a couple of other places than just within 5.5 second delay routine. I am not sure what you advice was so I cleared the variables at the beginning of the delay routines which is probably wrong. And as sad as it is to say the code was always written in assembly. Here is the updated code.

    Thanks,
    -John Whitfield
  • NateNate Posts: 154
    edited 2005-06-20 01:42
    John,

    You don't need to clear the variables before the delay routine, as you initalize them at the start of the delay routine anyhow.· Your .5 second routine·will give you a .5 second delay (or pretty close) if you are runing with a 50 MHz resonator.· If you want a seven second delay, you will need to call the .5 second delay 14 times in a row.· Where exactly (in the code) do you want the seven seond delay to happen?

    Nate
  • John WhitfieldJohn Whitfield Posts: 42
    edited 2005-06-24 20:47
    I would like small delays of 0.5 seconds after each code is sent to the speakjet, though program will not run with them in certain places, so the places throughout the program where they are inserted are the ones that allow the program to still work. So, I would like a longer delay at the end of the program to allow the user to have a gap before the next codes are spoken to make the entire thing more understandable. I thought the 5.5 second delay would be enough, and it should be, but from the beginning of one code being said to the beginning of the next is around four seconds. So I don't know if this is because it is getting caught somewhere and reseting itself or if there is some other problem. Maybe I should just increase the number of times it calls the 05 second delay, but that still doesn't explain why the delay runs for a far shorter amount of time then what the math says it should.

    Thanks,
    -John Whitfield
  • pjvpjv Posts: 1,903
    edited 2005-06-24 21:32
    Hello John;

    This all becomes very simple if you would just use the "simple non pre-emptive RTOS" I have developed (there is also a more complicated pre-emptive one). See my source code post of March 29, as well as my second contest entry regarding the prototype development board. That·gives an example of how to use it by generating two independent sine waves.

    This RTOS is so simple, I can't understand why anyone needing any type of delay or sequencing or scheduling does not use it. It will solve all those kind of problems.

    If you need more help, I will give some further pointers.

    Cheers,

    Peter (pjv)

    Post Edited (pjv) : 6/24/2005 9:38:55 PM GMT
  • KenMKenM Posts: 657
    edited 2005-06-25 03:39
    Peter,
    OUt of curiosity, I will take you·up on the offer....could you explain what the RTOS is, it's main purpose etc?
    Ken
    pjv said...


    This RTOS is so simple, I can't understand why anyone needing any type of delay or sequencing or scheduling does not use it. It will solve all those kind of problems.

    If you need more help, I will give some further pointers.

    Cheers,

    Peter (pjv)
  • pjvpjv Posts: 1,903
    edited 2005-06-25 16:54
    Hi Ken;

    If you read my SX contest entry (there are two different ones) regarding the Preemptive RTOS, it gives a reasonable explanation as to the purpose. Although for many simple applications pre-emptive is not required, and my other non-preemptive RTOS which is a lot simpler, is good enough. That one is described in the other contest entry regarding a Development board. It contains a very good example (in my opinion) of how to use it, as well as how to make sine waves of any (almost) arbitrary frequency. For that matter, almost any waveform could be generated by simply altering the values in the look-up table.

    Cheers,

    Peter (pjv)

    Post Edited (pjv) : 6/26/2005 5:10:20 AM GMT
  • KenMKenM Posts: 657
    edited 2005-06-25 16:55
    Thanks Peter,

    I will take a careful read this weekend.

    Ken
  • pjvpjv Posts: 1,903
    edited 2005-06-26 18:23
    Hi Ken;

    I highly reccommend studying the sample program in detail, and single stepping it using the SX Key.

    Please do remember that the SX Key often does not like to single-step from the mainline into the interrupt routine; it depends on previous stepping conditions.

    Regardless, if you set the break in the mainline at the entry into the RTOS (on clearing the interrupt flag), and single step from there, I'm sure the RTOS operation will become crystal clear, and it's relevance become evident.

    Let us know how you make out.

    Cheers,

    Peter (pjv)
Sign In or Register to comment.