Fast PWM using atmega2560 .

#define F_CPU 16000000
#include <avr/io.h>
#include <util/delay.h>
#define PIN_OCOB PG5

void initPWM();

int main(void)
{
	
     initPWM();	
		
    while (1) 
    {
	//set the duty cycle
	OCR0B = 128;//50% duty cycle
		
	_delay_ms(10);
    }
}

void initPWM()
{
	
	//        FAST PWM                | CLEAR OCOA ON COMPARE
	TCCR0A |= (1<<WGM01) | (1<<WGM00) | (1<<COM0B1) | (0<<COM0B0);
	
	//CS = NO PRESCALE  
	TCCR0B |= (1<<CS00) ;
	
	//Enable OCOA PWM pin	
	DDRG |= 1<<PIN_OCOB;
	
}

Running a stepper motor with arduino on RAMPS with drv8825 driver

#include <Stepper.h>

int enablePin = 24;
int dirPin = 28;
int stepPin = 26;

void setup() {
  pinMode(enablePin, OUTPUT);
  digitalWrite(enablePin, LOW);
  pinMode(dirPin, OUTPUT);
  pinMode(stepPin, OUTPUT);
}

void step(boolean dir, int steps)
{
  digitalWrite(dirPin, dir);
  delay(50);

  for( int i=0;i<steps;i++)
  {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(800);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(800);

  }
}

void loop() {
  step(true, 1000);
  delay(50);
  step(false, 1000);
  delay(50);
}