Thanks Michael. The code looks pretty straight forward. Thanks for the sample. I'll let the list know how I made out. John -----Original Message----- From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu]On Behalf Of michael brown Sent: Sunday, January 23, 2005 9:42 AM To: Microcontroller discussion list - Public. Subject: Re: [PIC] TMR0 counter and RB0/INT help. ----- Original Message ----- From: "John Mullan" To: Sent: Saturday, January 22, 2005 5:49 PM Subject: [PIC] TMR0 counter and RB0/INT help. > I was hoping someone on the list could supply my with (or point me to) some > simple example code for using the TMR0 as counter. > > I would like to measure time between interupts on RB0/INT pin. I would be > measuring the mains frequency through bridge rectifier (ie; should average > 120 interupts per second). However, I would want to have a range from 0 > (missing) to say 75hz (150 interupts). I presume I will need the example to > include the prescaler for this. You don't necessarily need the prescaler, you can count the roll-overs of TMR0 and acheive 1uS precision. If you'd like to keep it all in 8 bits, then the prescaler will be needed. The period between peaks in your signal is about 8.3333R mS (8 1/3 to be precise ;-) for 60Hz AC that has been fully rectified. You didn't specify a minimum value on the number of ints, so it's hard to nail down the exact prescaler value you need. A prescaler of 256 will let you measure up to 65.535 mS before a TMR0 rollover occurs using a 4MHz crystal. However that will only give you resolution to about .25mS. > I learn best by example. I have done several PIC projects, but nothing > really to do with interupts. I attached an example. It is UNTESTED, but is cut and pasted from working code. It should at least give you an idea of how to do what you wish. -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist