Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Sync Problem

Status
Not open for further replies.

Marc_Urito

New Member
HI, to all, I am new here and new to this world of PICS.

Well my problem is I am trying to sync a PIC 12C509A with the data stream coming through the cable line, What I mean the PIC used to sync the data(Rx and TX), but not anymore, I made a log with a software called bit logger just to see where the changes where made, and what i found was that the life time of the stop bit is not anymore 34us, now is 36us, the asm has several delays, I have made all kind of changes with no success, somebody told me that what I need is a PIC with 8MHZ and not this pic that has 4MHZ, I really don't know what more to do, this is driving me crazy and I know there is a change in the protocol to be made but I just don't know how to do it. Please Help. I am attaching this part of the asm.

Code:
;----- SYNCHRONOUS TRANSMIT / RECEIVE ROUTINE -----------------------------   

SYNCTX
 BSF     TEMPSTAT,4
 BSF     TEMPSTAT,5
 MOVWF   XMITHREG        ; MOVE BYTE IN W TO HOLDING REGISTER

RECVBYTE

CHECKSTART               ; WAIT FOR START BIT IN EXTSYNC

 CLRF    GPIO
 BSF     GPIO,4
 BSF     GPIO,5

WAITFORSTOPBIT

 BTFSC   GPIO,GP1
 GOTO    WAITFORSTOPBIT          ; CHECK GP1 FOR 0

WAITFORRISE

 BTFSS   GPIO,GP1
 GOTO    WAITFORRISE     ; CHECK GP1 FOR 1
 BSF     GPIO,GP0
 MOVLW   4           ; 17 CYCLE DELAY
 MOVWF   DELAYCOUNT

QTRBITLOOP

 DECFSZ  DELAYCOUNT,F
 GOTO    QTRBITLOOP
 BTFSS   GPIO,GP1        ; 18US IN TO WAVEFORM,
 GOTO    CHECKSTART      ; CHECK SA1 @ 1/4 THROUGH START BIT
 MOVLW   3
 MOVWF   DELAYCOUNT

HALFBITLOOP1

 DECFSZ  DELAYCOUNT,F
 GOTO    HALFBITLOOP1
 BTFSC   TEMPSTAT,3
 GOTO    SWITCHTIMEALIGN
 BTFSC   GPIO,BOOTSWITCH_PIN
 GOTO    SETCHMAPFLAG

SWITCHTIMEALIGN

 BTFSC   TEMPSTAT,3
 GOTO    IGNORESWITCH 

IGNORESWITCH

 INCF    LA0,F
 BTFSS   STATUS,Z
 GOTO    INCREMENTALIGN
 INCF    LA1,F

INCREMENTALIGN

 BTFSS   STATUS,Z
 GOTO    CHECKMAPPINGEND
 INCF    LA2,F

CHECKMAPPINGEND

 BTFSC   LA2,6               ;  EVERY 2MINUTES  ; 5   ; REFRESH EVERY 27 MINUTES
 GOTO    REFRESH
                 ; 2+34+18 CYCLES, 54 US = 3/4 START BIT
 BTFSS   GPIO,GP1        ; CHECK SA1 @ 3/4 THROUGH START BIT
 GOTO    CHECKSTART
 GOTO    SYNXINIT

XMITBYTE

 BSF     TEMPSTAT,4      ; TX DATA IS EMITTED
 BCF     TEMPSTAT,5      ; GENERATE SYNC FROM INTERNAL TIMEBASE
 MOVWF   XMITHREG        ; MOVE BYTE IN W TO HOLDING REGISTER
 MOVLW   19              ; DELAY LOOP FOR START BIT IN INTSYNC

SYNCTMR0WAIT             ; USING INTSYNC

 BTFSC   TMR0,7          ; WAIT FOR TIMER INITIATED START IN INTSYNC
 GOTO    SYNCTMR0WAIT
 BSF     GPIO,GP0        ; SET START BIT
 MOVWF   DELAYCOUNT

SYNXINIT             ; 9 CYCLES

 CLRWDT
 BCF     TEMPSTAT,6      ; CLEAR PARITY FLAG
 BCF     TEMPSTAT,7      ; CLEAR END FLAG
 MOVF    XMITHREG,W
 BTFSC   TEMPSTAT,4      ; /4 IS RX AND PASSTHROUGH, 4 IS RX AND TX INDEPENTLY
 ADDWF   CHECKSUM,F      ; UPDATE CHECKSUM IF IN TRANSMIT MODE
 COMF    XMITHREG,F      ; INVERT IT READY FOR TX
 BCF     PARITY,0        ; INITIALISE BIT 0 IN PARITY REGISTER TO 1
 MOVLW   8
 MOVWF   XMITBITCOUNT        ; SET BIT LOOP COUNTER FOR 8 INTERATIONS
 BTFSC   TEMPSTAT,5      ; TEMPSTAT5 = EXTSYNC / ~INTSYNC
 GOTO    WAITFORFALL     ; GOTO CHECK FOR STARTBIT IN EXTSYNC

