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

need help for TCPIP+CCP1...

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



Joined: 25 Dec 2008
Posts: 32

View user's profile Send private message

need help for TCPIP+CCP1...
PostPosted: Sat Jan 31, 2009 3:56 am     Reply with quote

Hi,
I am working with my final year project which monitors heartbeat (using CCP1 to capture the pulse) through Ethernet. When i load the program into the PIC (both TCPIP stack and CCP1 are in the same program), it seems that no interrupt was detected but if the TCPIP stack is removed, the heartbeat program seems ok. Can anyone give some idea on this? Thank you very much
dyeatman



Joined: 06 Sep 2003
Posts: 1923
Location: Norman, OK

View user's profile Send private message

PostPosted: Sat Jan 31, 2009 11:20 am     Reply with quote

The question you are asking is the equivalent of:
" If I add an accessory to my car the car doesn't work any more, why not?"

Without knowing the car type, the accessory and how it was installed you wouldn't have a CLUE as to what the problem is. The same is true here...
leejok2003



Joined: 25 Dec 2008
Posts: 32

View user's profile Send private message

PostPosted: Sat Jan 31, 2009 11:47 am     Reply with quote

well, i am using PIC18F4620+ENC28J60 for the ethernet connection, and for the pulse reading, i use the same PIC and uses timer1+CCP1 function to capture the pulse.
dyeatman



Joined: 06 Sep 2003
Posts: 1923
Location: Norman, OK

View user's profile Send private message

PostPosted: Sat Jan 31, 2009 1:54 pm     Reply with quote

OK, great.
Now we need to see some code to determine how the two functions affect each other. What do you mean by:
Quote:
both TCPIP stack and CCP1 are in the same program
Later you say:
Quote:
if the TCPIP stack is removed, the heartbeat program seems ok
So apparently the TCPIP, Timer1 and CCP1 code are separate.

Show your main program with all the setup lines, include lines and complete ISR routine(s). Are you using someone elses code? If so can you provide a link to see what you are working with? Do not show the TCP/IP stack code.
leejok2003



Joined: 25 Dec 2008
Posts: 32

View user's profile Send private message

PostPosted: Sat Jan 31, 2009 9:23 pm     Reply with quote

Hi,
Sorry for my poor english... What i want to mean is that actually i write the code for CCP1+timer1 separately from the TCPIP stack initially to read pulses. This code (CCP1+timer1) works fine for reading pulses.
Then i include CCP1+timer1 code into the TCPIP stack code, which i plan to read pulses through ethernet, and this one doesn't work... Bellow is the code combine the TCPIP and the CCP1+timer1:

Code:



#define STACK_USE_ICMP  1
#define STACK_USE_ARP   1
#define STACK_USE_TCP   1
#define STACK_USE_HTTP  1
#include "ccstcpip.h"

#if STACK_USE_CCS_PICENS
 #include "tcpip/mlcd.c"
#else
 #include "tcpip/dlcd.c"
#endif

int sta1,sta2,sta3,pus,count,det;
int1 ccp_updated=FALSE;
unsigned int32 over, start_time, end_time,width,time1,t_time,heart,time2;
#INT_TIMER1
TIMER1_isr()
{
   over = over + 1;
}

#INT_CCP1

CCP1_isr()
{
   end_time = CCP_1;
   ccp_updated = TRUE;
   det=1;
   //printf("\r\n det= %d",det);
}
//here is this examples / page
const char  HTML_INDEX_PAGE[]="
<HTML>
<HEAD>
<META HTTP-EQUIV=REFRESH CONTENT=8>
<\HEAD>
<TITLE>Patient Monitoring Page</TITLE>
<BODY BGCOLOR=#ADD8E6 TEXT=#000000>
<H1 align= center>Patient Monitoring System Beta 1.0b</H1>
<HR>
<BR><I>This is a prototype which uses &quot in code&quot html page edit.</I>
<FORM METHOD=GET>
<BR>LED1:<INPUT type=\"radio\" name=\"led1\" value=1>ON &nbsp; &nbsp; &nbsp;
<INPUT type=\"radio\" name=\"led1\" value=0 checked>OFF
<BR>LED2:<INPUT type=\"radio\" name=\"led2\" value=1>ON &nbsp; &nbsp; &nbsp;
<INPUT type=\"radio\" name=\"led2\" value=0 checked>OFF
<BR><INPUT TYPE=\"submit\"></FORM>
</P>
<P>
<H3>STATUS</H3>
<TABLE WIDTH=100% BORDER-STYLE: BORDER >
<TR>
<TD>
BTN1=%4
</TD>
</TR>
<TR>
<TD>
BTN2=%5
</TD>
</TR>
<TR>
<TD>
 LED1=%2
