TimerOne library does not function

keithg

Well-known member
I am running a modified version of this code on a mega.

AC_Dimmer

I want to run it on a teensy 3.0. I finally figured out how to get the interrupt pin to work, now I want to attach a timer to it and have previously used the TimerOne library. I also tried both examples which come with the TimerOne library and they both fail with the same error listing. Can anyone help me to get this working without the library or will this library interaction be fixed shortly (beta 8)? There are a number of reasons I want to use the teensy 3.0 on this project and an arduino or even a teensy 2.0 is not adequate.

my line 24 is the include of the TimerOne library...

When I try to compile it, it pukes with this error:
Code:
In file included from dimmer_v9.ino:24:
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h: In member function 'void TimerOne::initialize(long unsigned int)':
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:42: error: 'TCCR1B' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:42: error: 'WGM13' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:43: error: 'TCCR1A' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h: In member function 'void TimerOne::setPeriod(long unsigned int)':
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:49: error: 'CS10' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:53: error: 'CS11' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:57: error: 'CS11' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:57: error: 'CS10' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:61: error: 'CS12' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:65: error: 'CS12' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:65: error: 'CS10' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:68: error: 'CS12' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:68: error: 'CS10' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:71: error: 'ICR1' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:72: error: 'TCCR1B' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:72: error: 'WGM13' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h: In member function 'void TimerOne::start()':
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:79: error: 'TCCR1B' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:80: error: 'TCNT1' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:81: error: 'WGM13' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h: In member function 'void TimerOne::stop()':
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:84: error: 'TCCR1B' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:84: error: 'WGM13' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h: In member function 'void TimerOne::restart()':
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:87: error: 'TCCR1B' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:88: error: 'TCNT1' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:89: error: 'WGM13' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h: In member function 'void TimerOne::resume()':
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:92: error: 'TCCR1B' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:92: error: 'WGM13' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h: In member function 'void TimerOne::setPwmDuty(char, unsigned int)':
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:102: error: 'TIMER1_A_PIN' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:102: error: 'OCR1A' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h: In member function 'void TimerOne::pwm(char, unsigned int)':
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:111: error: 'TIMER1_A_PIN' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:111: error: 'TCCR1A' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:111: error: 'COM1A1' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:119: error: 'TCCR1B' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:119: error: 'WGM13' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h: In member function 'void TimerOne::disablePwm(char)':
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:126: error: 'TIMER1_A_PIN' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:126: error: 'TCCR1A' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:126: error: 'COM1A1' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h: In member function 'void TimerOne::attachInterrupt(void (*)())':
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:140: error: 'TIMSK1' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:140: error: 'TOIE1' was not declared in this scope
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h: In member function 'void TimerOne::detachInterrupt()':
C:\Users\kgrider\Documents\Arduino\arduino-1.0.2_b7\libraries\TimerOne/TimerOne.h:147: error: 'TIMSK1' was not declared in this scope
 
TCCR1B and the others aren't declared because the TimerOne library you're using hasn't been ported to Teensy3 yet.
I was going to post an example of code that runs a timer in Teensy3 but discovered that it doesn't run in beta8. So, I'm holding off until the beta8 problem is resolved.
[edit] Found it.
I posted some code in http://forum.pjrc.com/threads/489-T3-beta-8-regression which blinks an LED using a Teensy3 timer interrupt. For beta7 or beta8 it requires a fix described in my second post in http://forum.pjrc.com/threads/14-Teensy-3-0-and-interrupts. Perhaps it will give you a start.

Pete
 
Last edited:
Ok, I have some time to work on this and am trying to make sure I understand what all the code does/means...

I want to trigger a timer based on an interrupt pin (pin 16 for example) and want it to run at 60hz and want to borrow your code if I can. I am chopping the A/C waveform and am using the ZC detector on pin 16. When it sees a rising edge, I want to start a timer and divide the time into 255 slices.

I am pretty lost here, but I have a trigger on pin 16 and want to start a timer from the rising edge. I want that :

can anyone help me get this arduino sketch ported over to Teensy 3?

These are the lines of the code I am trying to get replaced in teensy 3 so it will compile.

Code:
// for timer function 
int freqStep = 65;    // Set the delay for the frequency of power (65 for 60Hz, 78 for 50Hz) per step (using 128 steps)
// freqStep may need some adjustment depending on your power formula 
// is (500000/AC_freq)/NumSteps = freqStep

attachInterrupt(interrupt_pin, zero_cross_detect, RISING);   // Attach an Interupt to Pin 21 (interupt 2) for Zero Cross Detection
  Timer1.initialize(freqStep);                                 // Initialize TimerOne library for the freq we need
  Timer1.attachInterrupt(AC_out_check, freqStep);      
  // Use the TimerOne Library to attach an interrupt to the function we use to check to see if it is 
  // the right time to fire the triac.  This function will now run every freqStep in microseconds.

TIA,

Keith
 
Back
Top