user31301: I am currently implementing the following setup:
Arduino Mega 2650 -- DRV8834 -- Stepper motor
Everything works fine, however since it can provide a higher torque I want to run the stepper in half step mode. Each step is triggered by a single pulse coming from the Arduino to the driver. If one uses the Digital Pins for this purpose as done by AccelStepper, the maximum frequency is around 1000 pps (points per second). This is a third of what I want to achieve. The second option would be to use the PWM of the Arduino which naturally runs at 16 MHz (way to high). There is a way to downgrade this frequency, however the steps are only discrete and not accurate enough for a nice speed control.
Therefore I want to do the following
Arduino Mega 2650 -- Controller -- DRV8834 -- Stepper motor
whereby the Controller is creating a PWM with a frequency (100 to 3000 Hz) depending on some signal coming from the Arduino (I2C, voltage level or something else). I was now searching two days for a component and have no clue what I could use. 
How can I create a PWM from 100 to 3000Hz with an arduino?

Edit 1: I have to read out sensors while the motor is running. Therefore, the so called "bit banging" PWM 
void loop(){
digitalWrite(pinSTEP, HIGH);
delayMicroseconds(T/2); 
digitalWrite(pinSTEP, LOW);
delayMicroseconds(T/2);
}

where T = 1 / f is not feasible since I have to read out a sensor in the loop which destroys the motor timing.

Edit 2: There is a method to change the register of the timers. One can adapt a so called prescalar values (from 0 to 7) which will define the frequency of our PWM. However with only seven discrete steps this leads to the following freuquencies:
prescalar = 1 ---> PWM frequency is 31000 Hz
prescalar = 2 ---> PWM frequency is 4000 Hz
prescalar = 3 ---> PWM frequency is 490 Hz (default value)
prescalar = 4 ---> PWM frequency is 120 Hz
prescalar = 5 ---> PWM frequency is 30 Hz
prescalar = 6 ---> PWM frequency is <20 Hz

which is not sufficient for my application.
For more about this method:

http://usethearduino.blogspot.ch/2008/11/changing-pwm-frequency-on-arduino.html
http://forum.arduino.cc/index.php?topic=72092.0


Sometimes a solution is so easy that it hurts ;) Based on the input of this wonderful community I found my solution. Code:
#include <TimerThree.h>
// TimerThree PWM Pins 2, 3, 5

#define pinPWM       2
#define pinM0        22
#define pinM1        24
#define pinSleepnot  28
#define pinDir       30

void setup(void){

  // Define output pins
  pinMode(pinM0, OUTPUT);
  digitalWrite(pinM0, HIGH);
  pinMode(pinM1, OUTPUT);
  digitalWrite(pinM1, LOW);
  pinMode(pinSleepnot, OUTPUT);
  digitalWrite(pinSleepnot, HIGH);
  pinMode(pinDir, OUTPUT);

  // Initialize serial communication
  Serial.begin(9600);

}

void loop(void){

  for (float frequency = 500; frequency < 3000; frequency = frequency + 1) {
    float T = 1 / frequency * 1000000;
    Serial.print("Frequency: ");
    Serial.println(frequency);
    Timer3.initialize(T);
    Timer3.pwm(pinPWM, 100);
    delay(5);
  }
}


user-1: You might need to move away from the AccelStepper library, and 'roll your own', but as others have pointed out, the MCU certainly has the bandwidth to do this directly.  I understand that PWM resolution may not give smooth ramping, but I would probably look into using a timer interrupt.  The timer ISR would count steps and you would only need to adjust the timer compare register to change the step frequency.

31301: <p>I am currently implementing the following setup:</p>

<p>Arduino Mega 2650 -- <a href="https://www.pololu.com/product/2134" rel="nofollow noreferrer">DRV8834</a> -- Stepper motor</p>

