Nigel, timing of tut7_1.asm

I have studied your tutorial 7 on RS232. I have a little bit unclear about the timing of XMIT.

Code:
Ser_Loop    RRF     Xmit_Byte , f         ;send one bit
            BTFSS   STATUS    , C
            BCF     SER_PORT, SER_OUT
            BTFSC   STATUS    , C
            BSF     SER_PORT, SER_OUT
            CALL    Bit_Delay
            DECFSZ  Bit_Cntr  , f         ;test if all done
            GOTO    Ser_Loop
            BSF     SER_PORT, SER_OUT
            CALL    Bit_Delay
            RETURN

where Bit_Delay is

Code:
Bit_Delay   MOVLW   0x18
            MOVWF   Delay_Count
Bit_Wait    NOP
            DECFSZ  Delay_Count , f
            GOTO    Bit_Wait
            RETURN

From my calculation, Bit_Delays takes 2 + (Bit_Wait) 95 + (Return) 2 = 99 instructions cycles.
and Thus,
Code:
RRF	1
BTFSS	1
BCF	1
BTFSC	1
BSF	1
CALL Bit_Delay	2 + 99
DECFSZ	1
GOTO	2

Ser_Loops takes 1 +4 + 2 + 99 + 1 + 2 = 109

Instead of 109, 104 is given in your tutorial.

I wonder, if my calculation is wrong, or the error is within the tolerance range, and thus 109 is acceptable.

Thanks
 
The actual routine is from a very old Parallax application note, written using their own assembler - I simply converted it to use MicroChip assembler, and have been using it for MANY years. I've never actually sat down and analysed it.

For using the same routine at 20MHz, I actually added a pulse output on an I/O pin, and used a scope to display the actual sampling point - then adjusted the delay timing so it fell in the middle of the bits.

The timing at 9600 baud isn't critical, you have a fair amount of time to play with.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…