RS232 Not Outputting Correct Characters with HITEC C

Moderator: Benj

Post Reply
medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

RS232 Not Outputting Correct Characters with HITEC C

Post by medelec35 »

RS232 Using software control at 4800 Baud TX from A0. Target=16F88 (same results for other target devices e.g. 16F88). When compiled to chip using BoostC, correct characters are displayed via USB and hypertermial.
If changed to Hitec (lite or evauation pro mode) then wrong characters are displayed and CR function not working either.
Any way around this please?
RS232 Test BoostC & Hitec.jpg
RS232 Test BoostC & Hitec.jpg (99.64 KiB) Viewed 12021 times

Code: Select all

File name:     M:\Flowcode Testing\TestRS232.c
Generated by:  Flowcode v4.3.7.63
Date:          Monday, March 28, 2011 23:11:00
Licence:       Professional
Registered to: Martin


http://www.matrixmultimedia.com


Launching the compiler...
C:\Program Files (x86)\HI-TECH Software\PICC\9.80\bin\picc.exe --CHIP=16F88 -N48 TestRS232.c
TestRS232.c: main()
   909:	FCD_RS2320_SendRS232String("Seconds:",8);
	                                     ^ (359) illegal conversion between pointer types (warning)
pointer to const unsigned char -> pointer to unsigned char
   919:	FCD_RS2320_SendRS232String("   ",3);
	                                ^ (359) illegal conversion between pointer types (warning)
pointer to const unsigned char -> pointer to unsigned char
   930:	FCD_RS2320_SendRS232String("AN0:",4);
	                                 ^ (359) illegal conversion between pointer types (warning)
pointer to const unsigned char -> pointer to unsigned char

..................

(1273) Omniscient Code Generation not available in Lite mode (warning)
HI-TECH C Compiler for PIC10/12/16 MCUs (Lite Mode)  V9.80
Copyright (C) 2010 Microchip Technology Inc.

Memory Summary:
    Program space        used   416h (  1046) of  1000h words   ( 25.5%)
    Data space           used    45h (    69) of   170h bytes   ( 18.8%)
    EEPROM space         used     0h (     0) of   100h bytes   (  0.0%)
    Configuration bits   used     2h (     2) of     2h words   (100.0%)
    ID Location space    used     0h (     0) of     4h bytes   (  0.0%)

Running this compiler in PRO mode, with Omniscient Code Generation enabled,
produces code which is typically 40% smaller than in Lite mode.
The HI-TECH C PRO compiler output for this code could be 408 words smaller.
See http://microchip.htsoft.com/portal/pic_pro for more information.


Return code = 0

Launching the linker/assembler...
C:\Program Files (x86)\Matrix Multimedia\Flowcode V4\Tools\DoNothing\DoNothing.exe 

Return code = 0

Launching the programmer...
C:\Program Files (x86)\Matrix Multimedia\Flowcode V4\tools\PPP\PPPv3.exe -cs 2 -chip PIC16F88 -nogui "TestRS232.hex"
Sending program...
Erasing the PICmicro
NOTE: EEPROM data will also be erased!
Writing program memory
Writing configuration memory
Writing id-locations
Reading program memory
Reading configuration memory
Finished reading PICmicro contents
Program sent and verified OK

1048 out of 4096 program words used
0 out of 256 data bytes used
That took 2.121 seconds

Return code = 0

FINISHED
Attachments
TestRS232HT.c
(21.3 KiB) Downloaded 381 times
TestRS232.fcf
(9.5 KiB) Downloaded 403 times
Martin

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 Not Outputting Correct Characters with HITEC C

Post by Benj »

Hello Martin,

Thats a bit odd, looking at the delay function it is a for loop based on a number of iterations required to generate a specific delay.

Looking at the characters that are appearing.

$ = 0x24 rs232 signal = 0 0010 0100 1
; = 0x3B rs232 signal = 0 0011 1011 1

I have given it a quick go here using the software UART and I am getting an output baud rate of around 1695bps instead of 4800bps.

frig factor = (4800 / 1695) = 2.831858

Using this as a frig factor, setting a custom rate of 4800 * 2.831858 = 13590 bps seems to work correctly.

Hardware baud rates should work correctly without using the frig factor.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: RS232 Not Outputting Correct Characters with HITEC C

Post by medelec35 »

