Modify freqMeasure library for higher frequencies

Status
Not open for further replies.

g92

New member
Hi,

I would like to modify the PJRC freqMeasure library to measure frequencies up to, or possibly slightly exceeding, 16 KHz. I would like to set count > 800. I am using an Atmega328p microcontroller on a custom board with a high stability 16 MHz clock. If someone could tell me if this is possible and provide me with suggestions on where to start or what needs to be changed, I would be very appreciative. I am aware that PJRC has another library that is more suitable for this frequency but I am interested in being able to set the number of edges that are counted instead of setting a fixed period. I am trying to control the frequency of a spinning object and would like to be able to detect that the frequency is changing and apply fixes as quickly as possible. I think the fixed number of edges approach will be better in this application.

Thank you,
Greg
 
Just use it as-is.

There are 2 limits. With a 16 MHz clock, you'll get 62.5 ns resolution, or about 10 bits resolution for a 16 kHz signal.

This will also generate 16000 interrupts per second, which is quite a lot for the slow 8 bit processor on Arduino Uno. You may run into problems when other interrupts like millis or Serial prevent the timer interrupt from running. On the 32 bit Teensy boards the interrupt controller supports priority nesting, so these high priority interrupts aren't blocked by serial communication and other lower priority interrupts. But on AVR, they are and there's really nothing you can do about it... other than a lot of work to not use other interrupts.
 
Hi Paul,

Thank you for the response. I have tried using it as-is and it generally works but I am seeing variation of 20 to 50 Hz between measurements which aren't real, as confirmed by a HP frequency counter connected in parallel. Since I'm using both I2C and UART to communicate with other parts of the system, it sounds like this variation is likely caused by interrupts from those serial protocols. I might be switching to a different microcontroller then.

Thank you again,
Greg
 
Status
Not open for further replies.
Back
Top