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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
02/01/05 22:07
Read: times


 
#86325 - not wrong, since it is tested !
Responding to: ???'s previous message
Dear Erik,

I'm really astonished, why you not see, what is obvious.

Again, loading and counting are not the same !

And on the 8051 both are done in different clock cycles of the 12 xtal clocks of every CPU cycle, so no interference can occur.

Following an example code, which read a counter with two ways, the XCH way works right but the MOV way works wrong as I already expected it.

Thus after the second routine was finished only the P1.7 was set.

The only difference, this example code use mode 1 and not mode 3. But this make no difference, if an overflow from the low byte increment the high byte or set the overflow flag.

        mov     p1, #0
        mov     tmod, #1        ; T0: Mode 1
        setb    tr0             ; run TR0

        mov     r0, #0F0h
m1:     mov     tl0, r0
        mov     th0, #0
        mul     ab              ; 4 cycle delay

        clr     a
        xch     a, tl0          ; read and clear simultaneous !!!
        mov     r7, a
        mov     r6, th0

        cjne    r6, #0, m2      ; >= 256
        cjne    r7, #0F0h, m3
m3:     jnc     m4              ; >= 0F0h
        setb    p1.4            ; error, val < 000F0h
        sjmp    m4
m2:     cjne    r7, #020h, m5
m5:     jc      m4
        setb    p1.5            ; error, val > 00120h
m4:     inc     r0
        cjne    r0, #0FCh, m1

        mov     r0, #0F0h
m11:    mov     tl0, r0
        mov     th0, #0
        mul     ab              ; 4 cycle delay

        mov     a, tl0          ; read
        mov     tl0, #0         ; clear to late !!!
        mov     r7, a
        mov     r6, th0

        cjne    r6, #0, m12     ; >= 256
        cjne    r7, #0F0h, m13
m13:    jnc     m14             ; >= 0F0h
        setb    p1.6            ; error, val < 000F0h
        sjmp    m14
m12:    cjne    r7, #020h, m15
m15:    jc      m14
        setb    p1.7            ; error, val > 00120h
m14:    inc     r0
        cjne    r0, #0FCh, m11

        sjmp    $
end



I tested it with the simulator and the real target (AT89C4051) and all what I can tell is, that the result was exact this, what I tried to tell you alle these posts above.

Now I'm unable to do more.

Please check it the next time, before you tell, that something was wrong.


Naturally there exist other ways to read a timer on the fly.
And also it is possible to stop the timer and perform a 16 bit addition to correct the timer value by the cycle count, during which the timer was stopped.
But all these ways need more code.


Peter


List of 30 messages in thread
TopicAuthorDate
help with duty cycle measurement            01/01/70 00:00      
   woefully incomplete            01/01/70 00:00      
      Definitions            01/01/70 00:00      
         gobbelygook            01/01/70 00:00      
   Routines            01/01/70 00:00      
   sorry for the gobbelygook            01/01/70 00:00      
      A job for the PCA?            01/01/70 00:00      
      now that is clear            01/01/70 00:00      
      4 errors found in your smt_1.asm pgm            01/01/70 00:00      
         maybe only 3            01/01/70 00:00      
   cannot change            01/01/70 00:00      
   SMT160 example code in C            01/01/70 00:00      
      why            01/01/70 00:00      
         It is absolute necessary !            01/01/70 00:00      
            on the fly            01/01/70 00:00      
               Thus I use assembler !            01/01/70 00:00      
                  not assembler but int            01/01/70 00:00      
                     It must be XCH !            01/01/70 00:00      
                        still wrong to read with running            01/01/70 00:00      
                           not wrong, since it is tested !            01/01/70 00:00      
                              OK            01/01/70 00:00      
            Thanks to all            01/01/70 00:00      
   Thanks Peter            01/01/70 00:00      
      Do some simple tests first            01/01/70 00:00      
         Problem solved But            01/01/70 00:00      
   Modified code and mistakes            01/01/70 00:00      
   smt160.asm example            01/01/70 00:00      
      Thanks for example            01/01/70 00:00      
   Please explain            01/01/70 00:00      
      Yes            01/01/70 00:00      

Back to Subject List