pete
Member level 2
Query on Pulse Width
Greetings to all:
I am experimenting on measuring a single pulse and the measured value displayed in binary as displayed in portd using 8 LEDs. Of course the timer I used is 16bit but I don't know yet how to display it in 16 LEDs using 2 ports. Also, the pulse width I input is whole number or integer value from 1usec to 50usec.
Whats wrong with my code below? I expect that if I input a 1usec pulse, the LED will read 00000001, for 2 usec 00000010, for 3 usec 00000011, for 4usec
00000100, etc... It doesn't display that way and am confused how to calibrate it, or my code is wrong. Need your help/comments. Thanks...
//None interrupt method
long pulse_width;
main()
{
trisb0=1; //make portb0 an input
trisd=0x00; //make portd an output
portd=0;
while(1)
{
setup_timer_1(T1_DISABLED);
set_timer1(0); // to overflow in 51us
while(!input(PIN_B0));
setup_timer_1(T1_INTERNAL);
while(input(PIN_B0));
setup_timer_1(T1_DISABLED);
pulse_width=get_timer1();
PORTD=pulse_width;
}
}
Greetings to all:
I am experimenting on measuring a single pulse and the measured value displayed in binary as displayed in portd using 8 LEDs. Of course the timer I used is 16bit but I don't know yet how to display it in 16 LEDs using 2 ports. Also, the pulse width I input is whole number or integer value from 1usec to 50usec.
Whats wrong with my code below? I expect that if I input a 1usec pulse, the LED will read 00000001, for 2 usec 00000010, for 3 usec 00000011, for 4usec
00000100, etc... It doesn't display that way and am confused how to calibrate it, or my code is wrong. Need your help/comments. Thanks...
//None interrupt method
long pulse_width;
main()
{
trisb0=1; //make portb0 an input
trisd=0x00; //make portd an output
portd=0;
while(1)
{
setup_timer_1(T1_DISABLED);
set_timer1(0); // to overflow in 51us
while(!input(PIN_B0));
setup_timer_1(T1_INTERNAL);
while(input(PIN_B0));
setup_timer_1(T1_DISABLED);
pulse_width=get_timer1();
PORTD=pulse_width;
}
}