Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
08/01/05 14:20
Read: times


 
#98595 - My old solution:
Responding to: ???'s previous message
On my former assembler days I used this:

;************************************************************************/
;*									*/
;*		Macro to waste a defined count of cycles		*/
;*                                                                      */
;*              Author: Peter Dannegger                                 */
;*                      danni@specs.de                                  */
;*									*/
;************************************************************************/

;macro parameters
;1.parameter:	count of cycles (1 ... 65535)
;2.parameter:	1. used register: default R7
;3.parameter:	2. used register (on delay > 515): default R6

mdelay	macro value, rx, ry	;cycle, used register(s)
	  local m____1
	  if( value < 5 )
	    rept value
	      nop
	    endm
	  elseif( value < 515 )
	    if nul &rx
	      mov r7, #low((value-1)/2)
	      djnz r7, $
	    else
	      mov rx, #low((value-1)/2)
	      djnz rx, $
	    endif
	    if((value and 1) = 0)
	      nop
	    endif
	  else
	    if nul &rx
	      mov r7, #high(value/2+253)
	      mov r6, #low(value/2-2)
m____1:	      djnz r6, m____1
	      djnz r7, m____1
	    else
	      mov rx, #high(value/2+253)
	      mov ry, #low(value/2-2)
m____1:	      djnz ry, m____1
	      djnz rx, m____1
	    endif
	    if(value and 1)
              nop
            endif
	  endif
	endm


http://home.tiscali.de/peterd/ap...mdelay.mac

There is no need for additional assembler instructions. Simple let the assembler calculate the right preload values for the counting registers.
The limitation until 65535 cycle was given by the assembler. But this is no drawback, because for longer delays a timer should always be the better approach. Since the title is real, the cycles are always wasted and thus mostly another task exist, which can already be done during delays above 65535 cycle.


Peter


List of 32 messages in thread
TopicAuthorDate
This weeks puzzle            01/01/70 00:00      
   This weeks Puzzle            01/01/70 00:00      
   its D-J-N-Z not J-N-Z-D            01/01/70 00:00      
   inc r6            01/01/70 00:00      
      Fails if R6 is Zero            01/01/70 00:00      
   in my point of view :            01/01/70 00:00      
   not correct question            01/01/70 00:00      
   LSB count value lost in first count            01/01/70 00:00      
   Setup R6/R7            01/01/70 00:00      
      why +1?            01/01/70 00:00      
   this is no fun            01/01/70 00:00      
      Thread closed            01/01/70 00:00      
   It is easy Erik!            01/01/70 00:00      
   Ok, you blew it            01/01/70 00:00      
      Not our mistake...            01/01/70 00:00      
         which was done again and again for the i            01/01/70 00:00      
            which the most of might never have noti            01/01/70 00:00      
               Well...            01/01/70 00:00      
                  well,well            01/01/70 00:00      
                  The explanation is:            01/01/70 00:00      
                     Never the intention            01/01/70 00:00      
                     Thoughts            01/01/70 00:00      
                        I really do not know            01/01/70 00:00      
                        discussion after the solution            01/01/70 00:00      
                           Agree            01/01/70 00:00      
                        Please, no sophisticated forum rules!            01/01/70 00:00      
                           agree            01/01/70 00:00      
      Never mind            01/01/70 00:00      
   My old solution:            01/01/70 00:00      
      constant            01/01/70 00:00      
         Re: constant            01/01/70 00:00      
   Re-Cap            01/01/70 00:00      

Back to Subject List