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 support@ccsinfo.com

Configuring 24EP series for 115200 usart.

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Pret



Joined: 18 Jul 2006
Posts: 92
Location: Iasi, Romania

View user's profile Send private message

Configuring 24EP series for 115200 usart.
PostPosted: Tue Oct 02, 2012 2:55 am     Reply with quote

Hi guys.

I'm having this PIC24EP64GP204 with CCS 4.130 and I'm unable to find a good configuration in order to be used with 115200 baud serial. Here is an example:
Code:
#include <24EP64GP204.h>

#fuses PR, XT, NOWDT, DEBUG, NOJTAG, ICSP2, NOPROTECT

#pin_select U1TX = PIN_C8
#pin_select U1RX = PIN_C7
#pin_select U2TX = PIN_B4
#pin_select U2RX = PIN_A8

#use delay(crystal=11050000, clock=11050000)

// Configure UARTS.
#use rs232(UART1, baud = 115200, parity=N, bits=8, errors, stream = modem)
#use rs232(UART2, baud = 115200, parity=N, bits=8, errors, stream = xbee)
#use rs232(xmit = PIN_B11, rcv = PIN_B10, baud = 115200, parity=N, bits=8, errors, stream = dbg)

I'm using an external crystal with 11.5MHz. I've heard that this value has smallest error with 115200 baudrate. But anything over 19200 is total crap when I'm trying to send something. This applies to hardware serial, but for the software serial as well. This troubles me. Means that, somehow, the delay procedures are wrong.

I've tried with a crystal of 10Mhz, with several PLL configurations, but no success.
I've tried with internal clock, something like "#use delay(clock=30Mhz, internal)". Same crappy tx output.

I think I'm experiencing something similar with this post.

Any idea would be appreciated. Thanks.
Ttelmah



Joined: 11 Mar 2010
Posts: 19394

View user's profile Send private message

PostPosted: Tue Oct 02, 2012 4:52 am     Reply with quote

Obvious first thing. If your crystal is 11.5MHz, then you need 'crystal=11500000'. You are shifting the decimal digits by one, which will give a 4% timing error. Right at the limit for async serial.....

Using the internal oscillator, on these chips, I don't actually think 60MHz is possible?. The VCO output of the PLL, has a restriction that 120MHz < Fsys < 340MHz. 60MHz, doesn't meet this. I'd suspect the frequency is therefore completely invalid....

Best Wishes
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Tue Oct 02, 2012 5:00 am     Reply with quote

