More Delay Problems
John Whitfield
Posts: 42
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
Thanks,
-John Whitfield
src
22K
Comments
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
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
Thanks,
-John Whitfield
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
Thanks,
-John Whitfield
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
OUt of curiosity, I will take you·up on the offer....could you explain what the RTOS is, it's main purpose etc?
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
I will take a careful read this weekend.
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)