View previous topic :: View next topic |
Author |
Message |
Manu59114
Joined: 22 Jan 2018 Posts: 34 Location: North of France
|
Bad Baudrate at 64MHz |
Posted: Mon May 21, 2018 11:53 am |
|
|
Hello to all.
I try to use the EUSART at 19200 baud on a 18F26K80 and i can't understand why at 32MHz with the internal oscillator, the baudrate is equal at 19200 and can be read on my laptop at 19200 Baud and
when i configure the PIC at 64MHz (internal oscillator), the baud rate can be only read when i configure the laptop at 14400 Baud!!!
When i use a baudrate like 9600..... everything is fine.... at 32MHz and 64 MHz!
Do you have an idea on this kind of problem?
Wish you all the best!
MAnu _________________ CCS + ICD3 + PIC18F46K80 |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Mon May 21, 2018 12:35 pm |
|
|
Please post your small, compilable test program. It must be an old laptop if it's got a real RS-232 comport ! You aren't using a TTL<>USB module are you?
I've run an 18F46K22 at 64 MHz, internal, looped BOTH HW UARTS to itself then a PC (old, REAL Comports) with problems....
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19551
|
|
Posted: Mon May 21, 2018 12:36 pm |
|
|
Try adding BRGHOK to your RS232 setup.
Not having this enabled limits the settings the UART can do. May be causing an issue. However it is difficult to see how it'd get /1.33.... |
|
|
Manu59114
Joined: 22 Jan 2018 Posts: 34 Location: North of France
|
|
Posted: Mon May 21, 2018 2:21 pm |
|
|
Thanks for your quick reply!
To Ttelmah,
I add "BRGH1OK" with no success!
What i forget to explain....
When i use this config:
#use delay(internal=32000000)
#use rs232(baud=256000,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1,BRGH1OK)
I can read with my laptop all baudrate...;no problem with 256000.
with i change the value with 64000000.
The program works at 64Mhz...timing is right.... Led blinking fine at the right timing but the RS232 output is wrong!
If i choose Baud=19200 on CCS...i can read all values at 14400 on my laptop (with a new cable USB FTDI Chip).
Code: |
works like a charm:
#include <18F26K80.h>
#device ADC=16
//#FUSES WDT //Watch Dog Timer
//#FUSES WDT1 //Watch Dog Timer uses 1:1 Postscale
#use delay(internal=32000000)
#use rs232(baud=256000,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1,BRGH1OK)
#use i2c(Master,Fast,sda=PIN_C4,scl=PIN_C3,force_hw)
#define LED PIN_B5
#define DELAY 1000
Doesn't work
#include <18F26K80.h>
#device ADC=16
//#FUSES WDT //Watch Dog Timer
//#FUSES WDT1 //Watch Dog Timer uses 1:1 Postscale
#use delay(internal=64000000)
#use rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1,BRGH1OK)
#use i2c(Master,Fast,sda=PIN_C4,scl=PIN_C3,force_hw)
#define LED PIN_B5
#define DELAY 1000
Main.c
#include <test uart 64MHz.h>
void main()
{
while(TRUE)
{
//Example blinking LED program
output_low(LED);
printf("OFF");
delay_ms(DELAY);
output_high(LED);
printf("ON");
delay_ms(DELAY);
//TODO: User Code
}
}
|
Wish you a great and sunny day!!! _________________ CCS + ICD3 + PIC18F46K80 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19551
|
|
Posted: Mon May 21, 2018 2:49 pm |
|
|
Critical question.
What compiler version?.
That way we can compile and see what register values are being set with the same compiler..... |
|
|
MikeW
Joined: 15 Sep 2003 Posts: 184 Location: Warrington UK
|
|
Posted: Tue May 22, 2018 1:36 am |
|
|
I would bet its because he is using the internal RC oscillator.
Its not that accurate.
Try an external crystal, also is the PIC well decoupled at the Vcc/gnd pins ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19551
|
|
Posted: Tue May 22, 2018 1:59 am |
|
|
He is using that when he is at 32MHz as well.
Not 33% error. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19551
|
|
Posted: Tue May 22, 2018 8:05 am |
|
|
OK. I've just built it with the current compiler, and the settings are right:
Code: |
#include <18F26K80.h>
#device ADC=10
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOXINST
#FUSES NOMCLR
#FUSES NOIESO
#FUSES NOFCMEN
#FUSES STVREN
#use delay(internal=64MHz)
#use rs232(BAUD=19200, PARITY=N, UART1, BITS=8, ERRORS, BRGH1OK)
void main()
{
while(TRUE)
{
//At this point PLLEN is set to 1 (so 64 MHz selected).
//TXSTA1 = 0xA6 clock from BRG, ASYNC, TXEN, HSEN
//RCSTA1 = 0x90 CREN, SPEN
//BAUDCON1 = 0x48 16bit BRG selected, RX idle
//SPBRG1= 0x340 Fosc/(4*n+1) n = 833 (/3332) -> 19207Hz
putc('A');
delay_ms(10);
}
}
|
When it arrives at the putc, all the UART1 registers are set correctly to generate 19200bps (actually set to generate 19207 bps). |
|
|
Manu59114
Joined: 22 Jan 2018 Posts: 34 Location: North of France
|
|
Posted: Wed May 23, 2018 5:11 am |
|
|
Hi Ttelmah, Hi Temtronic, Hi MikeW
This morning, i investigated the problem and i found the solution. it's Resolved!!!
I used a scope and i finally view that the voltage on the TX output was only 2 volts.
I measured Voltage on the PCB on these point:
Main input power connector: 3.3Volts.
On the SMD decoupling capacitor very closed to VDD pin of the PIC, i measured 3.3Volts.
And..........On the PIC18F26K80 VDD pin....... the voltage was......2.12Volts!
On the VDD pad there was a micro wire cut! ....need a magnifying glass to see the brake between the wire and the VDD pad.
The difficulty for me to found where was the problem was that all of lectronic parts of the PCB working fine....
Everything work at 32MHz (PIC, All hardware parts and Uart at all Baudrate!)
at 64MHz
Every electronic parts working except baudrate up to 9600.
Good Timing...except for the UART)
Found in the PIC18F66K80 Family Datasheet.....
VOLTAGE-FREQUENCY GRAPH fig 31.1
For VDD values 1.8V to 3V, FMAX = (VDD – 1.72)/0.02 MHz
in my case
(2.12-1.72)/0.02= 20MHz!!!
I was Lucky because at 32MHz...i had no problem!
Hope that my problem will help some people....
Thank you to all for help me....
Thank you to all for your quick answers.
Wish you all the best! _________________ CCS + ICD3 + PIC18F46K80 |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Wed May 23, 2018 6:13 am |
|
|
Glad you found BOTH problems, 1 hardware, one software..
I need a *5 mag to see PCBs these days, sigh, getting old...
Usually I think of PICs running off 5 volts( again I'm old..somr of my PICs have windows on them !). The frequency vs VDD is an important spec, all too often overlooked. The other is the 'stability' or 'accuracy' of the internal oscillators vs temperature. Get too hot or too cold and ...'hmm it doesn't work anymore'....
cheers
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19551
|
|
Posted: Wed May 23, 2018 6:57 am |
|
|
Yes. I'm the only person at my company who will debug SMD stuff. I even have a SMD microscope.
Makes amazing 'sense' the chip running off a lower voltage than it should be...
Even more amazing was that it worked at 9600bps. Think about it the chip would stll have been clocking at 64Mhz!...
Glad you have found it. |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Wed May 23, 2018 7:23 am |
|
|
We have a fully featured assembly line consisting of a paste machine, pick & place, and a reflow oven. Pick & place is capable of 0201 components. I spec'd this: http://www.st.com/en/power-management/led2472g.html for a prototype (in the 5mm VFQFPN leadless package) and I managed to successfully solder 3/5 prototypes by hand using solder paste, a microscope, and a cheapo drawer-based reflow oven. Despite that, and despite our line's capabilities I still caught grief from our production staff that the component was "too small for the machine."
...Since the hand soldered prototypes we've run nearly a thousand with zero issues.
OP: congratulations on finding such a non-obvious problem. Well done! |
|
|
Manu59114
Joined: 22 Jan 2018 Posts: 34 Location: North of France
|
|
Posted: Fri May 25, 2018 6:15 am |
|
|
Hello
Just for information
I tested my board with a Numerique adjustable power supply.
( PIC18F26K80)
All is ok at 64MHz with a voltage of 2.70V.
At 2.62Volt... the UART is the first part to give up! but the rest work!
Wish you a nice weekend!
Manu _________________ CCS + ICD3 + PIC18F46K80 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19551
|
|
Posted: Fri May 25, 2018 6:20 am |
|
|
Something has to be first...
Just amazing that everything else was working!. |
|
|
|