PWM frequency library

Thank you for the library.

I used your example to try to use Scope to test the signal coming out and this is what i got

it has a few spikes and the amplitude changes greatly. What would I need to do to...:

  1. Control the speed using a program on my computer?
    2)Fix the PWM signal to be a constant 89hz with a controlled duty cycle that I can control by clicking on buttons or something of the like?

the code I used is:

/*

Mimics the fade example but with an extra parameter for frequency. It should dim but with a flicker
because the frequency has been set low enough for the human eye to detect. This flicker is easiest to see when
the LED is moving with respect to the eye and when it is between about 20% - 60% brighness. The library
allows for a frequency range from 1Hz - 2MHz on 16 bit timers and 31Hz - 2 MHz on 8 bit timers. When
SetPinFrequency()/SetPinFrequencySafe() is called, a bool is returned which can be tested to verify the
frequency was actually changed.

This example runs on mega and uno.
*/

#include <PWM.h>

//use pin 11 on the Mega instead, otherwise there is a frequency cap at 31 Hz
int led = 9; // the pin that the LED is attached to
int brightness = 0; // how bright the LED is
int speedcontrol = 5; // how many points to fade the LED by
int32_t frequency = 89; //frequency (in Hz)

void setup()
{
//initialize all timers except for 0, to save time keeping functions
InitTimersSafe();

//sets the frequency for the specified pin
bool success = SetPinFrequencySafe(led, frequency);

//if the pin frequency was set successfully, turn pin 13 on
if(success) {
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
}
}

void loop()
{
//use this functions instead of analogWrite on 'initialized' pins
pwmWrite(led, brightness);

brightness = brightness + speedcontrol;

if (brightness == 0 || brightness == 255) {
speedcontrol = -speedcontrol ;
}

delay(30);
}

While I know its not right code, I wanted to test to see if it was getting a solid 89hz, which it was getting 89, but not solid (as in it spiked to above 200hz) possibly because of the programming not being right?