INTSTARTLOOP

 DECFSZ  DELAYCOUNT,F
 GOTO    INTSTARTLOOP
 GOTO    READBYTE        ; GOTO START OF BIT PROCESSING LOOP

READBYTELOOP

 BTFSC   TEMPSTAT,5      ; CHECK AGAIN FOR SYNC MODE
 GOTO    TRANSITIONWAITSENSE     ; IF EXTSYNC GOTO WAIT FOR CLOCK TRANSITION

INTSYNC

 MOVLW   5           ; IN INTSYNC DELAY TO START OF CLOCK TRANSITION
 MOVWF   DELAYCOUNT

INTSYNCPARITYWAIT

 GOTO    INTSYNCLOOP     ; 2 CYCLE DELAY

INTSYNCLOOP

 DECFSZ  DELAYCOUNT,F    
 GOTO    INTSYNCLOOP
 GOTO    READBYTE        ; THEN GOTO BIT PROCESSING LOOP

TRANSITIONWAITSENSE          ; IN EXTSYNC CHECK EDGE OF CLOCK TRANSITION WE ARE LOOKING FOR

 BTFSS   GPIO,GP1
 GOTO    WAITFORONE

WAITFORFALL

 BTFSC   GPIO,GP1
 GOTO    WAITFORFALL
 GOTO    READBYTE

WAITFORONE

 BTFSS   GPIO,GP1
 GOTO    WAITFORONE
 GOTO    READBYTE

READBYTE             ; MAIN BIT PROCESSING LOOP

 COMF    GPIO,F          ; INVERT OUTPUT FOR CLOCK TRANSITION
 MOVLW   7               ; DELAY 18 CYCLES FOR CLOCK HALF OF BIT CELL
 MOVWF   DELAYCOUNT

CLOCKBITLOOP         

 DECFSZ  DELAYCOUNT,F    
 GOTO    CLOCKBITLOOP
 BTFSC   TEMPSTAT,7
 GOTO    ENDSYNCTX
 BTFSC   TEMPSTAT,4      ; CHECK WHETHER WE ARE TRANSMITTING OR PASSING THROUGH
 GOTO    TXINDEPENDENT

PASSTHROUGHDATA              ; IF IN PASSTHOUGH MODE THEN PASS INCOMING DATA TO OUTPUT

 RRF GPIO,F
 RRF GPIO,F
 RRF GPIO,F
 RRF GPIO,F
 RRF GPIO,F
 RRF GPIO,F
 RRF GPIO,F
 RRF GPIO,F
 RRF GPIO,F
 RRF GPIO,F
 RRF GPIO,F
 RRF GPIO,F
 GOTO    SYNXREADBIT

TXINDEPENDENT                ; IF TRANSMITTING THEN GET READY TO TRANSMIT THE BIT

 MOVLW   2           ; 28 US
 MOVWF   DELAYCOUNT      ; IF HERE, WE ARE TRANSMITTING DATA BITS
 BTFSC   TEMPSTAT,6      ; CHECK WHETHER WE ARE TRANSMITTING THE DATA OR PARITY BITS
 GOTO    SYNCTXPARITY
 RRF     XMITHREG,F      ; ROTATE RIGHT (LSB 1ST) INTO C
 MOVF    STATUS,W        ; C IS STATUS:0 INTO W
 XORWF   PARITY,F        ; UPDATE PARITY REGISTER
 RLF GPIO,F          ; EMIT DATA OUT OF BIT 0      - 34 US

SYNXREADBITDELAY

 DECFSZ  DELAYCOUNT,F    
 GOTO    SYNXREADBITDELAY

SYNXREADBIT

 BTFSC   TEMPSTAT,6
 BSF     TEMPSTAT,7
 RRF     RECV,F
 BSF     RECV,7      
 BTFSC   GPIO,GP1            ; 54 US
 BCF     RECV,7
 DECFSZ  XMITBITCOUNT,F
 GOTO    READBYTELOOP            ; 58US IN PASSTHROUGH & TX INDEPENDENT
 BSF     TEMPSTAT,6
 INCF    XMITBITCOUNT,F
 INCF    XMITBITCOUNT,F
 MOVF    RECV,W
 MOVWF   XMITHREG
 BTFSC   TEMPSTAT,5
 GOTO    TRANSITIONWAITSENSE     ; IF EXTSYNC GOTO WAIT FOR CLOCK TRANSITION
 MOVLW   3
 MOVWF   DELAYCOUNT
 GOTO    INTSYNCPARITYWAIT