Hi Ben,
Thank you for looking into this I appreciate it, as it would mean a lot to me if there is a workaround.
I have tried setting custom baud rate of 13590 and 13593, but still no joy :(
RS232 Cust Setting.JPG
RS232 Cust Setting.JPG (74.08 KiB) Viewed 12006 times
I did notice that when setting custom baud rate:
If Flowcode is running on non windows7 OS then text box has a white background, and numbers have a black font.
If Flowcode is running on windows7 OS then text box has a black background, and numbers have a black font.
So You can't see what your typing. Only way to see numbers is to highlight then. Just thought i would mention it for next Flowcode update.
Benj wrote: Hardware baud rates should work correctly without using the frig factor.
Thanks for that information.
I know hardware would be much better, unfortunately, I have to stay with the software method for now.
Martin

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: RS232 Not Outputting Correct Characters with HITEC C

Post by medelec35 »

Hi Ben,
I believe there could be more to this than first thought?
When I place a 1 sec delay and sendRS232String "U" within a loop, then no data what so ever is sent (confirmed on the scope)
This is the same for baud rate of 4800 and 13590.
I chose a U because of 10101etc pattern

When sent U using BoostC then that char was correctly dispalyed every second.
Martin

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: RS232 Not Outputting Correct Characters with HITEC C

Post by medelec35 »

Benj wrote:
frig factor = (4800 / 1695) = 2.831858

Using this as a frig factor, setting a custom rate of 4800 * 2.831858 = 13590 bps seems to work correctly.
Forgot to ask.
Did you see correct characters displayed via hyperterminal, or was you just measuring o/p using a scope?

Reason I asked is I can get timing near, but waveform looks wrong. There are lows where there should be highs etc.
That could be the reason for wrong chars displayed

If you did get correct chars displayed, it would not be the 1st time my hitec C works differently to yours. :P
Martin

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 Not Outputting Correct Characters with HITEC C

Post by Benj »

Hi Martin,

Yes I first only tried with scope and left it at that. Then I saw your reply and tried with my RS232 board and that indeed failed and was generating garbage in Hyperterminal.

Looking at the code I can't really see anything that can really go wrong. I'll spend a bit of time on this today and see if I can make it behave for you.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: RS232 Not Outputting Correct Characters with HITEC C

Post by medelec35 »

Thanks Ben,
If you can make it behave that would be fantastic!!
Reason it's so important is because I am stuck with 16F616 chip. (using 16F88 for testing only)
My Code has just got bigger, and is now too big to fit on chip with BoostC.
So I'm intending to use HITEC in trial mode to generate smaller code to fit on chip.
Otherwise would just use BoostC as that seems more reliable.
Even if you can't, your time and efforts are really appreciated!
Martin

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 Not Outputting Correct Characters with HITEC C

Post by Benj »

Hello,

Right I have tried again with a 16F877A and this seems to have a different frig factor to the 16F88 that I was testing before.

The frig factor of 7000 is working perfectly on the 16F877A running at 4800 baud no data problems or anything like that.

Just to make sure here is a copy of the latest RS232 C file with a couple of minor HiTech related mods. For now you will still need the frig factor for the HiTech software baud but I will see if I can clean this up. It might be that I will have to re-write parts of the RS232 component in assembler to try and ensure that both HiTech and BoostC use the same amount of delays when using the software UART.

Another thing I have noticed is that when using the software UART frequency interrupts such as timer interrupts can really have an effect. If I have a timer interrup running at around 2KHz then the software UART works great. Upping the interrupt frequency slightly breaks the delay functionality and I stop receiving the correct data at the PC. If the interrupt rate is constant then it should be possible to balance the frig factor against the rate of the interrupt.
Attachments
PIC_RS232.c
(13.83 KiB) Downloaded 380 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: RS232 Not Outputting Correct Characters with HITEC C

Post by medelec35 »

Thanks Ben. I will Retry with the new RS232 Component, and will let you know how I got on.
Martin

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: RS232 Not Outputting Correct Characters with HITEC C

Post by medelec35 »

Thanks Ben
RS232.c component did the trick!
After setting baud for 4500 (from a bit of trial an error), display gave correct characters.
Any higher Baud than 4500 gave wrong chars.
So with my set up of 4800, 4500 was not far off at all!!
Just for reference my set up is as follows:
Target device = 16F616.
Osc = internal set at 4MHz
Thank you for solving this issue so quickly.
Martin

Post Reply