??? 05/24/06 03:30 Read: times |
#116998 - wrong calculation of timer delay ... |
SUBROUTINE 1
DELAYMS: ;millisecond delay routine | MOV R7,#00H ;put value of 0 in register R7 LOOPA: INC R7 ;increase R7 by one (R7 = R7 +1) MOV A,R7 ;move value in R7 to Accumlator (also known as A) CJNE A,#0FFH,LOOPA ;compare A to FF hex (256). If not equal go to LOOPA RET ;return to the point that this routine was called from THIS ABOVE SUBROUTINE HAS 7 CYCLE, EACH MACHINE CYCLE TAKES 1 MICOSECOND SO TOTAL OF 1027 APROX, FOR 256 VALUE's OF R7 FROM 0 TO 255 SO THE ABOVE SUBROUTINE WILL TAKE APROX 1 MILLISECONDS ... ***************************************************************;************************************************************************** THE BELOW SUBROUTINE2 WILL TAKE 14 CYCLES IN 1 STEP ... Sir for the 1st subrt my calculations of aprox 1 milliseconds are correct but for the below I am facing so much probs ... In PINNACLE the total time elapsing is .5716670 seconds ie. half a second ... but according to my cal it is coming ... 3.153920 ... if I just take 512 as the cycles in the below subrt and multiply it to 1027 then its giving me approx .5 seconds ie equal to PINNALCE ... but Sir besides counting from 0 to 255 by R6 there are other cycles also which should be taken into consideration like ... LOOPB: INC R6 ;increase R6 by one (R6 = R6 +1) ; TAKES 1 CYCLE ACALL DELAYMS ;call the routine above. It will run and return to here. ; TAKES 2 CYCLES MOV A,R6 ;move value in R6 to A ; TAKES 1 CYCLE JNZ LOOPB ; TAKES 2 CYCLES ... so extra of 6 cycles are coming aprox ... but the OUTPUT is coming exactly calculating 256 * 2=512 ===> 512 * 1027 ===> 525824 ... ie .5 seconds ... or half second *************************************************************************************************************************** SUBROUTINE 2 DELAYHS: ;half second delay above millisecond delay MOV R6,#00H ;put 0 in register R6 (R6 = 0) MOV R5,#002H ;put 2 in register R5 (R5 = 2) LOOPB: INC R6 ;increase R6 by one (R6 = R6 +1) ACALL DELAYMS ;call the routine above. It will run and return to here. MOV A,R6 ;move value in R6 to A JNZ LOOPB ;if A is not 0, go to LOOPB DEC R5 ;decrease R5 by one. (R5 = R5 -1) MOV A,R5 ;move value in R5 to A JNZ LOOPB ;if A is not 0 then go to LOOPB. RET Sir please reply me why its happening so ... |
Topic | Author | Date |
wrong calculation of timer delay ... | 01/01/70 00:00 | |
Comments | 01/01/70 00:00 | |
Russel Sir ... have a look again pl | 01/01/70 00:00 | |
Yes I'm looking | 01/01/70 00:00 | |
Russell Sir ... once again have a look | 01/01/70 00:00 | |
I'm still looking! | 01/01/70 00:00 | |
Try this: | 01/01/70 00:00 | |
Sometimes a Calculator helps![]() | 01/01/70 00:00 |