Well, if you can, try to avoid using RB0/INT for that. I just spent 3 or 4 months trying to detect zero crossing off an AC line with it, only to discover that when configured as an interrupt it is a schmitt trigger, and therefore won't work for that.... As soon as I used one of the INT on change ports (RB4 thru RB7), the unit worked almost flawlessly... Hmm, since your only wanting to know when it goes low (not high and low), RB0 might work just fine for you. Hmm, lets see here. between 0 and 240 what? Milliseconds, Microseconds, what? And after answering that one.... What kind of resolution? Again, Milliseconds, Microseconds, Nanoseconds? I'm assuming your wanting to use an internal "timer" to count the time between each pulse? Where at the beginning of the pulse you would go to your interrupt routine, and then copy the timer value into your display variable. When the pulse of done (another interrupt), test port to see if it is low. If it is, reset TMR0 to zero and then go about doing other program fuctions again. When the "next pulse" occurs, read the timer value at the end of the pulse in another part of the interrupt routine (move it to your display value memory location). This is the best way to do it, if your PIC is having to do a bunch of "other stuff" while counting pulses (calculations, displaying, etc...) Okay, lets pretend your wanting to measure between pulses in Milliseconds, from 1ms to 250ms (because 250ms is exactly 1/4th of a second, which is a better "multiple" to work with). At 4mhz (FOSC/4= counter speed of 1mhz), an eight bit timer (like TMR0) at a 1:1 ratio can only count up to 255 microseconds(us) (about 1/4th of a millisecond), so you'd have to prescale the timer if you want it to get up to 250 milliseconds before it rolls over (read the data sheets for that PIC). For upto 250 milliseconds (255 max), you would need to set the prescaler to a 1:977 ratio (takes 977 clock cycles to increment the timer once). Obviously, this won't work (the prescaler ratio limit is only 256). You'll NEED a PIC with a 16 bit timer (TMR1) in order to do it this way (a 16 bit TMR1 can go to 65535 before rolling over). For a 16 bit timer, you'd set the prescaler to a 1:4 ratio (65535 * 4 = 262140us, or a bit over 1/4 of a second), which will also give you 4us timer resolution. I might suggest the F87x PICs for prototyping. Now, what happens if the timer overflows?!? i.e., if the time between pulses is longer than 1/4 second (or the maximum timer value of 262140)? Build part of your interrupt routine to test and compensate for this eventuallity (i.e., less than 4 beats per second). If the interrupt detects a timer overflow (interrupt was caused by a TMR1 overflow), then you could put a special value into your variable that holds the display value (it would have to be a 16 bit variable then), or set a flag of some sort, so that your display routine would then know that it needs to tell you this (like displaying "OL" for "Over Load", or "LF" for "Low Frequency". The only way I can see doing this on an F84 part would be to write a tight loop in ASM (4 or 5 clocks long) that increments a 16 bit variable until the port goes high again. Of course, your program will be stuck in this loop between pulses (more hardware will probably be needed to drive your display then). You'll also have to divide your timer value by an appropriate value (like 1000) to get it down to 250 or less. ; port RB0 is used as the pulse low counting pin, set as an input. ; This routine will take 5 clocks to loop, giving you a 1:5 clock timer ratio ; minus what ever time it takes to get to it.... ; BIG_TMR is a 16 bit variable that you've defined (not an internal timer) ; You'd enter this routine as soon as RB0 goes low (via an interrupt) start BTFSC PORTB,0 ; Test bit 7 of portb, skip next instruction if clear (pin low) GOTO end ; If RB7 is set (high/pulse), then exit loop INCFSZ BIG_TMR,1 ; manually Increment 16 BIT COUNTER by one GOTO start ; if BIG_TMR not overflowed, goto start MOVF D_ERROR,0 ; if BIG_TMR IS overflowed, move error value to W MOVWF DISP_EF ; Move W to display error flag (used in display routine) end ; do what ever clean up needs to be done (reset RB0 interrupt flag, divide BIG_TMR by an appropriate value, move it to display value, etc...) I think this will work, but I'm pretty new to MPASM myself (anyone else wanna check it?). It would be nicer if it could loop in 4 clocks too. Another problem with the manual timer method, is that if your pulse lengths are "too short", you won't have enough time to display it, as that is the only time when it is NOT sitting in that interrupt loop, or you'll at least need more display hardware support so it doesn't blink (especially if using led displays directly driven). BTW, your pulse lengths will have to be at last 1 TCY long in order to be detected by the interrupt on change ports. I'm thinking that is at least one microsecond (us) at 4mhz. -----Original Message----- From: Kajcsa Laszlo AII III To: PICLIST@MITVMA.MIT.EDU Date: Wednesday, December 27, 2000 7:06 AM Subject: [PIC]:pulse meter >Hi! > >I am working on a pulse meter >I want to use a 16f84 or 16f627-628 >Supouse that the normal pulse is beetwen min.0 and max.240 >So in that case i have a frequency beetwen 0-4 pulse/sec. >How can i measure the time beetwen 2 pulses using the rb0/int interrupt >and 4MHz clock. >I need to have a number beetwen 0-240 after to interrupts > >Have anyone some ideas? > >regards > Kajcsa Laszlo >and happy new year > >-- >http://www.piclist.com hint: To leave the PICList >mailto:piclist-unsubscribe-request@mitvma.mit.edu > > > -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu