|
|
View previous topic :: View next topic |
Author |
Message |
Shishido
Joined: 09 Mar 2014 Posts: 10
|
#use capture can be 2 channels? |
Posted: Fri Apr 10, 2015 5:10 pm |
|
|
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: 1345
|
|
Posted: Fri Apr 10, 2015 6:11 pm |
|
|
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
|
Thanks |
Posted: Fri Apr 10, 2015 10:31 pm |
|
|
> 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: 1345
|
|
Posted: Sat Apr 11, 2015 12:12 am |
|
|
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
|
|
Posted: Sat Apr 11, 2015 2:43 am |
|
|
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: 9221 Location: Greensville,Ontario
|
|
Posted: Sat Apr 11, 2015 7:00 am |
|
|
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
|
Resolves |
Posted: Sat Apr 11, 2015 7:17 am |
|
|
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) |
|
|
|
|
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
|