Hello,
I have some code which was derived from another member some time ago, which I am looking at again and wanting to improve.
I have a PCB with a 328P on it, which is dedicated to counting the time between two consecutive pulses and estimating the number of pulses there would be in a second. The answer is then requested from another uC every 300ms or so, transmitted over I2C.
The code I have uses Timer0 with a prescaler of 64.
From what I understand of it, each pulse that comes in, it takes a record of Timer0 in the ISR, and then compares the time to the next pulse that comes in. It then does a calculation and determines how many pulses there would be in a second.
I am wanting this code to count as fast and as accurately as possible, and I need some assistance in doing that.
Should I change this over to use Timer1 instead of Timer0, to get a higher resolution, and change the Prescaler over to /8 instead of /64 too?
Do you think this will help? I was thinking about putting on a 20Mhz crystal instead of the 16Mhz one, to help things along too.
The code handles 2 inputs, attached to INT0 and INT1.
If you can please assist with improvements to the counting code (not the I2C stuff), I would appreciate it. The I2C stuff is still being worked on.
Attached to a function generator, I can read up to 43kHZ or there abouts, however the resolution up there is extremely poor, it is +/-1000Hz territory. When under 1000Hz, the accuracy is rather good, and is generally within 1Hz.
Help would be appreciated.
Code next post (this one is getting too long)
Regards
James