SYNCTXPARITY             ; IF HERE, WE ARE TRANSMITTING DATA BITS

 BCF     PARITY,1        ; CLEAR BIT 1 OF PARITY REGISTER TO USE AS A STOP BIT
 RRF     PARITY,F        ; LOAD THE RELEVANT BIT INTO CARRY
 RLF     GPIO,F          ; TRANSMIT THE BIT IN CARRY   - 34US
 DECF    DELAYCOUNT,F
 GOTO    SYNXREADBITDELAY

ENDSYNCTX

 MOVLW   0XD8            ; (FUNCTION OVERHEAD) - NUMBER OF CYCLES IN 36US
 MOVWF   TMR0
 MOVF    XMITHREG,W
 MOVWF   RECV
 BTFSS   TEMPSTAT,4
 ADDWF   CHECKSUM,F
 CLRF    GPIO
 BSF     GPIO,4          ; KEEP IT HIGH
 BSF     GPIO,5          ; KEEP IT HIGH
 RETLW   0
 
I think you need to explain more what the code is doing. It looks like RS232 with some strange alignment code. You state a bit time of 34-36uS which suggests a baud rate of 28.8KBaud but the comments in the code suggest half that speed ie 14.4KBaud.

If your problem is simply timing then run the code in the simulator and use the stopwatch to adjust the delays.

Mike.
 
I am not using RS232, the pic is connected directly to the data line of the decoder(cablebox), and yes it seems the stream coming through the cable line is 14.4K, but the problem is a month ago the liftime of the stop bit was 34us status 0, and now is 36us with status 0. I don't know how to do the simulator thing but I will show you the log I made before and after. The pic used to sync perfectly after the changes where made. The pic was receiving data perfectly in diagnostic mode was r0, and now is -E and sometimes rE this means an FM error in communication.

Code:
This was a month ago:

Bit Logged;Life time for this bit *;Status of this bit

27;78;0
10;32;0
8F;30;1
10;32;0
A1;66;1
10;32;0
91;34;1
10;32;0
8F;30;1
22;68;0
A3;70;1
22;68;0
8F;30;1
10;32;0
A3;70;1
10;32;0
8F;30;1
22;68;0
8F;30;1
10;32;0
A3;70;1
10;32;0
8F;30;1
10;32;0
91;34;1
10;32;0
8F;30;1
10;32;0
8F;30;1
22;68;0
91;34;1
10;32;0
A1;66;1
10;32;0
8F;30;1
12;36;0
8F;30;1
10;32;0
8F;30;1
10;32;0
8F;30;1
24;72;0
8F;30;1
10;32;0
8F;30;1
10;32;0
A3;70;1
10;32;0
8F;30;1
22;68;0
A3;70;1
22;68;0
A1;66;1
10;32;0
91;34;1
22;68;0
8F;30;1
10;32;0
8F;30;1
10;32;0
A3;70;1
10;32;0
8F;30;1
22;68;0
91;34;1
10;32;0
A1;66;1
10;32;0
8F;30;1
12;36;0
8F;30;1
22;68;0
A1;66;1
24;72;0
8F;30;1
10;32;0
8F;30;1

Code:
This is the log now:

91;34;1
12;36;0
91;34;1
10;32;0
91;34;1
12;36;0
91;34;1
10;32;0
92;36;1
25;74;0
C5;138;1
12;36;0
8F;30;1
12;36;0
91;34;1
25;74;0
A1;66;1
12;36;0
91;34;1
12;36;0
8F;30;1
12;36;0
91;34;1
10;32;0
92;36;1
12;36;0
91;34;1
22;68;0
A1;66;1
25;74;0
A3;70;1
25;74;0
A3;70;1
12;36;0
8F;30;1
12;36;0
91;34;1
10;32;0
91;34;1
12;36;0
91;34;1
27;78;0
C4;136;1
13;38;0
8F;30;1
25;74;0
8F;30;1
12;36;0
A3;70;1
12;36;0
91;34;1
12;36;0
8F;30;1
12;36;0
91;34;1
10;32;0
92;36;1
27;78;0
C4;136;1
25;74;0
8F;30;1
FF;spacer;64 FFs
C5;138;1
12;36;0
91;34;1
25;74;0
A3;70;1
25;74;0
A1;66;1
12;36;0
91;34;1
12;36;0
8F;30;1
12;36;0
92;36;1
25;74;0
C5;138;1
25;74;0
8F;30;1
12;36;0
A3;70;1
25;74;0
A3;70;1
12;36;0
8F;30;1
12;36;0
91;34;1
12;36;0
91;34;1
12;36;0
92;36;1
21;66;0
A1;66;1
12;36;0
91;34;1
10;32;0
 
This how the bit logger works, I am posting this because this software was made by a friend of mine and maybe people don't know how it works.
 

Attachments

  • sample.jpg
    sample.jpg
    91 KB · Views: 161
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top