View Full Version : Help with an Arduino Library

02-17-2013, 08:02 PM
Hi Everyone,

Well I am new to both the arduino and the teensy, so bear with me. I am working on a project that has been using an arduino and I have been using this library to measure 3 things, frequency 440hz to 3000hz, time period (0.01 to 0.02 seconds), and a second time period (.5 to 1 second). Link to library is http://www.avdweb.nl/arduino/hardware-interfacing/frequency-period-counter.html. It is working with the arduino, however I would like to use a teensy due to faster usb write speed, can use 3 interrupts, and it is smaller. I am just wondering why this library will not work with the Teensy 3. I am not sure if it is a simple fix to make it work, or if it is really hard. Like I said I am new to all of this and trying to learn it the best I can. Any help would be great. For reference I have just tried to use the basic example on that website and it does not spit out any serial data. Thanks in advance.

02-17-2013, 09:34 PM
Since the sample code compiles fine for T3, there is really nothing we can help with unless you post your code and explain what your problem is. I do believe the interrupts are numbered after the pins eg int1 = pin1

02-17-2013, 10:13 PM
I have tried to change the interrupts to match, I assume when I use pin 3, it is equal to interrupt 3. Here is the code.

#include <FreqPeriodCounter.h>

const byte counterPin = 3;
const byte counterInterrupt = 3; // = pin 3
FreqPeriodCounter counter(counterPin, micros, 0);

void setup(void)
{ Serial.begin(9600);
attachInterrupt(counterInterrupt, counterISR, CHANGE);

void loop(void)
{ if(counter.ready()) Serial.println(counter.hertz());

void counterISR()
{ counter.poll();

The issue is that nothing happens. From looking at the cpp and header file, it waits for a boolean to be true, which says it is ready to spit out a value, at least this is what I assume it means. So it will compile and I can upload it, however it will never go ready, therefore nothing gets printed out. The code does not seem that advance, that is why I thought it would just work for the teensy 3 without changes. Thanks for your reply.
I also just noticed that in the header file it has #include arduino.h....would this be different for the teensy 3?

02-18-2013, 04:55 AM
What do you have connected to the input pin? "poll" a is only called if there is a change to the pin value and ready is only called if poll is getting a value. If you feel confident pull should return a value, try to put counter.poll() into the main loop to isolate if the problem is related to the interrupt, the poll or the actual input value.

02-18-2013, 05:07 AM
I have a function generator connected spitting out a pulse at 1000hz at 3V. Exact same as I have on the arduino uno and it is working. I will try another input tomorrow just to see if it is that. Since it compiles it should run. All new to me, so learning as I go. Thanks for the help.

02-18-2013, 03:56 PM
I figured it out, I was forgetting to set the pinMode to input. I knew it was some stupid oversight on my part.