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

How to fast is fast enough to prevent overrun error.

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








How to fast is fast enough to prevent overrun error.
PostPosted: Thu Dec 16, 2004 12:20 pm     Reply with quote

Hello,

I want to knoe how to avoid the overrun error on a 18LF452.
I can write code on a 16F877A in the #int_RDA to get a byte from the com port, store it, check it, and set a result. No lockup. But when i try to do the same thing in the 'LF452, no matter what i try, i get overrun error.

I have tried using the code in the examples dir., and they will lockup.
I have put a simple 'buffer = getc(); inc buffer element' removing all format code, and OERR fires.
I have even used inline #ASM and use the Microchip example code, and i still get the same problem.
I suspect it could be a setting issue, and i've check all comms related regs.

I don't want to use the ERRORS, as i will lose a byte. I look at my LST file and notice 0xFAF (SPBRG) is set to 0x19. The DCE is 9600 8N1 and the PIC isset the same.

What options are there to get over this.?
Guest








How to fast is fast enough to prevent overrun error.
PostPosted: Thu Dec 16, 2004 12:23 pm     Reply with quote

Just to add,
this is the first time i am using a resonator rated a 4Mhz with built in caps.

Normally i use Xtal Osc.modules.
languer



Joined: 09 Jan 2004
Posts: 144
Location: USA

View user's profile Send private message

PostPosted: Thu Dec 16, 2004 1:38 pm     Reply with quote

This link may provide some help,

http://www.picbasic.co.uk/forum/showthread.php?s=&threadid=702

Quote:
On the 16F series you have an 8 level deep stack, and once it's filled up, it starts being over-written (circular type buffer) by further return addresses pushed onto the stack from top-to-bottom.

While your program may or may not work on a 16F part when doing this, it can still cause trouble depending on how many consecutive calls you have before returns start (referred to as nesting) popping addresses back off the stack.

You have return addresses being pushed onto the stack by PBP library functions + your own code. With the 16F's circular type stack buffer, you're getting by with the boo-boo because return addresses are still being pushed on the stack (simply overwritting previous contents), and all's well if you're not nesting calls too deep.

One the 18F parts you have a 31 level stack, BUT, it's not the circular type buffer like you have with the 16F. Once you get to location 31 the 32nd return address simply overwrites location 31,
and it's sit & spin at location 31 from there on.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Dec 16, 2004 1:54 pm     Reply with quote

1. What happens if you test the 18LF452 with a crystal, instead of the resonator ?

2. What voltage are you using for the 18LF452 ?

3. Are you using a MAX232-type chip ?

4. What's your version of the CCS compiler ?

5. What is the source of the RS-232 data stream ? What is the
spacing between the bytes ? (in microseconds or milliseconds)

6. Post your test program (complete with all #fuses statements, etc.)
Show the complete (but small) test program.
Guest








PostPosted: Thu Dec 16, 2004 3:08 pm     Reply with quote

Hiya,

Quote:

1. What happens if you test the 18LF452 with a crystal, instead of the resonator ?


I normally use a clock module with XT set. Using it now i get the same response. So i think that's not the problem.
I also get 3.98Mhz on OSC2 pin using the resonator.

Quote:

2. What voltage are you using for the 18LF452 ?


I believe the fact it is 'LF' says it can operated a lower voltages, but i am using 5v off a regulator.

Quote:

3. Are you using a MAX232-type chip ?


Yepp, MAX232CPE from MAXIM.


Quote:

4. What's your version of the CCS compiler ?


MPLAB v6.30
v3.200 PCWH

Quote:

5. What is the source of the RS-232 data stream ? What is the
spacing between the bytes ? (in microseconds or milliseconds)


Not entirely sure.

Quote:

6. Post your test program (complete with all #fuses statements, etc.)
Show the complete (but small) test program.


Code:

#include <18F452.h>
#device adc=8
#use delay(clock=4000000)
#fuses NOWDT,HS, PROTECT, NOOSCSEN, BROWNOUT, BORV20, PUT, STVREN, NODEBUG, NOLVP, NOWRT, NOWRTD, NOWRTB, NOWRTC, NOCPD, NOCPB, NOEBTR, NOEBTRB
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=9,stream=GSM)
#use rs232(baud=9600,parity=N,xmit=PIN_D1,rcv=PIN_C1,bits=8,stream=COM)



#byte   RCREG   =0xFAE
#bit   OERR    =RCREG.1
#bit   FERR   =RCREG.2
#bit   CREN   =RCREG.4

char InBuff[20];
int8 t=0;
int8 i;

void SetupMCU()
{
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);

   }

#int_RDA

RDA_isr()
{
    InBuff[t]=fgetc(GSM);   

    if(OERR)
   {
   output_high(PIN_E1);
      CREN=0;
      CREN=1;
   }
   else
   {
   
   }
   if(FERR)
   {
   output_high(PIN_E2);
   }
   else
   {

   }
    t=(t+1)%sizeof(InBuff);    // just inc the buffer
}

void main()
{
SetupMCU();

output_high(PIN_E0);
delay_ms(1000);
output_low(PIN_E0);
delay_ms(1000);

    enable_interrupts(INT_RDA);
    enable_interrupts(GLOBAL);

// clear the buffer
for(i=0; i<sizeof(InBuff); i++)
{
   InBuff[i]=0;
}

do{

fputs("AT\r\n",GSM);

delay_ms(1000);
fputs(InBuff,COM);
}
while(1);


}

Guest








40,000,000 OR 3,980,000
PostPosted: Thu Dec 16, 2004 4:41 pm     Reply with quote

[quote="Anonymous"]Hiya,

Quote:

I normally use a clock module with XT set. Using it now i get the same response. So i think that's not the problem.
I also get 3.98Mhz on OSC2 pin using the resonator.

Code:

#include <18F452.h>
#device adc=8
#use delay(clock=4000000)



IF THE xTAL IS 3.98mhZ WHY ARE YOU USING A CLOCK = 40,000,000
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Dec 16, 2004 4:52 pm     Reply with quote

There are several things I noticed, but first try to comment out these
lines withing the do-while loop. See if you still get the error.
Code:
do{
// fputs("AT\r\n",GSM);
// delay_ms(1000);
// fputs(InBuff,COM);
}
while(1);
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Thu Dec 16, 2004 5:37 pm     Reply with quote

Check to make sure the device is not echoing the data back. Since you are sending string you might be getting it back and could be the cause of the problem. I don't know if CCS disables ints in the fputs() call, but if they do, then that's the problem.
Guest








PostPosted: Thu Dec 16, 2004 5:51 pm     Reply with quote

Hi PCM,

Ok i have done that, i've used SIOM that comes with CCS, and i get diddly squat, nothing. PIN_E0 flashes once, OK, but i don't have any error LEDs lit. The 'COM' stream is wired into the remaining half of the MAX 232, and into the PC. As i imagined it would do.

Guest, the part is a resonator with built in caps. Marked as 4Mhz, but on Osc2 it shows 3.98Mhz.

Mark, i checked the status of the device, it has that option, but it is switched off. When i connect it the the PC (no PIC or anything else), i can send data, and nothing is echoed. I though it might have been a duff MAX232 or bad wiring. but the same wiring and chip talk to the PC with no problems.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Dec 16, 2004 6:17 pm     Reply with quote

OK, since the Error LED didn't light up, it means that one or more
of those lines in the do-while() loop is the problem. I don't have
that version of the compiler, so I can't examine the .LST file for you.
What I would be looking for is what Mark said: Is the compiler
disabling interrupts. The primary suspect for me would be the
delay_ms(1000) statement.

Try un-commenting each of those 3 lines, one at a time. If you
start to get the error, then that line will be the problem. Then we
(or someone) can look at the .LST file and find out why.
Guest








PostPosted: Thu Dec 16, 2004 8:40 pm     Reply with quote

PCM,

I've checked them, and i get both errors on OERR and FERR when just "fputs("AT\r\n",GSM); is the only working line. I am about to change the command with fprintf to see the response, but don't think it'l make any difference.

Where to i send the LST file, would i post it here or directly to those concerned?

Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Dec 16, 2004 9:17 pm     Reply with quote

You don't have to post it. I looked at the .LST file for vs. 3.188.
It's as Mark said. CCS is disabling global interrupts during the fputs(). (They do the same thing during fprintf).
Guest








PostPosted: Thu Dec 16, 2004 10:04 pm     Reply with quote

But i would have thought that would be a problem, i've used the same routine ages ago on an 16f877A

what do i do?
Guest








PostPosted: Fri Dec 17, 2004 1:34 am     Reply with quote

I mean't "wounldn't".

Quote:

But i would have thought that would be a problem, i've used the same routine ages ago on an 16f877A


I've been up late.
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Dec 17, 2004 4:01 am     Reply with quote

Code:
#byte   RCREG   =0xFAE
#bit   OERR    =RCREG.1
#bit   FERR   =RCREG.2
#bit   CREN   =RCREG.4


I suggest you go to bed. You are looking at the wrong address. You want the RCSTA register for these control bits not the RCREG


If you want to clear the buffer you should do it before you enable the serial interrupt
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
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