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.

USART and MPLAB SIM timing

Status
Not open for further replies.

SPDCHK

Member
I’m busy with a networking project between PIC micro controllers using RS485. I designed my own protocol initially, but it does not have the flexibility I now need.

I then decided to use USART . I had a look at Nigels tutorials, (Tutorial 7) and worked through them all to see what will suit me best. If anyone’s ever done this before, you will know that only Tutorial 7.7 covers USART.

While running the MPLAB SIM I keep an eye out on the stopwatch to see how long these routines take to execute. With Nigel’s code the baud rate is set at 9600. This equates to about ~100us per bit. For 10 bits that then adds up to ~1ms. (This is with the Rcv_RS232 routine).

When running the transmit routine (XMIT_RS232) it takes about 2us. The question is now, how long does it take the data that’s now been stored in the TXREG to be serially transmitted out?

If I use the following method (see code below), monitoring the TXIF bit of register PIR1, it takes about 8ms for the transmit routine to finish. This is obviously not right? (8ms for 10 bits, is about 1200 BAUD).

Code:
TXRS232:	movwf	TXREG		; send data in W 
		bsf	STATUS,RP0	; RAM PAGE 1 
WtHere		btfss	TXSTA,TRMT	; TXSTA<1>. Transmit Shift Register status bit
		goto	WtHere		; Transmission is complete if hi
BRK		bcf	STATUS,RP0	; RAM PAGE 0
		Return

For my networking application I need to know when the TXREG has successfully been transmitted as I need to move on to the next node. Waiting 8ms is hopelessly to long for me.

Can anybody please explain what’s happening here? Surely the TX routine should also take about 1ms for a total of 10 bits to be sent (1 Start, 8 Data, 1 Stop bit)?
 
Hi Mike,

Yes I did. The RX routine shows me ~ 1ms for the full byte, that's at about 104us/bit, which = 9600 BAUD. From that timing I know that the RX code is working.
 
Can't See the Forest for the Trees

Perhaps I should stop worrying about the timing issues I seem to have and realize that USART implemented in PIC's runs at FULL DUPLEX. That in itself poses a major problem for RS485 using two wire solution.

Time to go back to the drawing board.
 
Status
Not open for further replies.

Latest threads

Back
Top