View previous topic :: View next topic |
Author |
Message |
ROBOTICAR
Joined: 28 Aug 2007 Posts: 45
|
internal osc and RS232 problem |
Posted: Wed Mar 11, 2015 12:15 pm |
|
|
Hi
I searched the forum and I couldn't find any answer to my question.
I use PIC25k80 and I run it through internal RC oscillator with x4PLL I just add this code in my header file :
#use delay(int=64M)
in doing so, my RS232 port, which is configured as software uart, would not work as well as it used to ! I mean I just could get some scrambled characters in hyperterminal whose baudrate was set in 115200!
#use rs232 (BAUD = 115200, Xmit = Pin_C4 , RCV = Pin_C5 , stream = CH1)
by measuring the time intervals of printing a text via rs232 in proteus simulator I found for working properly I should define baud rate as 115200 X4 !!!!!
I mean :
#use rs232 (BAUD = 460800, Xmit = Pin_C6 , RCV = Pin_C7 , stream = CH1)
by defining BAUD = 460800 it now works properly as UART 115200 baud rated !
it's a ridiculous problem and solution !!!!
Am I making a mistake or it's just true ?
CCS PCH C Compiler, Version 5.012 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Wed Mar 11, 2015 12:26 pm |
|
|
The compiler is sometimes not as smart as you may hope....
It won't tell you when it can't actually handle the setup you ask for. You have to turn on the PLL yourself. It's running the clock at 16MHz, so the UART runs at 1/4 the speed you ask for.
Set your oscillator as:
#use delay(int=16M,clock=64M)
Then add a setup_oscillator line as:
setup_oscillator(OSC_PLL_ON);
This should boot at 16MHz, and then enable the PLL to switch to 64MHz. You may need to also add the 16MHz oscillator to the setup line (OSC_16MHZ|OSC_PLL_ON). |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Thu Mar 12, 2015 7:58 pm |
|
|
i have not used the PIC chip the OP mentioned,
but i noticed this:
Version 5.012
i have used the HS+PLLx4 declared in the #fuses with the
ultimate frequency - just as his post stated -
and had no trouble in late V4.1xx
or in 5.042, just now without any problem involving
baudrate or delay functions.
so i wonder if it's the CCS version or maybe
the part database thats messed up for him... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Fri Mar 13, 2015 1:54 am |
|
|
You are using HS. External, not internal oscillator. When you use external, these chips wake using the internal oscillator, then switch to the external oscillator. This is part of the chip, and the handling of it is in the CCS code. Problem here is that he is waking using the internal, and then needs to switch to internal*4. The compiler doesn't understand how to do that.
I've stepped through the setups it uses, and if you select the internal oscillator, it removes the automatic switch after boot. So you simply have to add it back!... |
|
|
|