Software serial baud rates

Status
Not open for further replies.

Oznog

Active Member
I was looking at what it would take to make a software serial port receive at 4800 baud to talk to a GPS, because the hardware port was already being constantly used for something else.

Now I have a 10 MHz instruction clock here (18F series, 10MHz xtal with a 4x PLL to give a 40MHz clock freq). I read here that I need to handle this on an interrupt basis at 3x the baud rate, so this would then require interrupts only 694 instructions apart?

Also TMR2 is already in use for PWM and cannot be reassigned. On the 18F4620, like most PICs, the period can only be arbitrarily assigned in TMR2. Can I sample a 4800 baud serial signal at a higher rate? If I use another timer at 512 clks then it's 36% faster.

Frankly I would expect this is going to be a positively awful performance hit, there is even a remote possibility that in a worse case scenario where it also gets interrupted with a high priority interrupt that it may lose a cycle. Any other better way to do this at all?
 
Here's a interrupt driven rs232 routine. It runs on a 8MHz clock (2M cc) and uses timer0 for 4800 baud. Maybe you could adapt this. It's was originally on a 16F819.

I have to go out now, so can't answer any questions at the moment. Hopefully, it's self explanetary.


Mike.
Edit, it uses timer 0 not 1.
Prescaller = 2
macros are
bbs = branch bit set
setc = set carry = bsf STATUS,C
etc.

Code:
#define		b_RS232Out	PORTB,3
#define		b_RS232In	PORTB,2

; variables
TransferFlags
InByte
cache
RecSkips


; TransferFlags bits
b_receiving	equ	7
b_transmit	equ	6
b_byte_available equ	5
b_sent_start	equ	4
b_Count100	equ	3



interupt	movwf	int_work;					       2 latent +1
		swapf	STATUS,W;							+1 4
		movwf	int_status;		status is nibble swaped			+1 5
		bcf	STATUS,RP0;							+1 6
		bcf	STATUS,RP1;							+1 7
		movlw	100h-130/2;							+1 8
		movwf	TMR0;								+1 9 + 130 = 139
		bcf	INTCON,TMR0IF;		reset int flag
		decfsz	RecSkips,F
		goto	DoneRS232
		incf	RecSkips,F;	set to 1
		btfss	TransferFlags,b_receiving
		goto	get_start_bit
		Setc
		btfss	b_RS232In
		clrc
		rrf	InByte,F
		movlw	3
		movwf	RecSkips
		btfss	STATUS,C
		goto	DoneRS232
got_byte	movf	InByte,W
		movwf	cache
		bsf	TransferFlags,b_byte_available
		bcf	TransferFlags,b_receiving
		goto	DoneRS232
get_start_bit	bbs	b_RS232In,DoneRS232
		movlw	4
		movwf	RecSkips
		bsf	TransferFlags,b_receiving
		movlw	80h
		movwf	InByte
DoneRS232	swapf	int_status,W
		movwf	STATUS
		swapf	int_work,F;	swap to file
		swapf	int_work,W;	swap to work
		retfie
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…