View previous topic :: View next topic |
Author |
Message |
POPE19
Joined: 27 Jun 2017 Posts: 71
|
Data baud rate mismatch |
Posted: Wed Aug 30, 2017 12:12 pm |
|
|
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");
}
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19359
|
|
Posted: Wed Aug 30, 2017 1:04 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Aug 30, 2017 1:14 pm |
|
|
Also add PLL_SW to your #fuses. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19359
|
|
Posted: Wed Aug 30, 2017 1:35 pm |
|
|
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](images/smiles/icon_biggrin.gif) |
|
![](templates/subSilver/images/spacer.gif) |
POPE19
Joined: 27 Jun 2017 Posts: 71
|
|
Posted: Wed Aug 30, 2017 3:03 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19359
|
|
Posted: Thu Aug 31, 2017 12:49 am |
|
|
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..... |
|
![](templates/subSilver/images/spacer.gif) |
POPE19
Joined: 27 Jun 2017 Posts: 71
|
|
Posted: Thu Aug 31, 2017 4:58 am |
|
|
Yes Ttelmah & PCM Programmer. It solved the problem, it works now. Thanks for the explanation. |
|
![](templates/subSilver/images/spacer.gif) |
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
|
Posted: Thu Aug 31, 2017 6:22 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9170 Location: Greensville,Ontario
|
|
Posted: Thu Aug 31, 2017 6:37 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
|
Posted: Thu Aug 31, 2017 7:08 am |
|
|
Thanks for the answer Jay
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
So I will stick with the 26/46K22 for the high speed.
Best wishes
Joe |
|
![](templates/subSilver/images/spacer.gif) |
|