CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

485 comm, problem found
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
new2pic



Joined: 02 May 2006
Posts: 16

View user's profile Send private message

485 comm, problem found
PostPosted: Fri May 05, 2006 3:18 pm     Reply with quote

I am swapping out a 17C756 with a 18F4610. There are no errors with the 17C756. With the 18F4610 I will however get "comm errors" about 10% of the time. The other 90% of the time everything works fine. I have also found that sending certain byte combinations can increase these "comm errors" to more like 50% of the time. I have a slave board that has one of its outputs connected to one of its inputs, so when the output is on, the input is on. I tell it to turn the output on, it turns it on, then i ask it if the input is on and it tells me yes (most of the time). These are the comm errors (when i ask it if the input is on and it is on but it tells me that it is not). My registers are as follows:
TXSTA = 0x26;
RCSTA = 0x90;
BAUDCON = 0x00;
SPBRG = 15;
ADCON1 = 0x0F;
PORTC = 0x00; // clear portc
TRISC = 0x9D;
(also I read/clear the RCREG upon initialization)
I have a 14.7456MHz clock, and Buad Rate of 57.6kHz. I have confirmed my baud rate and consulted the data and errata sheets to the best of my ability. I have noticed an inconsistancy between the 17C756 and the 18F4610. With the following code:

Transmit(0xFE); DelayIt(20);
Transmit(0xFE); DelayIt(20);
Transmit(0xFE); DelayIt(20);
Transmit(0xFE); DelayIt(20);
Transmit(0xFE); DelayIt(20);
Transmit(0xFE); DelayIt(20);
void DelayIt(unsigned char time)
{
while (time > 0)
time--;
}

//For the 17C756

void Transmit(unsigned char data)
{
BSR = 4;
while(!TRMT2);
TXREG2 = data;
}

//For the 18f4610
void Transmit(unsigned char data)
{
while(!TRMT);
TXREG = data;
}

When I look at the TX line of the scope I notice a convenient difference between the two . I do not know what is causing this but believe it has something to do with the errors that I am getting. Do you know what may be the explanation for this?

Unfortunately I can not figure out how to add an attachment but the basic picture shows that for the 17C, the line is high, goes low for 35microseconds, high for 139microseconds, low for 35 microseconds,.....
However, the 18f, is high, goes low for 35microseconds, then high for 156microseconds, low 35...
and (156-139)micro=(1/57.6k)
Any help or ideas would be greatly appreciated. I apalogize ahead of time if I dont fully understand your replies, im kinda new2pic among other things.
Ttelmah
Guest







PostPosted: Fri May 05, 2006 3:57 pm     Reply with quote

Firstly, neither scope 'timing' is right. However this may well be innaccuracy in the scope, unless this have been accurately calibrated recently....
'FE', should have seven bit times low. At 57600bps, this is:

7/57600 second. 121.5uSec

Now if I assume that the scope is 14% out of calibration, and therefore is showing '139uSec', for a 'real' value of 121.5uSec, then the 156uSec 'reading', is actually 136uSec. This is far enough 'out of spec', to give serial errors (12.2%).
You say you have 'checked the baud rate'. Do you mean that you have actually stuck a frequency meter on the output, and tested the frequency being generated?. Alternatively, try a simple program, that uses a simple long time delay, and toggles a pin. Check this with a stopwatch. I suspect you are going to find that the chip is running perhaps 12% 'off frequency'.
One possibility is that your crystal has too much gain. The oscillator on latter chips like the 18F4610, has higher gain than that on the older chips. When these chips first appeared, there were a _lot_ of people who had problems getting the chips to run 'on frequency'. This has declined with latter releases, but may still apply to some chips. The solution most commonly used, is to add a series resistor to the crystal, to reduce the signal fed back into the chip.

Best Wishes
new2pic



Joined: 02 May 2006
Posts: 16

View user's profile Send private message

PostPosted: Mon May 08, 2006 6:46 am     Reply with quote

are there any other things that could cause this, perhaps with the chip configuration, not a hardware problem or scope problem or osillator problem or any other external problem?
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Mon May 08, 2006 7:25 am     Reply with quote

Quote:

are there any other things that could cause this, perhaps with the chip configuration, not a hardware problem or scope problem or osillator problem or any other external problem?


All will be possible, but did you do the time test suggested by Ttelmah?
The long delay test is a must in your situation.

Humberto
new2pic



Joined: 02 May 2006
Posts: 16

View user's profile Send private message

PostPosted: Mon May 08, 2006 8:03 am     Reply with quote

I dont understand what is meant by this? Toggle a pin on and off to make a square wave? how do you toggle it, from a timer interrupt program? I do not know how to create an accurate delay program unless it is using a timer.
new2pic



Joined: 02 May 2006
Posts: 16

View user's profile Send private message

PostPosted: Mon May 08, 2006 8:09 am     Reply with quote

I think the long 'high' stretch is 8 long, not 7 becuase it has the stop bit, is this correct?
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Mon May 08, 2006 8:19 am     Reply with quote

Quote:
I think the long 'high' stretch is 8 long, not 7 becuase it has the stop bit, is this correct?

Yes it is correct.