</TD>
</TR>
<TR>
<TD>
 LED2=%3
</TD>
</TR>

</TABLE>
</P>
<DIV>
<H2>Body</H2>
<TABLE>
<TR>
<TD>
Heartbeat: %7 BPM
</TD>
</TR>
<TR>
<TD>
Temperature=<B>%0&nbsp;&nbsp;<\B>
</TD>
</TR>
<TR>
<TD>
Temperature Warning: %6
</TD>
</TR>

</TABLE>
</DIV>
<P ALIGN=LEFT><A HREF=\"/analog\">Analog Readings</A><\P>
</BODY></HTML>
";

const char  HTML_ANALOG_PAGE[]="
<HTML><BODY BGCOLOR=#ADD8E6 TEXT=#000000>
<HEAD>
<META HTTP-EQUIV=REFRESH CONTENT=8>
</HEAD>

<H1>PICNET ADC READINGS</H1>
<TABLE>
<TR>
<TD>
<DIV>Temperature</DIV>
</TD>
<TD><DIV><B>%0&nbsp;&nbsp;<\B><\DIV>
</TD>
</TR>
<TR>
<TD>

<TD>
</TR>
</TABLE>
<BR>%1
<P><A HREF=\"/\">Change LCD/LEDs</A>
</BODY></HTML>
";

//this is a callback function to the HTTP stack.  see http.c
//this demo provides to web "pages", an index (/) and an about page (/about)
int32 http_get_page(char *file_str) {
   int32 file_loc=0;
   static char index[]="/";
   static char about[]="/analog";

   printf("\r\nRequest %s ",file_str);

   if (stricmp(file_str,index)==0)
      file_loc=label_address(HTML_INDEX_PAGE);

   else if (stricmp(file_str,about)==0)
      file_loc=label_address(HTML_ANALOG_PAGE);

   if (file_loc)
      printf("(FILE=%LU)",file_loc);
   else
      printf("(File Not Found)");

   return(file_loc);
}

void heart_read(void)
{
      while(ccp_updated==FALSE);
      disable_interrupts(INT_TIMER1);
      width= get_timer1();
      time1=262140*over;
      time2= width*4;
      t_time=time1+time2;
      heart= 600000000/t_time;
      printf("\r\n heart= %lu",heart);
      ++count;
      output_high(USER_LED5);
      over = 0;//clear overflow counts
      start_time = end_time;  //end time of this pulse is the start time for the next one
      ccp_updated= FALSE;
      enable_interrupts(INT_TIMER1);
      set_timer1(0);
     
       
      //delay_ms(10);
}

void refresh()
{
   printf("\r\n pus= %d",pus);
   if(count==6)
   pus=1;
   
}

