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

#use capture can be 2 channels?

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



Joined: 09 Mar 2014
Posts: 10

View user's profile Send private message

#use capture can be 2 channels?
PostPosted: Fri Apr 10, 2015 5:10 pm     Reply with quote

I want to measure capture time by 2 channels such as CCP1 and CCP2.

However, it seems to [#use capture......] can be set only 1 channel as below.
Code:

#include <16f1938.h>
#DEVICE  ADC=10
#fuses  INTRC_IO,NOWDT,NOPROTECT,PUT,NOCPD,NOLVP,BROWNOUT,PLL_SW
#use delay(clock = 8M)
#use RS232(BAUD =19200, XMIT=PIN_C6 ,RCV=PIN_C7) 
#use capture(CCP1, FASTEST, CAPTURE_RISING, timer=1, define=capture_ticks_per_second, fastest)
#include <stdlib.h>

float32 GetFrequency(void);
//
main(){
float32 time;

time=GetFrequency();
printf("Freq=%5.2lf ",time);
}

//
float32  GetFrequency(void)
{
float32 t;
get_capture_time();
while (!get_capture_event());
t=get_capture_time();
while (!get_capture_event());
t=get_capture_time() - t;
Return(capture_ticks_per_second / t);
}

How can I measure capture time both CCP1 and CCP2 used by [#use capture........] ?
jeremiah



Joined: 20 Jul 2010
Posts: 1354

View user's profile Send private message

PostPosted: Fri Apr 10, 2015 6:11 pm     Reply with quote

As with just about any #use, there is a "stream" option. Make two different #use capture() directives and assign them different streams. Then supply the stream arguments for capture methods.
Shishido



Joined: 09 Mar 2014
Posts: 10

View user's profile Send private message

Thanks
PostPosted: Fri Apr 10, 2015 10:31 pm     Reply with quote

>
jeremiah wrote:
As with just about any #use, there is a "stream" option. >Make two different #use capture() directives and assign them different >streams. Then supply the stream arguments for capture methods.



Thank you for your quick reply. I am not familiar with 'stream' option of #use capture.
Sorry for your trouble, could you please let me know for make 2 different sample #use capture (........ stream=id) ?

Regards!
jeremiah



Joined: 20 Jul 2010
Posts: 1354

View user's profile Send private message

PostPosted: Sat Apr 11, 2015 12:12 am     Reply with quote

without having any background using your chip:

Code:

#use capture(CCP1, FASTEST, CAPTURE_RISING, timer=1, define=capture_ticks_per_second, fastest, stream=CCP1_STREAM)
#use capture(CCP2, FASTEST, CAPTURE_RISING, timer=1, define=capture_ticks_per_second, fastest, stream=CCP2_STREAM)

void main(){
   int16 v1,v2;

   while(TRUE){
      if(get_capture_event(CCP1_STREAM)){
         v1 = get_capture_time(CCP1_STREAM);
      }
      if(get_capture_event(CCP2_STREAM)){
         v2 = get_capture_time(CCP2_STREAM);
      }
   }
}



Didn't test this for compilation or correctness...just an example of using stream identifiers.
Shishido



Joined: 09 Mar 2014
Posts: 10

View user's profile Send private message

PostPosted: Sat Apr 11, 2015 2:43 am     Reply with quote

jeremiah wrote:
without having any background using your chip:

Code:

#use capture(CCP1, FASTEST, CAPTURE_RISING, timer=1, define=capture_ticks_per_second, fastest, stream=CCP1_STREAM)
#use capture(CCP2, FASTEST, CAPTURE_RISING, timer=1, define=capture_ticks_per_second, fastest, stream=CCP2_STREAM)

void main(){
   int16 v1,v2;

   while(TRUE){
      if(get_capture_event(CCP1_STREAM)){
         v1 = get_capture_time(CCP1_STREAM);
      }
      if(get_capture_event(CCP2_STREAM)){
         v2 = get_capture_time(CCP2_STREAM);
      }
   }
}



Didn't test this for compilation or correctness...just an example of using stream identifiers.


//////////////////////////////////////
Thanks! However I face compile error when double [#use capture] defined.

--- Info 300 "PWM_1.c" Line 13(1,1): More info: Timer 1 tick is 500 ns
*** Error 99 "PWM_1.c" Line 14(5,116): Option invalid Bad Option: DEFINE
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Apr 11, 2015 7:00 am     Reply with quote

hmm...

define=capture_ticks_per_second


compiler doesn't 'like' this. Check the PIC header to see what options for DEFINE are valid.


Jay
Shishido



Joined: 09 Mar 2014
Posts: 10

View user's profile Send private message

Resolves
PostPosted: Sat Apr 11, 2015 7:17 am     Reply with quote

temtronic wrote:
hmm...

define=capture_ticks_per_second


compiler doesn't 'like' this. Check the PIC header to see what options for DEFINE are valid.


Jay


///////////////////////////////////
Thank you very much again, finally resolved problem

#use capture(CCP3, FASTEST, CAPTURE_RISING, timer=1, stream=CCP1_IN,define=capture_ticks_per_second1,fastest)
#use capture(CCP4, FASTEST, CAPTURE_RISING, timer=1, stream=CCP2_IN,define=capture_ticks_per_second2,fastest)
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