measure pulse width
Hi,
OK first method :
withut int
while(1)
{
while(input(PIN_B0));
set_timer1(0);
while(!input(PIN_B0));
puls=get_timer1();
printf("%lu",puls);
}
you must setup timer_1 depend of your pulse width. This is very simple method, can use with all timer, if we talk specially for timer 1 you can use start/stap bit to enable disable timer, and then only read and clear after reading.
whit intterupt
ext interrupt subroutine
#int_ext
ext_IRS()
{
if(!start_mes)
{
start_mes=true;
set_timer1(0);
ext_int_edge( L_TO_H );
}
else
{
puls=get_timer1();
start_mes=false;
mes_compl=true;
ext_int_edge( H_TO_L );
}
}
main routine
ext_int_edge( H_TO_L );
while(1)
{
if(mes_compl)
{
mes_compl=false;
printf("%lu",puls);
}
}
this is one of the possible way, using ext int pin, you must enable this interrupt. When start the soft, your interrupt will be High to Low, when you receive the interrupt, soft clear the timer 1 and after this configurate ext int pin to generate interrupt on Low to Hig. when impulse going again to 1, you read the timer and set measurement complete bit to 1.
Yu can use port B change interrupt, then no neet to preconfigurate the interrupt edge becouse port B4-B7 generate enterrupt on both edge.
This is the idea, you can use CCP module for this measurement too.