Creates square-wave frequency output on pin p22. Custom frequency between 1Hz and 48 MHz. (LPC 1768)

Dependencies:   FastPWM

Creates square-wave frequency output on pin22 with custom frequency.

Tested for frequencies from 1Hz to 48MHz. The accuracy depends heavily on the frequency - at 12, 24, 48 MHz the frequency deviation is less than 1%, but at 20 MHz it is about 20%.

Uses Library FastPWM ( http://mbed.org/users/Sissors/code/FastPWM/ ). For LPC 1768.

How to use this Library:

#include "mbed.h"
#include "PwmOscillator.h"

PwmOscillator oscillator;
DigitalOut led1(LED1);

int main() 
{
    oscillator.initWithFrequency(8000000);     // initialize oscillator instance (pin p22) with custom frequency, here: 8MHz
    led1=1;                                    // optional: indicator LED shows that oscillator is running
    oscillator.start();                        // start oscillator
    wait(5);                                   // optional: oscillator is running 5 seconds
    oscillator.stop();                         // stop oscillator
    led1=0;
}
Committer:
geotec
Date:
Fri Dec 14 14:39:48 2012 +0000
Revision:
1:4bbb380a1089
Parent:
0:9e0f295a55a4
Child:
2:d9fea7c1fc8d
Improved documentation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
geotec 0:9e0f295a55a4 1 #include "mbed.h"
geotec 0:9e0f295a55a4 2
geotec 1:4bbb380a1089 3 /** Creates square-wave frequency output on pin22 with custom frequency. Tested for frequencies from 1Hz to 48MHz.
geotec 1:4bbb380a1089 4 * The accuracy depends heavily on the frequency - at 12, 24, 48 MHz the frequency deviation is less than 1%, but at 20 MHz it is about 20%.
geotec 0:9e0f295a55a4 5 * Uses Library FastPWM ( http://mbed.org/users/Sissors/code/FastPWM/ ). */
geotec 0:9e0f295a55a4 6 class PwmOscillator
geotec 0:9e0f295a55a4 7 {
geotec 0:9e0f295a55a4 8
geotec 0:9e0f295a55a4 9 public:
geotec 0:9e0f295a55a4 10
geotec 0:9e0f295a55a4 11 /** Initialize PwmOscillator instance with frequency [Hz].
geotec 0:9e0f295a55a4 12 * @param frequencyHz = frequency in Hz (1 ... 48000000) */
geotec 0:9e0f295a55a4 13 void initWithFrequency(int frequencyHz);
geotec 0:9e0f295a55a4 14
geotec 0:9e0f295a55a4 15 /** Start oscillator
geotec 0:9e0f295a55a4 16 */
geotec 0:9e0f295a55a4 17 void start();
geotec 0:9e0f295a55a4 18
geotec 0:9e0f295a55a4 19 /** Stop oscillator
geotec 0:9e0f295a55a4 20 */
geotec 0:9e0f295a55a4 21 void stop();
geotec 0:9e0f295a55a4 22 };