void life()
{
   output_high(USER_LED4);
   output_low(USER_LED5);
   delay_ms(60);
   output_low(USER_LED4);
}
//this is a callback function to the HTTP stack. see http.c
// this demo provides handling for two formatting chars, %0 and %1.
//  %0 is ADC for channel 0, %1 is ADC for channel 1.
/*
%0=AN0
%1=AN1
%2 - CHECKED if LED1 is ON
%3 - CHECKED if LED1 is OFF
%4 - CHECKED if LED2 is ON
%8 - CHECKED if LED2 is OFF
*/
int8 http_format_char(int32 file, char id, char *str, int8 max_ret) {
   char new_str[20];
   int8 len=0;
   float i,temp,real_volt;
 
   *str=0;

   switch(id)
   {
      case '0':
         set_adc_channel(0);
         delay_us(100);
         i=read_adc();
         real_volt=((float)i/204.6);
         temp= real_volt*100;
         sprintf(new_str,"%1.1f",temp);
         //printf("\r\n temperature= %1.1f",temp);
         len=strlen(new_str);
         break;
     
      case '6':
         if((temp<36.4)||(temp>37.6))
         {
            output_high(USER_LED3);
            printf("\r\n Temperature Warning!\r\n");
         }
         sprintf(new_str,"<B>%D</B>",sta3);
         len=strlen(new_str);
         break;
         
      #if defined(USER_BUTTON1)
      case '4':
         sprintf(new_str,"<B> </B>");
         if (input(USER_BUTTON1))
         sprintf(&new_str[3], "1");
           
         
         else
            sprintf(&new_str[3], "0");
           
           
         len=strlen(new_str);
         break;
      #endif
     
      #if defined(USER_BUTTON2)
      case '5':
         sprintf(new_str,"<B> </B>");
         if (input(USER_BUTTON2))
            {
            sprintf(&new_str[3], "1");
            enable_interrupts (INT_TIMER1); //unmask Timer1 overflow interrupt
            enable_interrupts (INT_CCP1);
            enable_interrupts (GLOBAL);
           
            }
         else
            {sprintf(&new_str[3], "0");
             disable_interrupts (INT_TIMER1);
             disable_interrupts (INT_CCP1);
             disable_interrupts (GLOBAL);
         len=strlen(new_str);
            }
         break;
      #endif
     
      /*case '1':
        #if STACK_USE_CCS_PICNET
         set_adc_channel(1);
         delay_us(100);
         i=read_adc();
         sprintf(new_str,"<B>AN1 = </B>0x%X",i);
         len=strlen(new_str);
        #else
         len=0;
        #endif
         break;
         */
         
      case '2':
      sprintf(new_str,"<B>%D </B>",sta1);
      len=strlen(new_str);
      break;
     
      case '3':
      sprintf(new_str, "<B>%D </B>",sta2);
      len=strlen(new_str);
      break;
     
     
      case '7':
      if(det==1){
      while(pus==0)
      {
       
        heart_read();
        refresh();
        sprintf(new_str,"<B>%U </B>",heart);
        len=strlen(new_str);
       
      }
     
      count=0;
      pus=0;
      }
      else
      sprintf(new_str,"<B>0</B>");
        len=strlen(new_str);
      break;
     
     
     
     


     

   }

   if (len) {
      if (len>max_ret) {len=max_ret;}
      memcpy(str,new_str,len);
   }

   return(len);
}

//this is a callback function to the HTTP stack. see http.c
//in this example it verifies that "pwd" is "master", if it is
//then it sets led1 and led2 ("led1" and "led2") based on their value
//and changes the lcd screen ("lcd").
void http_exec_cgi(int32 file, char *key, char *val) {
   static char led1_key[]="led1";
   static char led2_key[]="led2";
   static char led3_key[]="led3";
   static char lcd_key[]="lcd";
   int8 v;

   printf("\r\nCGI FILE=%LD KEY=%S VAL=%S", file, key, val);

   if (stricmp(key,led1_key)==0) {
      v=atoi(val);
      if (!v)
      {output_low(USER_LED1);
      sta1=0;}
      else {output_high(USER_LED1);
      sta1=1;}
   }

   if (stricmp(key,led2_key)==0) {
      v=atoi(val);
      if (!v)
      {output_low(USER_LED2);
      sta2=0;}
      else {output_high(USER_LED2);
      sta2=1;}
   }
    if (stricmp(key,led3_key)==0) {
      v=atoi(val);
      if (!v)
      {output_low(USER_LED3);
      sta3=0;}
      else {output_high(USER_LED3);
      sta2=1;}
   }


   if (stricmp(key,lcd_key)==0) {
      printf(lcd_putc,"\f%s",val);
   }
}


void main(void)
{
   printf("\r\n Device Started");
   
   MACAddrInit();
   IPAddrInit();

   init_user_io();

   //lcd_init();

   //printf(lcd_putc,"\fCCS CGI Example\nWaiting");
   printf("\r\n\nPatient Monitoring...\r\nWaiting");
 
   setup_adc_ports(AN0);         // saluran 0 sbg input analog
   setup_adc(ADC_CLOCK_DIV_64); // 20000000/625000 = 30.769  => 32
   setup_ccp1 (CCP_CAPTURE_RE);
   setup_timer_1 (T1_INTERNAL|T1_DIV_BY_2); //set timer1 to run at system clock / 4
   
   StackInit();

   while(TRUE) {
     
     
      StackTask();
      life();
   }
}

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