Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help me with my code and the pulse width

Status
Not open for further replies.

pete

Member level 2
Joined
Aug 21, 2005
Messages
48
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,785
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;
}
}
 

Re: Query on Pulse Width

hi

i think the problem either due to mismatch with the frequency of crystal oscillator u r using with the frequency u used in the code or the time period of 1us is not perceived by ur eye to see the changes in the fractilon of seconds
so increase the delay so that u can see the changes
 

Re: Query on Pulse Width

I use 20Mhz clock. With my range of input in usecs, the LEDs are lighted but the binary value is not correct corresponding to the pulse width I have inputted.
So my problem is either my code is wrong or I have the correct code but not calibrated properly to display correct reading in binary. I understand, for every line of code, there is some delay.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top