RS232 Baud Rate %Error

Forum for problems or queries regarding Flowcode Comms Components. Eg LIN, I2C, SPI, RS232, CAN, IrDA etc

Moderators: Benj, Mods

Post Reply
Ron
Posts: 225
Joined: Wed Apr 11, 2007 6:15 pm
Has thanked: 2 times
Contact:

RS232 Baud Rate %Error

Post by Ron »

Hi,

I want to set the baud rate to 115200 using the 18.432MHz crystal. Flowcode reports 100% error. I think this is because you only take into account one possibility for the SYNC, BRG16 and SPBRG registers.

Can I set these three registers up in a "C" block to support 115200 at 18.432, and will Flowcode generate the proper code?

Will the RS232 work in simulation even if the % error reported is 100%?

Flowcode defaults to 19660800 clock speed, at this speed can the above registers be set up to support 115200 at 0% error?

The PIC data sheet does not list this clock speed in the tables. There must be a reason you guys made this the default clock speed, why did you select 19660800?

If 19660800 at 115200 is not 0% what is the error rate based on the SPBRG, SYNC, and BRG16 registers?

What would the SPBRG, SYNC, and BRG16 registers need to be set to for 19660800 and 115200?

Thank you,

Ron

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: RS232 Baud Rate %Error

Post by Benj »

Hello Ron

Yes you can use C code to override the settings for the component and yes the simulation will still work.

19.6608 is a good speed as it divides down nicely for timed events like timer interrupts etc to give nice whole number frequencies.

There are only two registers that control the UART baud rate.

txsta
spbrg

These can be assigned values as such using a C code block.

txsta = 0x00;
spbrg = 0x00;

where 0x00 is the hex value for the register.

Flowcode should find the best solution for the baud rate chosen so it may not be possible to get this working but its worth having a try.

Ron
Posts: 225
Joined: Wed Apr 11, 2007 6:15 pm
Has thanked: 2 times
Contact:

Re: RS232 Baud Rate %Error

Post by Ron »

Hi Ben,

The 16F88x has a BAUDCTL register, bit 3 is BRG16, this is set to 1 to achieve higher baud rates.

The 18F2620 has a BAUDCON register, bit 3 is BRG16, this is set to 1 to achieve higher baud rates.


At least this is what I think I am reading in the datasheets, with each new adventure comes uncertainty. Can you see if I am understanding what I am reading.

Thanks

Ron

Ron
Posts: 225
Joined: Wed Apr 11, 2007 6:15 pm
Has thanked: 2 times
Contact:

Re: RS232 Baud Rate %Error

Post by Ron »

Hi Guys,

Regarding the RS-232 component.

I looked at the 16F88 data sheet and this PIC only has 2 registers (Ben made me aware of this) for controlling Baud Rates.

TXSTA (SYNC & BRGH bits) and SPBRG

Newer PICs 16F887/18F4620 have 3 registers to control Baud rates.

TXSTA (SYNC & BRGH), SPBRG and BAUDCTL (BRG16 bit).

The RS232 component does not work properly for the newer PICs if you use the BAUDCTL (BRG16 bit) when calculating %error. I am not sure what else will not work properly.

Will the RS232 component be updated to work proerly with the newer 16F and 18F PICs that have the BAUDCTL/BAUDCON registers? If yes, will V3 get this correction or will it only be in V4?

Thank you,

Ron

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: RS232 Baud Rate %Error

Post by Benj »

Hello Ron

I will look into this for you. Hopefully it should be a quick fix so I should be able to provide the fix for V3 as well as V4 of Flowcode.

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: RS232 Baud Rate %Error

Post by Benj »

Hello Ron

Have you confirmed that the RS232 is not working correctly on these devices in hardware?

There is indeed an additional two registers for baud rate control on these newer devices ( BAUDCTL and SPBRGH ) but it seems that the extra options are disabled by default so they should not impact onto your program or the error given for calculating your baud rate.

Ron
Posts: 225
Joined: Wed Apr 11, 2007 6:15 pm
Has thanked: 2 times
Contact:

Re: RS232 Baud Rate %Error

Post by Ron »

Hi Ben,

I want to run at 115200 baud rate.

20MHz 16F887 (BAUDCTL) (18F4620 BAUDCON)
SYNC = 0 and BRGH = 1, BRG16 = 0, SPBRG = d10 --> -1.36%
SYNC = 0, BRGH = 0, and BRG16 = 1, SPBRG = d10 --> -1.36%

I am using SYNC = 0, BRGH = 1, BRGH16 = 1, SPBRG = d42 --> .94%.

Flowcode reports a 50% higher error rate than what is expected.

I am having intermittent connection issues with an olimex board, not sure if it is me or not.

I found this issue with incorrect reporting of % error, not sure if anything else might be going wrong on Flowcode side.

Thanks

Ron

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: RS232 Baud Rate %Error

Post by Benj »

Hi Ron

I will see if we can improve our baud rate calculations a bit when these extra registers are available.

I doubt that the errors of either 1.36 or 0.94 are throwing the baud timings out.

Here are a couple of tips to ensure good performance.

Read as often as you can. If you receive 3 bytes in a row without performing a read then your UART will register an error and will loose all the data you have received. Also if the UART is in error mode you will not be able to sent out data. Performing a read will clear any error if an error occurs. The RXINT Interrupt that fires when incoming data is received can be helpful when dealing with these receive errors.

Ron
Posts: 225
Joined: Wed Apr 11, 2007 6:15 pm
Has thanked: 2 times
Contact:

Re: RS232 Baud Rate %Error

Post by Ron »

Hi Ben,

I would like the powers that be to consider upgrading the RS232 component. I am not sure if it is possible given the fact that newer pics have several registers to control baud rate ond old ones only have 2.

It would be nice if we can set the necessay bits (SYNC, BRG16, BRGH) and registers (SPBRG) value so that we can set any baud rate for the newer PICs that have these registers.


19.6608 divides easily for time INT etc (you mentioned), How does 18.432 divide out, I will need to have TMR0 Int running at 1ms and another project at 10ms, I have yet to figure out how this works. The reason I ask is this freq has 0% error at all the standard baud rates up to 57k6 (SYNC = 0, BRGH = 0, BRG16 = 0, SPBRG = varies depending on baud rate). My guess is that this is the closest to the current RS232 component design. Based on this I would be able to experiment with baud rates up to 57k6, as 115200 is not an option with these settings.

Thank you,

Ron

Post Reply