Robert Lunn wrote: > > >I need to measure a continuous frequency between 0 - 250 cycles/MINUTE, > >and transmit it via RS-232 at 2400 baud in a message containing 6 bytes > >once 5 seconds. > > > >The PIC I plan to use is the low power 84 variant, running at 32 KHz, > >if possible. > > Peter, you don't indicate the accuracy with which you need > to measure the frequency... > > However, with a 32.768 kHz clock (which is 8192 instructions > per second) a variation of one instruction in detecting the > edge of a 250 rpm signal will cause an error in the calculated > instantaneous frequency of 0.2 rpm. +/- 0.5 rpm is fine. > > Assuming you don't want your measurement to be much less > accurate than this, you must measure the edges of the input > signal to within an instruction time. > > You can do this by setting up TMR0 as a free running timer > with no prescale, configuring RB0 as an interrupt, and > connecting your input signal to RB0. > > On each rising edge you get an interrupt, and in your ISR > you capture TMR0. > > You must handle overflow of TMR0 in your main line code. > > You are now measuring your signal period, and thus your > signal frequency, as accurately as it is possible. Seems a good solution so far. > > Ok, now to the output side of the equation... > > I can solve your problem if I can change your requirements :-) > > Use 300 baud instead of 2400 baud (which is barely possible > anyway). 300 baud may be a bit slow, Ill have to check. 1200baud is preferred. I want to use a 32KHz crystal because of its availability. Maybe I'll have to use a faster one, so as to increase the baud rate. The reason for the slow crystal is purely for power consumption reasons. > > At 300 baud you have just over 27 instructions per bit. The > ISR to capture TMR0 should be six instructions. This interrupt > can never occur more than once per character (indeed, can never > occur more than once per six byte transmission). Stretching > a single bit time by 20% will _probably_ be ok... > > Don't forget to handle TMR0 overflow between each byte. > > ___Bob Thanks again, Peter. -- _______________________________________________________________________ Peter Homann email: peterh@adacel.com.au Work : +61 3 9596-2991 Adacel Pty Ltd Fax : +61 3 9596-2960 250 Bay St, Brighton 3186, VIC, AUSTRALIA Mobile : 014 025-925