<p>Everything works fine, however since it can provide a higher torque I want to run the stepper in half step mode. Each step is triggered by a single pulse coming from the Arduino to the driver. If one uses the Digital Pins for this purpose as done by <a href="http://www.airspayce.com/mikem/arduino/AccelStepper/" rel="nofollow noreferrer">AccelStepper</a>, the maximum frequency is around 1000 pps (points per second). This is a third of what I want to achieve. The second option would be to use the PWM of the Arduino which naturally runs at 16 MHz (way to high). There is a way to downgrade this frequency, however the steps are only <a href="https://www.arduino.cc/en/Tutorial/SecretsOfArduinoPWM" rel="nofollow noreferrer">discrete</a> and not accurate enough for a nice speed control.</p>

<p>Therefore I want to do the following</p>

<p>Arduino Mega 2650 -- Controller -- DRV8834 -- Stepper motor</p>

<p>whereby the Controller is creating a PWM with a frequency (100 to 3000 Hz) depending on some signal coming from the Arduino (I2C, voltage level or something else). I was now searching two days for a component and have no clue what I could use. </p>

<p>How can I create a PWM from 100 to 3000Hz with an arduino?</p>

<hr>

<p>Edit 1: I have to read out sensors while the motor is running. Therefore, the so called "bit banging" PWM </p>

<pre><code>void loop(){
digitalWrite(pinSTEP, HIGH);
delayMicroseconds(T/2); 
digitalWrite(pinSTEP, LOW);
delayMicroseconds(T/2);
}
</code></pre>

<p>where T = 1 / f is not feasible since I have to read out a sensor in the loop which destroys the motor timing.</p>

<hr>

<p>Edit 2: There is a method to change the register of the timers. One can adapt a so called prescalar values (from 0 to 7) which will define the frequency of our PWM. However with only seven discrete steps this leads to the following freuquencies:</p>

<pre><code>prescalar = 1 ---&gt; PWM frequency is 31000 Hz
prescalar = 2 ---&gt; PWM frequency is 4000 Hz
prescalar = 3 ---&gt; PWM frequency is 490 Hz (default value)
prescalar = 4 ---&gt; PWM frequency is 120 Hz
prescalar = 5 ---&gt; PWM frequency is 30 Hz
prescalar = 6 ---&gt; PWM frequency is &lt;20 Hz
</code></pre>

<p>which is not sufficient for my application.</p>

<p>For more about this method:</p>

<ul>
<li><a href="http://usethearduino.blogspot.ch/2008/11/changing-pwm-frequency-on-arduino.html" rel="nofollow noreferrer">http://usethearduino.blogspot.ch/2008/11/changing-pwm-frequency-on-arduino.html</a></li>
<li><a href="http://forum.arduino.cc/index.php?topic=72092.0" rel="nofollow noreferrer">http://forum.arduino.cc/index.php?topic=72092.0</a></li>
</ul>

<hr>

<p>Sometimes a solution is so easy that it hurts ;) Based on the input of this wonderful community I found my solution. Code:</p>

<pre><code>#include &lt;TimerThree.h&gt;
// TimerThree PWM Pins 2, 3, 5

#define pinPWM       2
#define pinM0        22
#define pinM1        24
#define pinSleepnot  28
#define pinDir       30

void setup(void){

  // Define output pins
  pinMode(pinM0, OUTPUT);
  digitalWrite(pinM0, HIGH);
  pinMode(pinM1, OUTPUT);
  digitalWrite(pinM1, LOW);
  pinMode(pinSleepnot, OUTPUT);
  digitalWrite(pinSleepnot, HIGH);
  pinMode(pinDir, OUTPUT);

  // Initialize serial communication
  Serial.begin(9600);

}

void loop(void){

  for (float frequency = 500; frequency &lt; 3000; frequency = frequency + 1) {
    float T = 1 / frequency * 1000000;
    Serial.print("Frequency: ");
    Serial.println(frequency);
    Timer3.initialize(T);
    Timer3.pwm(pinPWM, 100);
    delay(5);
  }
}
</code></pre>
 -1: <p>You might need to move away from the AccelStepper library, and 'roll your own', but as others have pointed out, the MCU certainly has the bandwidth to do this directly.  I understand that PWM resolution may not give smooth ramping, but I would probably look into using a timer interrupt.  The timer ISR would count steps and you would only need to adjust the timer compare register to change the step frequency.</p>
