6 years, 5 months ago.

Frequency of 2 MHz

Hi. In my program I need a frequency of 2 MHz (a square wave with duty cycle at 50%), it should just run frequency in a short time, maybe one second. Also the code must listen to a voltage coming from a sensor.

Can someone help me with at least the frequency of 2MHz?

(I use nRF51822 mbed KIT if it has something to say)

1 Answer

6 years, 5 months ago.

You will need a PWM output to generate the 2MHz (at least I assume you want it externally available). However by default highest frequency mbed can go is 2MHz. The FastPWM lib for higher frequencies is not available for the NRF until someone ports it or sends me one :P.

But how? I get below 9 kHz with the program I have now.

  1. include "mbed.h"

PwmOut pwm(p22);

int main() { pwm.period(0.0000005);

while(1) { pwm = 0.5; } }

posted by Kri B 17 Apr 2015