Baud Rate problem FC5 - 18F66K22

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
MarkW
Flowcode v5 User
Posts: 118
Joined: Thu Sep 17, 2009 1:30 pm
Has thanked: 3 times
Been thanked: 11 times
Contact:

Baud Rate problem FC5 - 18F66K22

Post by MarkW »

Hello

Using 18F66K22 (internal osc 16mhz)with FC5....need to use baud rate of 115200. In RS232 panel settings
i have set the "custom" baudrate to 115200. But, the baud rate is not correct. Checked
by sending string from Uart1/2 to Hyperterminal. Only get garbled chars.....

Tried same test with different compiler....works no problem.

Help?

Thanx

Mark

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Baud Rate problem FC5 - 18F66K22

Post by Benj »

Hi Mark,

Can you try again at a lower baud say 9600 and just check to see if this is working ok. Could be that Microchip have added a * 2 or / 2 into the setup of the baud on this device. If 9600 doesn't work and you still get garbled data then try setting the embedded device baud to 4800 and keep the PC baud at 9600. If this doesn't work then you can also try the embedded device at 19200 and keep the PC baud at 9600.

Let me know how you get on.

MarkW
Flowcode v5 User
Posts: 118
Joined: Thu Sep 17, 2009 1:30 pm
Has thanked: 3 times
Been thanked: 11 times
Contact:

Re: Baud Rate problem FC5 - 18F66K22

Post by MarkW »

Hi Ben

Yup, tried 9600 / 19200 / 38400....all work.

Soon as you set 115200 on the "custom" baud rate setting, the data is garbled.

I know 115200 works, because i used it with a bootloader i used with another
compiler. That works flawlessly....

Something is not being calculated properly :roll:

Thanx

Mark

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Baud Rate problem FC5 - 18F66K22

Post by Benj »

Hi Mark,

Ok thanks for letting me know,

Does the 9600 work on the custom setting?

Also have you tried multiples of the baud on the PC e.g. set the baud to 115200 on the device but then use a baud of 57600 on the PC and see if that works. I know there is a divide by two flag on most devices so this could be being setup incorrectly. If this is the case then it helps me to track down where in the code the problem lies.

Hard to test here because that device is one of the newer families and requires a SMD circuit board to drive it.

If you can't get any further then let me know and I will have a dig in here to see if I can get anywhere.

MarkW
Flowcode v5 User
Posts: 118
Joined: Thu Sep 17, 2009 1:30 pm
Has thanked: 3 times
Been thanked: 11 times
Contact:

Re: Baud Rate problem FC5 - 18F66K22

Post by MarkW »

Hi Ben

I set the custom baud again 115200 (its the only way to select 115200)....and tried all different
baud rates on the PC side....not working, garbled data.

Tried setting 9600 on the "custom" method....works OK.

This might give you some clue? I have an idea that when you enter "115200" on the custom baud
setting, because it is 6 digits, that might be a problem for the holding variable for the custom
number?

I gotta fix this, as i need to have this program done in FC5. I am doing it for somebody
that has requested it from me.

cheers

Mark

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Baud Rate problem FC5 - 18F66K22

Post by Benj »

Hi Mark,

Right looking at the calculation for the baud rate.

Code: Select all

#define MX_HARD_BAUD_1	(((MX_CLK_SPEED / MX_UART_BAUD_1) - 16) / 16)
At 16MHz you end up with 7.68 which due to integer maths rounds to 7 which is probably just outside of the tolerance which means you get garbage instead of the correct data.

Is there any chance you can change the oscillator speed to give you more overhead to hit the baud rate on the nose, 19.6608MHz is a nice crystal for generating bauds.

If not then it should be possible to overwrite the baud calculation and plug in your own baud value. I'm guessing 8 would be better then 7 and hopefully will be in tolerance.

To do this open the CAL file C:\Program Files (x86)\Flowcode\v5\CAL\PIC\PIC_CAL_UART.c in a text editor.

On line 119 change this code

Code: Select all

#define MX_HARD_BAUD_1	(((MX_CLK_SPEED / MX_UART_BAUD_1) - 16) / 16)
To this

Code: Select all

#define MX_HARD_BAUD_1	  8     //(((MX_CLK_SPEED / MX_UART_BAUD_1) - 16) / 16)
Let me know how you get on.

MarkW
Flowcode v5 User
Posts: 118
Joined: Thu Sep 17, 2009 1:30 pm
Has thanked: 3 times
Been thanked: 11 times
Contact:

Re: Baud Rate problem FC5 - 18F66K22

Post by MarkW »

Hi Ben

Will try that.....but will that not fix the baudrate at that speed? Since you are commenting out the calculation?

Just remember this...my other compiler works 100% at 115200 baud with my 16mhz clock speed (internal).
So, they are getting it right somehow....but FC5 is not calculating correctly.

Will give it a shot, but if the fix means that the baud remains fixed then that could also be a problem, but will see as the program
progresses.

Thanx!

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Baud Rate problem FC5 - 18F66K22

Post by Benj »

Hello,
Will try that.....but will that not fix the baudrate at that speed? Since you are commenting out the calculation?
Yes we are hard coding but more for a quick sanity check to see if this starts the UART working at the correct baud rather then a long term fix.

If you don't want to hard code the calculation then you could try this instead.

Code: Select all

#define MX_HARD_BAUD_1   ((((MX_CLK_SPEED / MX_UART_BAUD_1) - 16) / 16) + 1)
The other compiler might be doing something fancy to do the calculation but i'm pretty sure it would also have to use 7 or 8 as the baud parameter and 7 isn't working. I might be able to get the pre-processor to round to the nearest value rather then always rounding down so I will have a look into this.

Out of interest what is your other compiler and can you find the value inside the SPBRG and TXSTA registers just to sanity check I'm not getting something wrong.

MarkW
Flowcode v5 User
Posts: 118
Joined: Thu Sep 17, 2009 1:30 pm
Has thanked: 3 times
Been thanked: 11 times
Contact:

Re: Baud Rate problem FC5 - 18F66K22

Post by MarkW »

Tried the +1 in the calculation....still not working.

I also tried hard coding the figures from 7 - 9. No luck.

Other compiler is the MikroBasic compiler for 12/16/18F devices.
I used this for the bootloader as they have nice library functions
for read/write to flash memory(cuz i am a lazy sod :D )

I will see if i can read out the registers and send out the serial port
in the morning and let you know whatsup.

Sorry to hassle you on this one Ben, it looks a bit nasty :(

Post Reply