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 support@ccsinfo.com

Data baud rate mismatch

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
POPE19



Joined: 27 Jun 2017
Posts: 71

View user's profile Send private message

Data baud rate mismatch
PostPosted: Wed Aug 30, 2017 12:12 pm     Reply with quote

Hello Friends,

I just bought PIC16F1939. I have connected it with a computer using USB/Serial Adapter. It is having incorrect baud rate. As per code below I have set the baud rate as 9600 BPS (default). However i am getting incorrect characters and random characters when i am setting the same baud rate in my CCS Serial Monitor. But if i am changing the baud rate inside the CCS Serial monitor ---> port options setting to "38400", the Pic displays the message correctly.

I think the PIC is running at a greater frequency however i have loaded the fuse correctly to select external oscillator "HS". Can someone please help me to figure out why, as i am not that much sound with the assembly language and cannot troubleshoot my code.

I am using 20MHZ External Oscillator and CCS Compiler Version 5.074.
Code:

#include <16F1939.h>
#fuses HS, MCLR, NOWDT, PUT, NOIESO, BROWNOUT, NOFCMEN
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
void main()
{
 
  while(TRUE)
  {
   
    printf("\r \n hello");
  }
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19359

View user's profile Send private message

PostPosted: Wed Aug 30, 2017 1:04 pm     Reply with quote

Do you have an external oscillator, or a crystal?.
Assuming a crystal (since you have selected HS), do you have a spec sheet/part number for this?. What loading capacitors are you using?. How is the board laid out in this area?. What voltage are you running the PIC?. It is quite common for crystals to run on an overtone, if being overdriven. This is why the example circuit on the data sheet shows a series resistor.

However, it is very unlikely that you will get to quadruple speed with the crystal oscillator though. 50% over perhaps, but the chip is only rated for 32MHz max. I'd be testing your USB adapter by sending a continuous data pattern out, and timing it with a scope.

Then do the simple test on the PIC. The 'flash an LED' test. Simple LED turned on/off at 1 second intervals. In a few moments, it can tell you whether the PIC is clocking at the speed expected.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 30, 2017 1:14 pm     Reply with quote

Also add PLL_SW to your #fuses.
Ttelmah



Joined: 11 Mar 2010
Posts: 19359

View user's profile Send private message

PostPosted: Wed Aug 30, 2017 1:35 pm     Reply with quote

That makes sense. 4*PLL being enabled by default.
Or use
#use delay(clock=20MHz, crystal=20MHz)

which will also disable the PLL.

What is amazing is the chip is running at 80MHz!...

Very Happy
POPE19



Joined: 27 Jun 2017
Posts: 71

View user's profile Send private message

PostPosted: Wed Aug 30, 2017 3:03 pm     Reply with quote

I am using 20 MHZ oscillator with 2 15 PF capacitor. I don't have the part no ri8 now. I am driving pic at 5 V output from a 5 volt regulator. It is laid on breadboard and near that region only oscillator connected with 2 capacitors and a series resistor of 220 ohms. I have already tried to turn on led at a freq of 1 Hz but it seems like it is turning on at higher frequency. It is for sure greater than 1 Hz.

When I tried to use internal oscillator everything works good. I will try adding PLL_SW tomorrow and let you know the results PCM Programmer.
Ttelmah



Joined: 11 Mar 2010
Posts: 19359

View user's profile Send private message

PostPosted: Thu Aug 31, 2017 12:49 am     Reply with quote

The PLL_SW is the fix. Key is if you look at the end of the .LST file. It shows what fuses are actually set. If you do so, you will see the PLL setting is defaulting to on.
I must admit the number of PIC16's with a PLL is so low, that I forgot this one had a PLL, so started looking for other problems (the crystal 'overdrive' one is quite common with some chip families where the oscillator gain is high).

So compile your code, and the file shows:
Code:

Configuration Fuses:
   Word  1: 0FC2   HS NOWDT PUT MCLR NOPROTECT NOCPD BROWNOUT NOCLKOUT NOIESO NOFCMEN
   Word  2: 1FFF   NOWRT NOVCAP PLL STVREN BORV19 NODEBUG NOLVP

Build with:
#use delay(crystal=20MHz, clock=20MHz)

and instead you get:
Code:

Configuration Fuses:
   Word  1: 0FC2   HS NOWDT PUT MCLR NOPROTECT NOCPD BROWNOUT NOCLKOUT NOIESO NOFCMEN
   Word  2: 1EFF   NOWRT NOVCAP PLL_SW STVREN BORV19 NODEBUG NOLVP

Or set the PLL_SW fuse yourself.

Key is that unless you specify them, fuses default to the erased state (1's). A '1' in this bit enables the PLL.....
POPE19



Joined: 27 Jun 2017
Posts: 71

View user's profile Send private message

PostPosted: Thu Aug 31, 2017 4:58 am     Reply with quote

Yes Ttelmah & PCM Programmer. It solved the problem, it works now. Thanks for the explanation.
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

View user's profile Send private message Send e-mail

PostPosted: Thu Aug 31, 2017 6:22 am     Reply with quote

Not connected to the topic issue, sorry.
Quote from Ttelmah:
Quote:
What is amazing is the chip is running at 80MHz!...

How can a 32MHz chip run at 80MHz?
It is possible? I suppose it gets hot, no?
If yes, the 64MHz chips maybe can work at 160MHz?
Maybe PIC's can run at much higher speed than the manufacturer is declaring?

Best wishes
Joe
temtronic



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

View user's profile Send private message

PostPosted: Thu Aug 31, 2017 6:37 am     Reply with quote

Yes Joe PICs will run faster than the 'rated' specification. You can 'overclock' them, same as a PC BUT beware... they will generate a LOT more heat( each clock transition is where the heat comes from) and they may not work reliably when over clocked. Some internal peripherals may be fine, or not work or kinda work. While PIC 'A' might run fine there is NO reason to assume PIC 'B' will run fine! Also PCB design has to be very,very good as now the I/O pins are accessed faster.

Bottom line... if you need a PIC to run fast, pick a PIC that is DESIGNED to be run fast.

Jay
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

View user's profile Send private message Send e-mail

PostPosted: Thu Aug 31, 2017 7:08 am     Reply with quote

Thanks for the answer Jay Smile
I really don't want to learn some new "high speed" PIC's as I really believe in the saying:
Can't teach old dog new tricks Very Happy
So I will stick with the 26/46K22 for the high speed.

Best wishes
Joe
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