Go Down

Topic: FreqCounter on Arduino Due? (Read 432 times) previous topic - next topic

deian

Hi all,

I am just at the final stage of my final year project and cannot for the life of me get the FreqCounter library to compile for me for the Arduino Due.

I can only assume the pins that go to the chips from the pins of the Due are different. But it doesn't even want to compile.

What I have done so far is to remove the bad encoding from the .cpp and .h file. It tries to compile better now but it complains about the following...

Code: [Select]
/tmp/buildf2fd1cc70aba7b12574f44d6ebaaa7a4.tmp/sketch/FreqCounter/FreqCounter.cpp:8:6: warning: unused parameter 'ms' [-Wunused-parameter]
 void FreqCounter::start(int ms)
      ^
/tmp/buildf2fd1cc70aba7b12574f44d6ebaaa7a4.tmp/sketch/FreqCounter/FreqCounter.cpp: In function 'void TIMER2_COMPA_vect()':
/tmp/buildf2fd1cc70aba7b12574f44d6ebaaa7a4.tmp/sketch/FreqCounter/FreqCounter.cpp:60:5: error: 'TCCR1B' was not declared in this scope
     TCCR1B = TCCR1B & ~7;      // Gate Off  / Counter T1 stopped
     ^
/tmp/buildf2fd1cc70aba7b12574f44d6ebaaa7a4.tmp/sketch/FreqCounter/FreqCounter.cpp:61:5: error: 'TIMSK2' was not declared in this scope
     TIMSK2 &= ~(1<<OCIE2A);       // disable Timer2 Interrupt
     ^
/tmp/buildf2fd1cc70aba7b12574f44d6ebaaa7a4.tmp/sketch/FreqCounter/FreqCounter.cpp:61:20: error: 'OCIE2A' was not declared in this scope
     TIMSK2 &= ~(1<<OCIE2A);       // disable Timer2 Interrupt
                    ^
/tmp/buildf2fd1cc70aba7b12574f44d6ebaaa7a4.tmp/sketch/FreqCounter/FreqCounter.cpp:62:5: error: 'TIMSK0' was not declared in this scope
     TIMSK0 |=(1<<TOIE0);        // enable Timer0 again // millis and delay
     ^
/tmp/buildf2fd1cc70aba7b12574f44d6ebaaa7a4.tmp/sketch/FreqCounter/FreqCounter.cpp:62:18: error: 'TOIE0' was not declared in this scope
     TIMSK0 |=(1<<TOIE0);        // enable Timer0 again // millis and delay
                  ^
/tmp/buildf2fd1cc70aba7b12574f44d6ebaaa7a4.tmp/sketch/FreqCounter/FreqCounter.cpp:66:28: error: 'TCNT1' was not declared in this scope
     FreqCounter::f_freq += TCNT1;       // add counter1 value
                            ^
/tmp/buildf2fd1cc70aba7b12574f44d6ebaaa7a4.tmp/sketch/FreqCounter/FreqCounter.cpp:71:9: error: 'TIFR1' was not declared in this scope
     if (TIFR1 & 1) {             // if Timer/Counter 1 overflow flag
         ^
/tmp/buildf2fd1cc70aba7b12574f44d6ebaaa7a4.tmp/sketch/FreqCounter/FreqCounter.cpp:73:16: error: 'TOV1' was not declared in this scope
     TIFR1 =(1<<TOV1);           // clear Timer/Counter 1 overflow flag


I can only assume these timers and counters are different on the cpu on Due and it won't compile because the code is targeted at the Uno? Or I'm missing something obvious. I haven't done any C code for ages, so please excuse my rustyness.

Some guidance would be much appreciated, thanks.

cattledog

Paul Stoffregen's FreqCount library is not written for the Due processor. You won't be able to modify it to make it work for the Due.

What Frequency pulses do you need to count? Can you count in an interrupt mode, or do you need to be in a timer/counter mode?

I would take your question to the Due section of the Forum.

deian

I have a square wave of about 120kHz that I need to measure with up to about +/-5Hz change, and I need 1Hz precision. It's for a traffic light project.

Thanks

cattledog

Quote
I have a square wave of about 120kHz that I need to measure with up to about +/-5Hz change, and I need 1Hz precision. It's for a traffic light project.
I would say that these are tough requirements. Accuracy of the time period will be important.

You may be able to do it with an interrupt rather than using the timer/counter and its worth a try. 

I don't know what else the program is doing, and what the interrupt latency is on the Due but it's likely you will have to delve into the data sheet to figure out the timer/counter management.

You could also consider using an external hardware counter IC.

deian

I can halve the wavelength to 60kHz or even 30kHz if need be.

cattledog

Quote
I can halve the wavelength to 60kHz or even 30kHz if need be.
Depending upon what the rest of the program is doing, I think counting at that frequency would be achievable with an interrupt rather than requiring the hardware timer/counter. Give it a try. You may want to use a timer to set the period of the interrupt count reading.

I'm not very knowledgeable about the Due, and I can probably only be of limited help when you get to the details.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy