|
|
View previous topic :: View next topic |
Author |
Message |
Acetoel Guest
|
Measuring a Pulse with 1us resolution |
Posted: Sat Mar 22, 2003 2:46 pm |
|
|
Hello,
I new to measure a very short pulse (from 80uSec to 1000uSec). The measurement has to start with a High-To-Low trasnsition, here the program must measure the Low state and stops to measure when a Low-To-High Transition occurs.
Is this possible with this resolution? I can implenet something similar with Pic*Basic*Pro, but would like to do it with C.
Thanks
Ezequiel
___________________________
This message was ported from CCS's old forum
Original Post ID: 12961 |
|
|
Shane Rowell Guest
|
Re: Measuring a Pulse with 1us resolution |
Posted: Sun Mar 23, 2003 1:31 am |
|
|
I am not sure what device you are using, but here is what is possible.
If you have a device with CCP1 and CCP2 you can tie the two pins together and set one for falling edge and the other for rising edge. Knowing the polarity of your signal you can then determine the pulse width. You should be able to achieve .2uS resolution.
Shane
:=Hello,
:= I new to measure a very short pulse (from 80uSec to 1000uSec). The measurement has to start with a High-To-Low trasnsition, here the program must measure the Low state and stops to measure when a Low-To-High Transition occurs.
:= Is this possible with this resolution? I can implenet something similar with Pic*Basic*Pro, but would like to do it with C.
:=Thanks
:=Ezequiel
___________________________
This message was ported from CCS's old forum
Original Post ID: 12967 |
|
|
Acetoel Guest
|
Re: Measuring a Pulse with 1us resolution |
Posted: Sun Mar 23, 2003 5:21 am |
|
|
Hi,
I'm using a 16F76 at 16MHz. Do you have a piece of code?
Thanks
Eze
:=I am not sure what device you are using, but here is what is possible.
:=
:=If you have a device with CCP1 and CCP2 you can tie the two pins together and set one for falling edge and the other for rising edge. Knowing the polarity of your signal you can then determine the pulse width. You should be able to achieve .2uS resolution.
:=
:=Shane
:=
:=:=Hello,
:=:= I new to measure a very short pulse (from 80uSec to 1000uSec). The measurement has to start with a High-To-Low trasnsition, here the program must measure the Low state and stops to measure when a Low-To-High Transition occurs.
:=:= Is this possible with this resolution? I can implenet something similar with Pic*Basic*Pro, but would like to do it with C.
:=:=Thanks
:=:=Ezequiel
___________________________
This message was ported from CCS's old forum
Original Post ID: 12970 |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
Re: Measuring a Pulse with 1us resolution |
Posted: Sun Mar 23, 2003 2:52 pm |
|
|
:=Hi,
:= I'm using a 16F76 at 16MHz. Do you have a piece of code?
:=Thanks
Hi:
Try starting with this
#include <16F876.H>
#device *=16
#fuses XT,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000) //using 4Mhz crystal you'll get 1 us increment
#use rs232(BAUD=9600, XMIT=PIN_C6, RCV=PIN_C7, ENABLE=PIN_C5, ERRORS)
#zero_ram
long int counter;
int end_counter_ready, enable_counter;
void main()
{
printf("\r\nRunning...");
enable_interrupts(INT_EXT);
ext_int_edge(H_to_L);
enable_interrupts(GLOBAL);
while(TRUE)
{
if(end_counter_ready)
{
printf("\r\nCounter \%lu ", counter);
end_counter_ready = FALSE;
delay_ms(200);
enable_interrupts(GLOBAL);
}
while(enable_counter)
{
counter++;
}
enable_counter = FALSE;
enable_interrupts(INT_EXT);
}
}
#int_EXT
edge_detect_isr()
{
if(!enable_counter)
{
enable_counter = TRUE;
ext_int_edge(L_to_H);
counter = 0;
}
else
{
enable_counter = FALSE;
end_counter_ready = TRUE;
ext_int_edge(H_to_L);
disable_interrupts(INT_EXT);
}
}
Hope this help
Humberto
___________________________
This message was ported from CCS's old forum
Original Post ID: 12979 _________________ Humber |
|
|
Acetoel Guest
|
Re: Measuring a Pulse with 1us resolution |
Posted: Sun Mar 23, 2003 6:57 pm |
|
|
Hi Humberto,
The High to Low Transition, in which pins has to occur. I think in the CCP1 pin, but I cannot see a reference to CCP1 in your code.
Thanks
Ezequiel
:=:=Hi,
:=:= I'm using a 16F76 at 16MHz. Do you have a piece of code?
:=:=Thanks
:=
:=
:=Hi:
:=Try starting with this
:=
:=#include <16F876.H>
:=#device *=16
:=
:=#fuses XT,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP
:=#use delay(clock=4000000) //using 4Mhz crystal you'll get 1 us increment
:=#use rs232(BAUD=9600, XMIT=PIN_C6, RCV=PIN_C7, ENABLE=PIN_C5, ERRORS)
:=#zero_ram
:=
:=long int counter;
:=int end_counter_ready, enable_counter;
:=
:=
:=void main()
:={
:= printf("\r\nRunning...");
:= enable_interrupts(INT_EXT);
:= ext_int_edge(H_to_L);
:= enable_interrupts(GLOBAL);
:=
:= while(TRUE)
:= {
:= if(end_counter_ready)
:= {
:= printf("\r\nCounter \%lu ", counter);
:= end_counter_ready = FALSE;
:= delay_ms(200);
:= enable_interrupts(GLOBAL);
:= }
:=
:= while(enable_counter)
:= {
:= counter++;
:= }
:=
:= enable_counter = FALSE;
:= enable_interrupts(INT_EXT);
:= }
:=}
:=
:=
:=#int_EXT
:=edge_detect_isr()
:={
:= if(!enable_counter)
:= {
:= enable_counter = TRUE;
:= ext_int_edge(L_to_H);
:= counter = 0;
:= }
:= else
:= {
:= enable_counter = FALSE;
:= end_counter_ready = TRUE;
:= ext_int_edge(H_to_L);
:= disable_interrupts(INT_EXT);
:= }
:=}
:=
:=Hope this help
:=
:=Humberto
___________________________
This message was ported from CCS's old forum
Original Post ID: 12987 |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
Re: Measuring a Pulse with 1us resolution |
Posted: Sun Mar 23, 2003 7:36 pm |
|
|
:=Hi Humberto,
:= The High to Low Transition, in which pins has to occur. I think in the CCP1 pin, but I cannot see a reference to CCP1 in your code.
:=Thanks
:=Ezequiel
Ezequiel:
Nop, I donīt use CCP1, instead I use external -edge selected- interrupt. I assume that to implement that you must use PIN_B0
to activate the interrupt hardware in 16F87x.This works fine.
Humberto
:=:=:=Hi,
:=:=:= I'm using a 16F76 at 16MHz. Do you have a piece of code?
:=:=:=Thanks
:=:=
:=:=
:=:=Hi:
:=:=Try starting with this
:=:=
:=:=#include <16F876.H>
:=:=#device *=16
:=:=
:=:=#fuses XT,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP
:=:=#use delay(clock=4000000) //using 4Mhz crystal you'll get 1 us increment
:=:=#use rs232(BAUD=9600, XMIT=PIN_C6, RCV=PIN_C7, ENABLE=PIN_C5, ERRORS)
:=:=#zero_ram
:=:=
:=:=long int counter;
:=:=int end_counter_ready, enable_counter;
:=:=
:=:=
:=:=void main()
:=:={
:=:= printf("\r\nRunning...");
:=:= enable_interrupts(INT_EXT);
:=:= ext_int_edge(H_to_L);
:=:= enable_interrupts(GLOBAL);
:=:=
:=:= while(TRUE)
:=:= {
:=:= if(end_counter_ready)
:=:= {
:=:= printf("\r\nCounter \%lu ", counter);
:=:= end_counter_ready = FALSE;
:=:= delay_ms(200);
:=:= enable_interrupts(GLOBAL);
:=:= }
:=:=
:=:= while(enable_counter)
:=:= {
:=:= counter++;
:=:= }
:=:=
:=:= enable_counter = FALSE;
:=:= enable_interrupts(INT_EXT);
:=:= }
:=:=}
:=:=
:=:=
:=:=#int_EXT
:=:=edge_detect_isr()
:=:={
:=:= if(!enable_counter)
:=:= {
:=:= enable_counter = TRUE;
:=:= ext_int_edge(L_to_H);
:=:= counter = 0;
:=:= }
:=:= else
:=:= {
:=:= enable_counter = FALSE;
:=:= end_counter_ready = TRUE;
:=:= ext_int_edge(H_to_L);
:=:= disable_interrupts(INT_EXT);
:=:= }
:=:=}
:=:=
:=:=Hope this help
:=:=
:=:=Humberto
___________________________
This message was ported from CCS's old forum
Original Post ID: 12988 _________________ Humber |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
Re: Measuring a Pulse with 1us resolution |
Posted: Sun Mar 23, 2003 8:14 pm |
|
|
:=:=Hi Humberto,
:=:= The High to Low Transition, in which pins has to occur. I think in the CCP1 pin, but I cannot see a reference to CCP1 in your code.
:=:=Thanks
:=:=Ezequiel
:=
:=Ezequiel:
Nop, I donīt use CCP1, instead I use external -edge selected- interrupt. I assume that to implement that you must use PIN_B0
to activate the interrupt hardware in 16F87x.This works fine.
#include <16F873.H>
#device *=16
#fuses XT,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000) //using 4Mhz crystal you'll get 1 us increment
#use rs232(BAUD=9600, XMIT=PIN_C6, RCV=PIN_C7, ENABLE=PIN_C5, ERRORS)
#zero_ram
long int counter;
int end_counter_ready, enable_counter;
void main()
{
printf("\r\nRunning...");
enable_interrupts(INT_EXT);
setup_timer_1 ( T1_INTERNAL | T1_DIV_BY_1 );
ext_int_edge(H_to_L);
enable_interrupts(GLOBAL);
while(TRUE)
{
if(end_counter_ready)
{
end_counter_ready = FALSE;
printf("\r\nCounter \%lu ", counter);
delay_ms(500); // choose your update time interval
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
}
do
{
}while(enable_counter);
}
}
#int_EXT
edge_detect_isr()
{
if(!enable_counter) // first falling edge
{
enable_counter = TRUE;
enable_interrupts(INT_TIMER1);
set_timer1(0);
counter = 0;
}
else
{ // second falling edge
disable_interrupts(INT_TIMER1);
counter = get_timer1();
disable_interrupts(INT_EXT);
enable_counter = FALSE;
end_counter_ready = TRUE;
}
}
Hope this help
Humberto
___________________________
This message was ported from CCS's old forum
Original Post ID: 12989 _________________ Humber |
|
|
Acetoel Guest
|
Re: Measuring a Pulse with 1us resolution |
Posted: Mon Mar 24, 2003 3:50 am |
|
|
Hi Humberto,
Thanks very much for your help. My code starts with no interrupt enable, I need only to measure 1 (ONE) High to Low Transition. I have PB.0 connected to PC.7 (HUART RX)and a pull up resistor. So I need to measure 1 start bit pulse, and with that measurement I can determine the baud rate. Can I use PC.7 (In I/O Mode) directly?
Thanks
Ezequiel
:=:=:=Hi Humberto,
:=:=:= The High to Low Transition, in which pins has to occur. I think in the CCP1 pin, but I cannot see a reference to CCP1 in your code.
:=:=:=Thanks
:=:=:=Ezequiel
:=:=
:=:=Ezequiel:
:=
:=
:=Nop, I donīt use CCP1, instead I use external -edge selected- interrupt. I assume that to implement that you must use PIN_B0
:=to activate the interrupt hardware in 16F87x.This works fine.
:=
:=
:=#include <16F873.H>
:=#device *=16
:=
:=#fuses XT,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP
:=#use delay(clock=4000000) //using 4Mhz crystal you'll get 1 us increment
:=#use rs232(BAUD=9600, XMIT=PIN_C6, RCV=PIN_C7, ENABLE=PIN_C5, ERRORS)
:=#zero_ram
:=
:=long int counter;
:=int end_counter_ready, enable_counter;
:=
:=
:=void main()
:={
:= printf("\r\nRunning...");
:= enable_interrupts(INT_EXT);
:= setup_timer_1 ( T1_INTERNAL | T1_DIV_BY_1 );
:= ext_int_edge(H_to_L);
:= enable_interrupts(GLOBAL);
:=
:= while(TRUE)
:= {
:= if(end_counter_ready)
:= {
:= end_counter_ready = FALSE;
:= printf("\r\nCounter \%lu ", counter);
:= delay_ms(500); // choose your update time interval
:= enable_interrupts(INT_EXT);
:= enable_interrupts(GLOBAL);
:= }
:=
:= do
:= {
:=
:= }while(enable_counter);
:= }
:=}
:=
:=
:=#int_EXT
:=edge_detect_isr()
:={
:= if(!enable_counter) // first falling edge
:= {
:= enable_counter = TRUE;
:= enable_interrupts(INT_TIMER1);
:= set_timer1(0);
:= counter = 0;
:= }
:= else
:= { // second falling edge
:= disable_interrupts(INT_TIMER1);
:= counter = get_timer1();
:= disable_interrupts(INT_EXT);
:= enable_counter = FALSE;
:= end_counter_ready = TRUE;
:= }
:=}
:=
:=
:=Hope this help
:=
:=Humberto
___________________________
This message was ported from CCS's old forum
Original Post ID: 12994 |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
Re: Measuring a Pulse with 1us resolution |
Posted: Mon Mar 24, 2003 9:21 am |
|
|
<font face="Courier New" size=-1>:=Hello,
:= I new to measure a very short pulse (from 80uSec to 1000uSec). The measurement has to start with a High-To-Low trasnsition, here the program must measure the Low state and stops to measure when a Low-To-High Transition occurs.
:= Is this possible with this resolution? I can implenet something similar with Pic*Basic*Pro, but would like to do it with C.
:=Thanks
:=Ezequiel
This is almost the best accuracy you may achieve. Connect an extra pin to the input signal.
While (extra_pin);
set_timer0(0);
While (!extra_pin);
get_timer0();
If the timer overflows increment another variable. You can count all the time you wish to. It only cost you an extra pin.</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 13000 |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
Re: Measuring a Pulse with 1us resolution |
Posted: Mon Mar 24, 2003 8:55 pm |
|
|
:=Hi Humberto,
:= Thanks very much for your help. My code starts with no interrupt enable, I need only to measure 1 (ONE) High to Low Transition. I have PB.0 connected to PC.7 (HUART RX)and a pull up resistor. So I need to measure 1 start bit pulse, and with that measurement I can determine the baud rate. Can I use PC.7 (In I/O Mode) directly?
Yes, you can use it BUT you need to disable the INT_RDA and enable the INT_EXT interrupt until you get the count pulses you expect to discriminate what the baud rate is, then you need to disable INT_EXT and enable the INT_RDA to enable the hardware UART and get the next char, I think you will lost the first character, you need to work around. The only pin that can trigger the INT_EXT is PB0.
regards,
Humberto
:=
:=Thanks
:=Ezequiel
:=
:=:=:=:=Hi Humberto,
:=:=:=:= The High to Low Transition, in which pins has to occur. I think in the CCP1 pin, but I cannot see a reference to CCP1 in your code.
:=:=:=:=Thanks
:=:=:=:=Ezequiel
:=:=:=
:=:=:=Ezequiel:
:=:=
:=:=
:=:=Nop, I donīt use CCP1, instead I use external -edge selected- interrupt. I assume that to implement that you must use PIN_B0
:=:=to activate the interrupt hardware in 16F87x.This works fine.
:=:=
:=:=
:=:=#include <16F873.H>
:=:=#device *=16
:=:=
:=:=#fuses XT,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP
:=:=#use delay(clock=4000000) //using 4Mhz crystal you'll get 1 us increment
:=:=#use rs232(BAUD=9600, XMIT=PIN_C6, RCV=PIN_C7, ENABLE=PIN_C5, ERRORS)
:=:=#zero_ram
:=:=
:=:=long int counter;
:=:=int end_counter_ready, enable_counter;
:=:=
:=:=
:=:=void main()
:=:={
:=:= printf("\r\nRunning...");
:=:= enable_interrupts(INT_EXT);
:=:= setup_timer_1 ( T1_INTERNAL | T1_DIV_BY_1 );
:=:= ext_int_edge(H_to_L);
:=:= enable_interrupts(GLOBAL);
:=:=
:=:= while(TRUE)
:=:= {
:=:= if(end_counter_ready)
:=:= {
:=:= end_counter_ready = FALSE;
:=:= printf("\r\nCounter \%lu ", counter);
:=:= delay_ms(500); // choose your update time interval
:=:= enable_interrupts(INT_EXT);
:=:= enable_interrupts(GLOBAL);
:=:= }
:=:=
:=:= do
:=:= {
:=:=
:=:= }while(enable_counter);
:=:= }
:=:=}
:=:=
:=:=
:=:=#int_EXT
:=:=edge_detect_isr()
:=:={
:=:= if(!enable_counter) // first falling edge
:=:= {
:=:= enable_counter = TRUE;
:=:= enable_interrupts(INT_TIMER1);
:=:= set_timer1(0);
:=:= counter = 0;
:=:= }
:=:= else
:=:= { // second falling edge
:=:= disable_interrupts(INT_TIMER1);
:=:= counter = get_timer1();
:=:= disable_interrupts(INT_EXT);
:=:= enable_counter = FALSE;
:=:= end_counter_ready = TRUE;
:=:= }
:=:=}
:=:=
:=:=
:=:=Hope this help
:=:=
:=:=Humberto
___________________________
This message was ported from CCS's old forum
Original Post ID: 13036 _________________ Humber |
|
|
Barry Gershenfeld Guest
|
Re: Measuring a Pulse with 1us resolution |
Posted: Wed Mar 26, 2003 2:18 pm |
|
|
: So I need to measure 1 start bit pulse, and with that measurement I can determine the baud rate.
Be aware that the start bit does not return high if the data bit that follows is also a zero. So you will need to watch those start bit readings for a few characters before deciding what is a usable reading. Or else instruct the host or user to always begin with certain characters.
Barry
___________________________
This message was ported from CCS's old forum
Original Post ID: 13106 |
|
|
|
|
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
|