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

how to use PWM and CCP_CAPTURE_FE ?

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



Joined: 30 Apr 2008
Posts: 4

View user's profile Send private message

how to use PWM and CCP_CAPTURE_FE ?
PostPosted: Wed Apr 30, 2008 4:04 am     Reply with quote

hi can u help me?
i use ccs c and PIC18F452.
i want to use PWM and CCP_CAPTURE_FE.

Try it but when i on PWM and CCP_CARTURE_FE TOGETHER as ccp1 and ccp2. The PWM(ccp2) did something to the CCP_CARTURE_FE(ccp1) interrupt.



Code:

#elif defined(__PCH__)
#include <18F452.h>
#device ICD=true
#fuses HS,NOWDT,NOLVP,WDT128,NOPUT,NOBROWNOUT,NOPROTECT,NOWRTD,CPD
#use delay(clock=20000000)
#use rs232(parity=N,BITS=8,xmit=PIN_C6,rcv=PIN_C7)  // Jumpers: 8 to 11, 7 to 12
#endif

int32 en=0;
int32 countstore=0,countstore2=0;
unsigned int32 count=0,duty=128;
int32 ans=0,ans3=0,ans2=0;
int32 in=0,count2=0;



#INT_TIMER1
void time1()
{
  // for(;;)
   count++;
}

#INT_CCP1
void hahah()
{

//      if(count2>=1 && count2 <17 )
//      {
      countstore2=CCP_1;
      countstore=count;
      count=0;

     // }
  //else if(count2==0)
    //  {
    //    en=CCP_1;
    //    count2++;
    //    count=0;
    // }

ans3=((countstore*65536)+countstore2)-en;
 //       printf("en=%lu \r\n ",en);
  //      printf("countstore2=%lu \r\n ",countstore2);
  //       printf("countstore=%lu \r\n ",countstore);
   //      printf("count2=%lu \r\n ",count2);
   //      printf("ans=%lu \r\n ",ans);
         countstore=0;
         in=0;
         if(en!=countstore2)
      {
        en=countstore2;
       // count2++;
       // count=0;
     }

     if(count2!=0)
     {
     ans2+=ans3;
     }
     count2++;


      if(count2==17)
      {
         ans=ans2/(count2-1);
 //        printf("countstore2=%lu \r\n ",countstore2);
  //       printf("countstore=%lu \r\n ",countstore);
  //       printf("count2=%lu \r\n ",count2-1);
         printf("ans=%lu \r\n ",ans);
  //       countstore=0;
         count2=0;
  //       countstore2=0;
         in=0;
         ans2=0;
      }
    //     countstore2=CCP_1;
    //     countstore=count;

}


void main() {

   set_uart_speed(9600);
   setup_ccp1(CCP_CAPTURE_FE);
   setup_ccp2(CCP_PWM);

   setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);
   setup_timer_2 ( T2_DIV_BY_1, 255, 1);
   enable_interrupts(INT_TIMER1);
   enable_interrupts(INT_CCP1);
   enable_interrupts(GLOBAL);
   
 for(;;)
{
   if(in==0)
   {
      if(ans>10000001 && duty >0)
      {
         duty--;
      }else if(ans<9999999 && duty <128)
      {
         duty++;
      }

    in=1; 
   }

                                 
    set_pwm2_duty(10L);             
}

}

 
Matro
Guest







PostPosted: Wed Apr 30, 2008 4:16 am     Reply with quote

Please post a small clean compilable code that demonstrates the problem and try to provide a deeper explanation of the issue you are encountering.

Matro
ruijing2



Joined: 30 Apr 2008
Posts: 4

View user's profile Send private message

PostPosted: Wed Apr 30, 2008 4:22 am     Reply with quote

#INT_TIMER1
void time1()
{
}

#INT_CCP1
void hahah()
{
}

void main() {

set_uart_speed(9600);
setup_ccp1(CCP_CAPTURE_FE);
setup_ccp2(CCP_PWM);
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);
setup_timer_2 ( T2_DIV_BY_1, 255, 1);
enable_interrupts(INT_TIMER1);
enable_interrupts(INT_CCP1);
enable_interrupts(GLOBAL);

for(;;)
{
set_pwm2_duty(10L);
}

}
ruijing2



Joined: 30 Apr 2008
Posts: 4

View user's profile Send private message

re:
PostPosted: Wed Apr 30, 2008 4:34 am     Reply with quote

it keep interrupt the ccp1 as it will interrupt at 1s only
Matro
Guest







PostPosted: Wed Apr 30, 2008 5:16 am     Reply with quote

I definitely don't understand what is the "problem".

What is your hardware?
What are you trying to do?
What did you expect?
What do you really obtain?

Matro
ruijing2



Joined: 30 Apr 2008
Posts: 4

View user's profile Send private message

PostPosted: Wed Apr 30, 2008 5:47 am     Reply with quote

i want to use EXTERNAL 1pps to read 10M count from EXTERNAL 10MHz clock. And to control the PWM.
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