Quote:

I dont understand what is meant by this? Toggle a pin on and off to make a square wave?

In the presumption that the oscillator is out of freq AND the scope is out of spec, a simple test is a long delay that you can measure with a stopwatch.

Code:


   while(1)
          {
             output_toggle(PIN_xx);
             delay_ms(10000);
          }


Humberto
new2pic



Joined: 02 May 2006
Posts: 16

View user's profile Send private message

PostPosted: Mon May 08, 2006 8:28 am     Reply with quote

still I dont have an accurate way to tell time. I have not been able to find a solid delay routine. I have checked my clock chip and its frequency is correct, if I transmit 1010 1010 with a leading low start bit and ending low end bit shouldnt this give me 57.6kHz?
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Mon May 08, 2006 8:55 am     Reply with quote

Quote:

still I dont have an accurate way to tell time.

Test with the suggested code.

Quote:

I have checked my clock chip and its frequency is correct, if I transmit 1010 1010 with a leading low start bit and ending low end bit shouldnt this give me 57.6kHz?


When talk about data transfer speed, to use proper word, do not refer as frequency measured un Khz, instead use Baud that refers to bits/sec.

If your data is 8 Bit wide + 1 STOP bit at @57.600 Baud, each bit should have 17.33 usec wide.
To measure if the data has the right frame, you must measure from the falling edge of the START bit to the falling edge of the next START bit.
At @57.600 baud it should be 173.33 usec/byte. 1 START + 8 DATA + 1 STOP = 10 bits

Humberto
new2pic



Joined: 02 May 2006
Posts: 16

View user's profile Send private message

PostPosted: Mon May 08, 2006 9:19 am     Reply with quote

is the code in assembly?
also
delay_ms(10000) is a function right? wouldnt i need the function definition and prototype?
new2pic



Joined: 02 May 2006
Posts: 16

View user's profile Send private message

PostPosted: Mon May 08, 2006 12:58 pm     Reply with quote

I have been looking at my tx and rx lines on the scope. I am comparing the readings from the 18f4610 to the ones on its predecesor, the 17c756(which is proven communication). On the transmit, either the stop bit is twice is long or there is a 1 bit wide idle time for some reason, this is odd but should not create any errors only slow me down. So I transmit to my slave (the18f242 that was previously the slave when the 17c756 was the master) asking it if its input is on, it responds and on my rcv line i get the correct response (4 bytes long). The input is off and so the 4th bit should be a zero which it is, however, sometimes my 18f4610 says that it is a zero and sometimes it says that it is not. Any ideas
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Mon May 08, 2006 5:58 pm     Reply with quote

Well, we didn�t get any feedback of the suggested actions.

Quote:

.....35microseconds, high for 139microseconds, low for 35 microseconds,.....
However, the 18f, is high, goes low for 35microseconds, then high for 156microseconds, low 35...
and (156-139)micro=(1/57.6k)


156-139 = 17 wich is 1 bit wide

According to your description it seems that the Tx is handling 9 bits.
We doesn�t know your application but certain instruments use the 9th bit for addressing.

For testing purposes, a work around should be using 9 data bits in the Tx side.
#use rs232(baud=57600, xmit=PIN_xx, rcv=PIN_xx, BITS=9, long_data)

To learn how to handle 9 bits, read the rs485.C driver in the CCS folders.


Humberto
new2pic



Joined: 02 May 2006
Posts: 16

View user's profile Send private message

PostPosted: Tue May 09, 2006 6:30 am     Reply with quote

If TX9 (9-bit Transmit enable bit) and RX9 (9-bit Receive Enable bit) are both set to zero = Selects 8-bit transmission/reception. How could I be sending 9-bits, and how would that 9th bit be set high? Im not sure what you mean by the suggestions, you suggested a time delay test but did not tell me how to do it. All of this stemmed from buad rate. If I am comparing the 18 to the 17, the 17 is perfect, so if the 18 looks identical to the 17 but stays high at the end for 1 bit longer, then the 18 is transmitting just fine but takes 1 bit longer between bytes. I think we have determined that the scope is not off and niether is my baud rate generation as the bits are consistantly all exactly as wide as they should be, right?
Ttelmah
Guest







PostPosted: Tue May 09, 2006 7:10 am     Reply with quote

The 'time delay test', is so basic, that I don't think anyone can believe you don't know how to do it. Delays are available as standard operations in CCS C, so it is just a matter of (for example), writing:
Code:

while (TRUE) {
    output_toggle(PIN_B0);
    delay_ms(10000);
}


The errors in this, should only be about four instruction times (actually varies according to what output mode is selected), and can be times with a stopwatch to verify a whole set of things. Basically, if this gives a ten second pulse, then it proves that your #use delay statement and crystal are in agreement. Any errors here, must be fixed, before looking eleswhere.

Best Wishes
new2pic



Joined: 02 May 2006
Posts: 16

View user's profile Send private message

PostPosted: Tue May 09, 2006 9:18 am     Reply with quote

im using regular c in hitide, so there is no premade delay_ms function. but if my pulse/bits are correct (correct width in seconds), there isnt a need to do a delay check to see if my clock is correct. right?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group