CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Baud rate Issues for UART2 on PIC18F65J11

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mayur.k.vadukul



Joined: 07 Jul 2022
Posts: 40

View user's profile Send private message

Baud rate Issues for UART2 on PIC18F65J11
PostPosted: Thu Apr 27, 2023 7:25 am     Reply with quote

I have been using UART1 & UART2 with PIC18F66K22 device and I have been doing the following to get the right baud rates for our systems:-

#use rs232(UART2, baud=9600, ERRORS, STREAM = FM_UART) //Set 2nd UART to 9600 Baudrate
#use rs232(UART1, baud=4322, ERRORS, ENABLE=DATA_DIR, DISABLE_INTS, STREAM = BUS_DATA) //For Data Bus

The code was running as expected and there were no issues.

I then changed the microprocessor from PIC18F66K22 to PIC18F65J11 (Pin Compatible) , and I have changed the device on my board keeping the code exactly the same as above. The code compiles too, but for some reason the baud rate for UART2 is unexpected. I don’t understand what could be the difference.
_________________
MVadukul
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Apr 27, 2023 7:34 am     Reply with quote

I don't use those PICs but....
It could be a compiler 'bug'
Post your version and someone with it can confirm/deny the 'bug' .
You should dump the listing to see what bits are being configured in the 'baud rate' register.
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Thu Apr 27, 2023 7:40 am     Reply with quote

What do you mean 'unexpected'?. Slow, fast, etc. etc..
What is the master oscillator frequency in both cases?.
Post the actual #PIN_SELECT lines for the UART.
What compiler version?.
mayur.k.vadukul



Joined: 07 Jul 2022
Posts: 40

View user's profile Send private message

baud
PostPosted: Thu Apr 27, 2023 7:44 am     Reply with quote

@ temtronic, see the listing below:-
.................... #use rs232(UART2,baud=9600,ERRORS, STREAM = FM_UART) //Set 2nd UART to 9600 Baudrate
*
0B6E: BTFSS FA4.4
0B70: BRA 0B6E
0B72: MOVWF F62
0B74: RETURN 0
@temtronic,
It is faster than 9600. the bit rate for working 9600 is 104uSec and non working code is 32uSec.
I don't understand what do you mean by #PIN_SELECT lines?
The compiler version is 5.109.
_________________
MVadukul
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Thu Apr 27, 2023 7:49 am     Reply with quote

Both of your chips are not PPS chips. Very surprising for a J chip.
However you haven't answered the oscillator question?.
mayur.k.vadukul



Joined: 07 Jul 2022
Posts: 40

View user's profile Send private message

Ttelmah
PostPosted: Thu Apr 27, 2023 7:52 am     Reply with quote

On both occasion the crystal is 16MHz and it is run at 64MHz using PLL.
#use delay(clock=64MHz,crystal=16MHz,restart_wdt)
_________________
MVadukul
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Thu Apr 27, 2023 8:02 am     Reply with quote

Also the baud rate setting code is not at the #USE line, but at the start
of main. Look there.

The J11, is not rated to run at 64MHz. 40MHz max. Probably why it is
not working right....
mayur.k.vadukul



Joined: 07 Jul 2022
Posts: 40

View user's profile Send private message

Baud rate Issues for UART2 on PIC18F65J11
PostPosted: Thu Apr 27, 2023 9:39 am     Reply with quote

I am sorry but I do not understand your comments.
_________________
MVadukul
mayur.k.vadukul



Joined: 07 Jul 2022
Posts: 40

View user's profile Send private message

Baud rate Issues for UART2 on PIC18F65J11
PostPosted: Thu Apr 27, 2023 9:42 am     Reply with quote

I have also tried disabling the PLL and ran the system at 16MHz crystal and it still did not work.
On scope, i tried delay function, checked timer interrupt and UART1. It all worked fine but the UART2 doesn't want to know. I happened to have the code in XC8 compiler as well and it is working fine. So there got to be the bug in the compiler. Do you know any other method to set the baud rate?
_________________
MVadukul
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Fri Apr 28, 2023 1:43 am     Reply with quote

OK.

The point I was making, was you posted the stuff generated by the
#use as if this could affect your UART. However this is just the transmit
and receive code (just the start of it posted). The UART _setup_ does
not appear here, but at the start of the main in the listing. So:
Code:

