Go Down

Topic: Square or Sinewave (Read 2 times) previous topic - next topic

mem

#5
Sep 21, 2009, 11:23 am Last Edit: Sep 21, 2009, 11:24 am by mem Reason: 1
If you can manage with an upper bound of 1MHz then you can use the FrequencyTimer2 library to simplify access to the timer.

Usage:
[font=Courier New]#include <FrequencyTimer2.h>

 FrequencyTimer2::setPeriod(period); // period in microseconds
 FrequencyTimer2::enable();  // start pulsing on pin 11 (set this to output mode in setup)[/font]

You can find the library here: http://www.arduino.cc/playground/Code/FrequencyTimer2

cenlasoft


Hello,
I tried the code below and I get many errors coming from the "FrequencyTimer" library. Where do I put the downloaded library files? I changed my hardware to accept a square wave from 100 khz to 900 khz. Thanks, Curtis
// SqrWave
#include <FrequencyTimer2.h>

void setup() {
 pinMode(11,OUTPUT);
   
 FrequencyTimer2::setPeriod(10000);
 FrequencyTimer2::enable();
}

void loop()
{
}

mem

#7
Oct 07, 2009, 10:19 am Last Edit: Oct 07, 2009, 10:19 am by mem Reason: 1
If you are using arduino 0017 you can follow the information on the Arduino reference page:  

To install, unzip the library to a sub-directory of the libraries sub-directory of your Arduino sketchbook directory (shown in the Arduino preferences dialog). If this is the first library you've installed, you'll need to create the libraries directory. After unzipping the library, (re-)launch the Arduino environment; you should see the library in the Import Library menu.

If you are still getting errors after copying the library into the correct place, please say what Arduino version you are running, your operating system and post the first few lines of the error message.

cenlasoft

Hello,
Thanks for the reply. Here are the errors:
This is one of the errors, they are all the same from different files in FrequencyTimer2:
C:\Documents and Settingings\Intern10\Desktop\Arduino-0017\Hardware\Libraries\FrequencyTimer2\FrequencyTimer2.cpp: In 'Static Member Function Void FrequencyTimer2::SetOnOverFlow(Void(*)())':

There was also the same type of error in that file and the other 'TIMSK' was not declared in this scope.

I am using Windows XP and Arduino 0017.
Thanks,
Curtis

mem

If you are using a standard Arduino bard then check to make sure you have the latest version, you should see this code at the beginning of the FrequencyTimer2.cpp file:
Code: [Select]
#if defined(__AVR_ATmega328P__)
// A mega328 is mostly like an mega168, in terms of peripherals
#define __AVR_ATmega168__
#endif

Download the latest version if yours does not have that code at the beginning.

If you are running the latest code, can you say what board are you using?

Go Up