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

interrupts questions
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Thu May 08, 2008 8:39 am     Reply with quote

Hi

you think is problem stay on software or hardware?

a post there my circuit... I stay think problem can stay on resistor R2? I need this for put program with bootload (colt PIC).

now I stay on university but at night I try remove this resistor...

[img][/img]
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Thu May 08, 2008 6:18 pm     Reply with quote

Hi

I stupid... you have reason... I need put max232 after GPS and conect them to PIC for it work...

I dont have time for test interrupts yet but tomorow I test and put there the results... and upgrade my circuit for all can see..

regards
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

PostPosted: Fri May 09, 2008 5:02 am     Reply with quote

filjoa wrote:
Hi
..I try remove this resistor (R2)...


Yes, remove it. When the BC547 transistor is switched on, +5v gets forced onto pin 18, which is good. But when the BC457 transistor is switched off, then all you have to determine the voltage at pin 18 is a voltage divider with 10K to +5v and 47K to GND. That comes out to 4.12v, which is still so close to +5 that it appears as logic high to pin 18. So pin 18 is always seeing logic high, regardless of what is coming in from GPS-3(TX).

Robert Scott
Real-Time Specialties
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Fri May 09, 2008 2:25 pm     Reply with quote

Hi

now I make the new circuit... and this circuit work fine... i dont need remove resistor...



and this is my new program:
Code:

#include <18F252.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=4800, parity=N, xmit=PIN_C6, rcv=PIN_C7, bits=8, stream=gpsport)
#use rs232(baud=4800, parity=N, xmit=PIN_C4, rcv=PIN_C5, bits=8, stream=tlmport)

#build(reset=0x200)
#build(interrupt=0x208)
#org 0x0000,0x01ff
void bootloader() {
#asm
  nop
#endasm
} // Reserve space for the bootloader


#int_rda
void rda_isr(void)
{
char c, string[61];
int i,k;

c=getc(gpsport);

   if (c=='$')
   {
   i=0;
   k=0;
      do
      {
      c=getc(gpsport);
      i++;
      string[i]=c;
      }while(c!='*');
      i=i-1;
      fprintf(tlmport, "array size: %u\n\r",i);
     
      //$GPRMC,161229.000,A,3723.2475,N,12158.3416,W,0.13,309.62,120598,,*10
      for(k=2;k<=12;k++)
      {
      fprintf(tlmport, "data: %c\n\r",string[k]);
      }
   }
}

void main ()
{
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);

while(1)
{
fprintf(tlmport,"wait for first character \n\r");
}

}

now my problem is:

this program only go to interrupt function 1 time :S... for example...
on terminal it write "wait for first character" many times and only go interrupt if I press reset but one time only... after that return write "wait for first character"

I dont need disable interrupts after go into "rda_isr(void)" and enable at the end?
I dont need clear flags??

I think witch I need make this but I dont know...

some one can correct this program?

regards
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

PostPosted: Fri May 09, 2008 2:40 pm     Reply with quote

You should never call these kinds of functions from within an interrupt routine:

fprintf(tlmport, "array size: %u\n\r",i);
fprintf(tlmport, "data: %c\n\r",string[k]);

Also, you should not call getc() more than once in the interrupt routine. Interrupt routines are supposed to be fast and return immediately after they do their work. You have made the interrupt routine wait for more characters to come in, and for characters to be written to the terminal. Redesign your program to do these things in your main program.

Robert Scott
Real-Time Specialties
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Fri May 09, 2008 4:15 pm     Reply with quote

hi

you think which is more correct I make the program like that?

Code:

#include <18F252.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=4800, parity=N, xmit=PIN_C6, rcv=PIN_C7, bits=8, stream=gpsport)
#use rs232(baud=4800, parity=N, xmit=PIN_C4, rcv=PIN_C5, bits=8, stream=tlmport)

#build(reset=0x200)
#build(interrupt=0x208)
#org 0x0000,0x01ff
void bootloader() {
#asm
  nop
#endasm
} // Reserve space for the bootloader


#int_rda
void rda_isr(void)
{
char c;

c=getc(gpsport);

   if (c=='$')
   {
   test();
   }
}