.................... void main()
0004:  CLRF   TBLPTRU
0006:  BCF    RCON.IPEN
0008:  MOVLW  40
000A:  MOVWF  OSCTUNE
000C:  CLRF   OSCCON
000E:  MOVF   OSCCON,W
0010:  CLRF   rs232_errors
0012:  BSF    F7C.3
0014:  MOVLW  40
0016:  MOVWF  SPBRG2
0018:  MOVLW  03
001A:  MOVWF  F7D
001C:  MOVLW  A6
001E:  MOVWF  TXSTA2
0020:  MOVLW  90
0022:  MOVWF  RCSTA2


The code starting at 0014, is where it sends the values to the BRG
registers.

This shows what the setting is doing.

Now, on your chip, UART1 & UART2 have different settings for the
BRG. Uart2 only has an 8bit BRG generator, while Uart1 has a 16bit
generator. On Uart2, there just is a prescaler controlled by the BRGH bit.
The setup code is treating UART2, like UART1, and loading the high
byte into the location F7D (001A). This doesn't exist for this UART.

Now the timings you were getting, were also wrong because of your clock
rate, which the chip didn't support. It looks as if the chip was actually
running at 32MHz, since it is loading a divider of 65, and a prescaler
of 16. 32uSec for the bit time gives a baud rate of 31250. and this times
65*16 -> 32000000.

So:
Code:

#define CLOCK 16000000 //set this to suit what your clock really is
#define BAUD 9600 //select the baud rate required
#define BRG16 (CLOCK/(16*BAUD))-1
#define BRG64 (CLOCK/(64*BAUD))-1
#BYTE SPBRG2=getenv("SFR:SPBRG2")
#BYTE TXSTA2=getenv("SFR:TXSTA2")
#bit BRGH=TXSTA2.2

//Then at the start of your main
void main(void)
{
#IF BRG16>255 //here we are going to have to select /64
   SPBRG2=BRG64; //set UART2 for 9600bps   
   BRGH=0;
#ELSE //here /16
   SPBRG2=BRG16; //set UART2 for 9600bps
   BRGH=1;
#ENDIF



If you run at a legitimate clock rate this will correct the BRG settings.
mayur.k.vadukul



Joined: 07 Jul 2022
Posts: 40

View user's profile Send private message

Baud rate Issues for UART2 on PIC18F65J11
PostPosted: Fri Apr 28, 2023 1:58 am     Reply with quote

Thanks for the in depth insight into the issue.

I have tried running the device with 16MHz as well. However, that did not work too. More so, I have use delay_ms (), function and check on the scope whether it produces right results to ensure that the clock is how i have set up. My UART1 works well as I have checked on the scope and so does my timers routine. (checked on scope too). All of these have been tried using both 16MHz & 64MHz. I understand the chip defines it to run with 40MHz max but not sure whether that is the highest frequency of the physical crystal or the actual clock after PLL. Anyway, for the purposes of the testing I have disabled PLL and ran purely as 16MHz as stated above and it still did not work.

I will try adding assembly code to get around and see what happens.

However, when I contacted CCS support, they sent me new pch.dll file as they admitted there is bug in the compiler for the microprocessor I am using. Now, when I pasted, in hurry i forgot to back up the original file and as a result now my CCS compiler program does not run due to CRG mismatch. :(
As soon as I get any response from the CCS, I will keep you posted of the findings and will be interesting to implement assembly lines too.

Many thanks and fingers crossed.
_________________
MVadukul
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Sat Apr 29, 2023 1:34 am     Reply with quote

From CCS to me:

Quote:

Yes, this was reported to us yesterday and we sent the user a fix.
If anyone else has trouble they can e-mail us for a fixed dll until
we make the next release.

I think only this part (maybe family) is affected.
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Sat Apr 29, 2023 9:44 am     Reply with quote

On overclocking, there is a lot to this.
First individual instructions and peripherals may simply not work.
Then the chip will run hot.
Then it may well stop operating at temperatures well below it's rated limits.
Long term this can destroy the chip.
As I said, in fact what your chip was doing was the PLL was failing to work
at this rate. It was not able to clock at the 64MHz rate, and was locking to
32MHz.
Small overclock levels (perhaps 10%), will almost certainly work fine.
Levels over perhaps 20% are likely to have/cause problems.
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Apr 30, 2023 5:17 am     Reply with quote

OK, I'm real curious...
What device has a baudrate of 4432 ??
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group