Hi guys

changed chip internal osc to an external tcxo at 16.368mhz with 4ppl to give 65.472mhz active for a 18f47k40 and the terminal port 2 is not as happy , all other bits on chip working fine

done the same tcxo change for k22 and it not an issue for the terminal at same speed as 19.2k baud rate ,and using just the base setup for the terminal
but the 47k40 is not output all the right chrs when connected to terminal at 19.2k with errors showing on a number of chrs

tried calc1 and calc2 code , but with the same result
also tried setting 16bit/ async SP2BRGH=0 which is the same as calc2 - but that results in total unreadable terminal display at 19.2k

so some help be good to solve this

cheers

sheldon



normally just the basic setting are needed

Code:
    DEFINE HSER_PORT 2          ' Hser port 2 use 
    DEFINE HSER2_RXREG PORTB    ' USART 2 RX - Set PPS Register port B
    DEFINE HSER2_RXBIT 7        ' 
    DEFINE HSER2_TXREG PORTB
    DEFINE HSER2_TXBIT 6
    DEFINE HSER2_RCSTA 90h      ' Hser2 receive status init  - async 
    DEFINE HSER2_TXSTA 24h      ' Hser2 transmit status init - async 
    DEFINE HSER2_BAUD 19200     ' Hser2 baud rate
Have tried a 2 baud rate calculations changes to allow for the osc change but result is the same
so must be missing something , but not sure what

calc1 ....
use 8bit brgh= 0 async = baud rate = fosc / (64 x SPxBRG) +1
osc 16.368mhz x 4 ppl = 65,472,000 hz
buad rate req 19.2k

solve SP2BRG
SP2BRG = 65472000 /( 64 X 19200) = 53.28125
SP2BRG = SP2BRG -1 = 52.28125
SP2BRG = 52

BAUD RATE = 65472000 / 64 X (52+1) = 19301.8867

ERROR RATE = 19301.8867 - 19200 / 19200 = 0.0053 %

CODE RESULT

Code:
    DEFINE HSER_PORT 2          ' Hser port 2 use 
    DEFINE HSER2_RXREG PORTB    ' USART 2 RX - Set PPS Register port B
    DEFINE HSER2_RXBIT 7        ' 
    DEFINE HSER2_TXREG PORTB
    DEFINE HSER2_TXBIT 6
    DEFINE HSER2_RCSTA 90h      ' Hser2 receive status init  - async 
    DEFINE HSER2_TXSTA 24h      ' Hser2 transmit status init - async 
    dEFINE HSER2_CLROERR 1      ' Clear overflow automatically
    DEFINE HSER2_BAUD 19200     ' Hser2 baud rate
    DEFINE HSER2_SPBRGH 0       ' set F/osc/[64(n+1] formular for baud rate gen
    DEFINE HSER2_SPBRGL 52      ' 19200 Baud @ SPBRGL = 52 0.0053% error
    BAUDCON2.3 = 0                 ' set BRG16 = 0  THEN  8BIT/ASYNC

calc2 ....
use 8bit brgh= 1 async = baud rate = fosc / (16 x SPxBRG) +1
osc 16.368mhz x 4 ppl = 65,472,000 hz
buad rate req 19.2k

solve SP2BRG
SP2BRG = 65472000 /( 16 X 19200) = 213.125
SP2BRG = SP2BRG -1 = 212.125
SP2BRG = 212

BAUD RATE = 65472000 / 16 X (212+1) = 19211.267

ERROR RATE = 19211.267 - 19200 / 19200 = 0.00058 %

calc2 give a value closer to the 19.2k than calc 1 - so should be the better ?

Resulting code

Code:
    DEFINE HSER_PORT 2          ' Hser port 2 use 
    DEFINE HSER2_RXREG PORTB    ' USART 2 RX - Set PPS Register port B
    DEFINE HSER2_RXBIT 7        ' 
    DEFINE HSER2_TXREG PORTB
    DEFINE HSER2_TXBIT 6
    DEFINE HSER2_RCSTA 90h      ' Hser2 receive status init  - async 
    DEFINE HSER2_TXSTA 24h      ' Hser2 transmit status init - async 
    dEFINE HSER2_CLROERR 1       ' Clear overflow automatically
    DEFINE HSER2_BAUD 19200     ' Hser2 baud rate
    DEFINE HSER2_SPBRGH 1        ' set F/osc/[16(n+1] formular for baud rate gen
    DEFINE HSER2_SPBRGL 212     ' 19200 Baud @ SPBRGL = 212   0.0058% error
    BAUDCON2.3 = 0                   ' set BRG16 = 0 - 8BIT/ASYNC