Have you checked that your crystal is operating properly? (You may need a 'scope)

11.5MHz is an unusual crystal frequency, and does not tally with your code.

Did you mean 11.05MHz?

Now depends on the UART sample rate which may be 4 or 16. (Set by BRGH bit)

Start from your 115,200 baud rate and multiply by 4 OR 16.


That gives 115,200Hz * 4 = 460,800Hz

OR

115,200Hz * 16 = 1,843,200Hz.


Crystals with a frequency of 460,800Hz OR 1,843,200Hz multiplied an integer SHOULD be capable of giving you ZERO error at 115,200 baud.

Standard crystals include:-

1.843,2MHz
3.686,4MHz
7.372,8MHz
9.216MHz
11.059,2MHz
14.745,6MHz
18.432MHz

Some of these will also generate other standard baud rates with zero error.


Mike
Pret



Joined: 18 Jul 2006
Posts: 92
Location: Iasi, Romania

View user's profile Send private message

PostPosted: Tue Oct 02, 2012 5:55 am     Reply with quote

Sorry, guys, yes, the crystal has 11.05MHz written on it. I was told that the value actually is 11059200.

I have tried:
Code:
#use delay(crystal=11059200, clock=11059200)
// or
#use delay(crystal=11059200, clock=22118400)
... but the result is the same. The CCS is able to set its fuses, or am I wrong?

I'm a little bit confused on how internal divisors and PLL works on this chip.

Thanks Mike Walne, it seems that this 11.059,2MHz is exactly what I need. It's just I can't set fuses properly...

Ttelmah, regarding internal osc, I was just specifying values to the #delay statement. I thought the CCS is somehow able to set required fuses accordingly. Since it compiled, thought that everything is fine...
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Tue Oct 02, 2012 6:23 am     Reply with quote

OK, so you've got the proper crystal.

Is it running correctly?

Have you got the correct value R and C's with the crystal?

Can you probe the oscillator O/P with a 'scope?

Does a simple LED flasher run at EXACTLY the right speed?

Try sending a continuous stream of letter 'A's, and proble with a 'scope.

If the hardware is wrong, no amount of playing with the code will help.

Mike
Pret



Joined: 18 Jul 2006
Posts: 92
Location: Iasi, Romania

View user's profile Send private message

PostPosted: Tue Oct 02, 2012 6:53 am     Reply with quote

Sorry, I don't have an OSC at the moment...
I made the simplest possible code using a software serial:
Code:
#include #include <24EP64GP204.h>

#fuses XT, NODEBUG, NOWDT, NOWRT

#use delay(crystal=11059200, clock=11059200)
#use rs232(force_sw, xmit = PIN_B11, rcv = PIN_B10, baud = 115200, parity=N, bits=8, errors, stream = dbg)

void main()
{
   for(;;)
   {
      delay_ms(1000);
      fprintf(dbg, "Hello world!\n");
   }
}
Since this is a software serial, I believe that the only thing that you need to get it right is the actual cpu clock. The compiler only needs this value for calculating the software delay. Well, this code is not working. I works only for 19200. Anything above is scrambled eggs. Most probably the code lacks on some fuse definitions and I don't think I know which one are them...

I find it hard to believe that there is a hw problem...
Ttelmah



Joined: 11 Mar 2010
Posts: 19394

View user's profile Send private message

PostPosted: Tue Oct 02, 2012 7:33 am     Reply with quote

Start with the first part of Mike's suggestion. An LED flasher. Serial should only be touched, once you are _sure_ your hardware is running at the correct rate.

Best Wishes
Pret



Joined: 18 Jul 2006
Posts: 92
Location: Iasi, Romania

View user's profile Send private message

PostPosted: Tue Oct 02, 2012 8:55 am     Reply with quote

Ok, I understand and I agree. I'll do some hw test as soon as possible. But still, a question. What if I just replace (on the same code) the #use statement with
Code:
#use delay(internal=16Mhz)
... would this be a valid configuration? In this manner it shouldn't have any dependency on external Q. Still, the result is the same.

I'm novice in hw, but is it possible to have a faulty max232 what works fine on lower baudrates, but fails on higher rates? I'm just trying to eliminate any external possibilities...
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Tue Oct 02, 2012 11:09 am     Reply with quote

Using a 'scope saves a lot of hassle.

Mike
Ttelmah



Joined: 11 Mar 2010
Posts: 19394

View user's profile Send private message

PostPosted: Tue Oct 02, 2012 3:19 pm     Reply with quote

Yes, the whole RS232 bus.
First, the maximum cable length declines massively as baud rates go up. At 115200, even if everything is 'in spec', you are limited to typically about 8' maximum cable length. The available drive, also limits the bus capacitance to well under the 2500pF allowed at 9600bps.
Second, the max232 itself is only warranted to 64kbps with 0.1uF capacitors 120k requires 1uF on the inverter lines. You need the max232A, to guarantee the higher rate with 0.1uF capacitors.
Third, the current required from the supply shoots up at higher rates. This affects the incoming supply as well.

Best Wishes
Pret



Joined: 18 Jul 2006
Posts: 92
Location: Iasi, Romania

View user's profile Send private message

PostPosted: Wed Oct 03, 2012 3:35 am     Reply with quote

Oh, crap. Mea culpa. The max is doomed.

He's simply unable to work with baudrates over 19200. I have checked with an OSC and the input is fine, but the output is scrambled. On 115200 is barely outputting some spikes. I have both serials being connected to it. It's a max2323. Those four capacitors are 1uF and there is another 10uF on its power input. The power source is pretty stable, with LM2675M...

I think I'll just replace it. Hopefully it's not a hw design problem...

Thanks for help guys...
Ttelmah



Joined: 11 Mar 2010
Posts: 19394

View user's profile Send private message

PostPosted: Wed Oct 03, 2012 4:06 am     Reply with quote

Er.
Go back and check your chip number....

MAX2323, is _not_ an RS232 transceiver. It's a CDMA mixer.

Hopefully 3232 - which is the 3v to 5v max232. These are very rugged devices, and are rated for 250kbps operation. What is the nature of your actual wire connection - length, type of wire, extra resistive loads, etc. etc.?

Have you triple checked your pin-outs, and particularly the polarities and locations of the capacitors. First cap, pin2, to +ve, pin4 -ve. Second, pin5 +ve pin6-ve. Third pin7 -ve Gnd to the +ve end. Fourth pin3 +ve -ve end to either Vcc, or GND. Finally Vcc to +ve and gnd to -ve. Total of five capacitors. You talk about four, which suggests you may have one missing!.....

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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