If this is for the TMP-03 sensor you may wish to consider a routine Dwayne Reid wrote. IIRC, it uses an interlaced co-routine type trick to poll a pulse and achieve 3 tcyc resolution in the measurement and have 16-bit dynamic range. I presume you can obtain similar results with TMR0 by setting the prescaler to 0 (i.e. give the WDT the prescaler), polling TMR0 rollovers, and polling the pulse. However, since there are two things that have to be polled you'd only be limited to 4 or 5 Tcyc resolution (that is if you're lucky or clever - which ever comes first) .lo --- Nikolai Golovchenko wrote: > -----Original Message----- > From: John De Villiers > To: PICLIST@MITVMA.MIT.EDU > Date: Tuesday, November 02, 1999 7:31 PM > Subject: Re: 0-100 duty cycle at 15 Hz to a 0-5v > analog > > >I would really like to see how you did this. > > > >Wanna share ?? > > > >> Why simply not use interrupts on edges of the PWM > signal and read timer > >> value at these moments? It takes only about 20 > instructions to > >> convert timer > >> samples to the pulse width. With constant PWM > frequency you can > >> use look-up > >> table to convert pulse width to analog value. > > > > > > Why not. Don't know if it will be useful to you, > because the routine is very > specific. > > Here is the setup: > TMP03 connected to RB0. > TMR0 programmed to run from internal clock (4 Mhz > crystal) with 1:8 > prescaler. The timer is free running, without > corrections to TMR0 register. > > This snippet measures time of pulse in high state > TMP_T1L, TMP_T1H and time > of pulse in low state TMP_T2L, TMP_T2H. The main > program uses these values > to compute temperature. To read the values the main > program polls ready flag > TMP_READY. > On timer overflow there is a correction to high > byte. Because timer overflow > handler does some other stuff I use nested > interrupts (BSF INTCON, GIE). > This is unnecessary if you move the timer overflow > handler in the main > program. > > Note that the routine is designed for TMP03 sensor, > which never has 0% or > 100% duty cycle. > > Is this what you wanted? > Bye > ----------------------------------------------------------- > > INTERRUPT ROUTINE > ~~~~~~~~~~~~~~~~~~ > ...... > BTFSS INTCON, INTF ;check for rb0 edge > GOTO STATEID2 > > ;**** temperature measure > MOVF TMR0, W > ;if after rb0 front the timer overflowed then > ;use value 255 as the most near value to the truth > BTFSC INTCON, T0IF > MOVLW 255 > > BTFSC TMP_READY > GOTO ID1C > BTFSC TMP_STARTWAITING > GOTO ID1A > > ;correct tmp_t2 if it's the end of high or low > period > PUSHW > ADDWF TMP_T2L, F > BTFSC _C > INCF TMP_T2H, F > BTFSC PORTB, 0 > GOTO ID1B > > ;copy tmp_t2 to tmp_t1 if it's the end of high > period > MOVF TMP_T2L, W > MOVWF TMP_T1L > MOVF TMP_T2H, W > MOVWF TMP_T1H > POPW2 > > ;Initialize tmp_t2 and clear waiting flag > ID1A BCF TMP_STARTWAITING > CLRF TMP_T2H > SUBLW 0 ;TMP_T2 = - TMR0 > MOVWF TMP_T2L > BTFSS _C > DECF TMP_T2H, F > > ;Prepare edge selector flag > BTFSS PORTB, 0 > GOTO ID1D > BANK1 > BCF OPTION_REG, INTEDG > GOTO ID1C > > ;Set ready flag and waiting flag > ID1B DECF FSR, F > BSF TMP_READY > BSF TMP_STARTWAITING > ID1D BANK1 > BSF OPTION_REG, INTEDG > ID1C BCF INTCON, INTF > GOTO INT_END > ;temperature measure **** > > > STATEID2: > BTFSS INTCON, T0IF > GOTO INT_END > > ;***** tmr0 overflow > BCF INTCON, T0IF > BTFSS TMP_READY ;Duty cycle timer modification > INCF TMP_T2H, F > ;global enable > BSF INTCON, GIE > ..... > ===== __________________________________________________ Do You Yahoo!? Bid and sell for free at http://auctions.yahoo.com