void test()
{

char c, string[61];
int i,k;


   i=0;
   k=0;

      do
      {
      c=getc(gpsport);
      i++;
      string[i]=c;
      }while(c!='*');
      i=i-1;
      fprintf(tlmport, "array size: %u\n\r",i);
     
      //$GPRMC,161229.000,A,3723.2475,N,12158.3416,W,0.13,309.62,120598,,*10
      for(k=2;k<=12;k++)
      {
      fprintf(tlmport, "data: %c\n\r",string[k]);
}


void main ()
{
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);

while(1)
{
fprintf(tlmport,"wait for first character \n\r");
}

}



but I don't need clean flags? I dont need disable and enable interrupts?
I think read some like this but I dont know make this :(

regards
Ttelmah
Guest







PostPosted: Sat May 10, 2008 3:12 am     Reply with quote

You need to switch the way this works completely.
As it stands, you use fprintf, both inside the interrupt (yetch), and outside. As such, interrupts _will_ be disabled during the fprintf in the main code. Since this comprises almost all the main code (except for the fraction of a second while it loops), interrupts will be disabled almost all the time.
Though I have 'writing code for you', and this is still not elegantly done (it'll sit for a long time in 'test', when it could be doing other things), this gives a better idea of how this should be approached:
Code:

int8 c;
int1 data_available = FALSE;
#define LOOP_FOR (20000)

#int_rda
void rda_isr(void) {
   c=getc(gpsport);
   data_available=TRUE;
}


void test(void) {

   char string[61];
   int i=0,k=0;

   i=0;
   k=0;

      do {
         while (data_available==FALSE) ;
      }
      data_available=FALSE;
      i++;
      string[i]=c;
      }while(c!='*');
      i=i-1;
      fprintf(tlmport, "array size: %u\n\r",i);
     
      //$GPRMC,161229.000,A,3723.2475,N,12158.3416,W,0.13,309.62,120598,,*10
      for(k=2;k<=12;k++)
      {
      fprintf(tlmport, "data: %c\n\r",string[k]);
}


void main (void) {
   int16 loop=LOOP_FOR;
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);

   while(TRUE) {
      if (data_available) {
         data_available=FALSE;
         if (c=='$') test();
      }
      if (--loop==0) {
         fprintf(tlmport,"wait for first character \n\r");
         loop=LOOP_FOR;
      }
   }
}


Best Wishes
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Sat May 10, 2008 1:14 pm     Reply with quote

Hi

thanks Ttelmah, for your code...

I make some modifications and result is a lite strange... now I only need see the time on protocol $GPRMC...
I change crystal to 40Mhz

my program is:
Code:

#include <18F252.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=40000000)
#use rs232(baud=4800, parity=N, xmit=PIN_C6, rcv=PIN_C7, bits=8, stream=gpsport)
#use rs232(baud=4800, parity=N, xmit=PIN_C4, rcv=PIN_C5, bits=8, stream=tlmport)

#build(reset=0x200)
#build(interrupt=0x208)
#org 0x0000,0x01ff
void bootloader() {
#asm
  nop
#endasm
} // Reserve space for the bootloader

int8 c;
int1 data_available = FALSE;
#define LOOP_FOR (20000)

#int_rda
void rda_isr(void) {
   c=getc(gpsport);
   data_available=TRUE;
}


void test(void) {

   char string[61];
   int i=0,k=0;

   i=0;
   k=0;

      do {
         while (data_available==FALSE) ;
         
      data_available=FALSE;
      i++;
      string[i]=c;
      }while(c!='*');
     
      //$GPRMC,161229.000,A,3723.2475,N,12158.3416,W,0.13,309.62,120598,,*10
      for(k=2;k<=11;k++)
      {
      fprintf(tlmport, "%c",string[k]);
      }
      fprintf(tlmport, "\n\r");
}

void main (void)
{
   int16 loop=LOOP_FOR;
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);

   while(TRUE) {
      if (data_available) {
         data_available=FALSE;
         if (c=='C') test();
      }
      if (--loop==0) {
         //fprintf(tlmport,"wait for first character \n\r");
         loop=LOOP_FOR;
      }
   }
}


and result on terminal is this...
Quote:
$GPVTG,35
190242.000

$GPGGA,19
190243.000
90307.000

$GPGSA,A,
190312.000
190313.000
190314.000
190315.000

$GPGSA,A,
190317.000
190318.000
190319.000
190320.000
190321.000


thanks for help me

regards
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Sun May 11, 2008 2:16 pm     Reply with quote

Hi

my problem is solved.. wait 1 or 2 days and I think have more questions Cool

but I put my new code... now I try make convertions of the units for present on terminal ...

regards all
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 Previous  1, 2
Page 2 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