Depends on the frequency and on the rate of frequency change that you try to achieve. The frequency of the PWM can be changed easily, keep the duty factor at 50% and there you go.
You may also be able to use the SPI or the I2S clock outputs. You just need to keep them going by using interrupts or DMA. The actual data output is ignored.
For low frequencies you could also use the Ticker and toggle a DigitalOut pin. Better performance will probably require low-level timer manipulation.
An analog outputsignal could be generated through the DAC and a DMA feed that sends data from a sinewave table or something like that. PFM is achieved when you vary the DMA transferrate.
Depends on the frequency and on the rate of frequency change that you try to achieve. The frequency of the PWM can be changed easily, keep the duty factor at 50% and there you go.
You may also be able to use the SPI or the I2S clock outputs. You just need to keep them going by using interrupts or DMA. The actual data output is ignored.
For low frequencies you could also use the Ticker and toggle a DigitalOut pin. Better performance will probably require low-level timer manipulation.
An analog outputsignal could be generated through the DAC and a DMA feed that sends data from a sinewave table or something like that. PFM is achieved when you vary the DMA transferrate.
"depends on the frequency and on the rate of frequency change that you try to achieve. The frequency of the PWM can be changed easily, keep the duty factor at 50% and there you go. "
Are you suggesting that all i need to do is keep the duty cycle constant to generate a PFM?
"depends on the frequency and on the rate of frequency change that you try to achieve. The frequency of the PWM can be changed easily, keep the duty factor at 50% and there you go. "
Are you suggesting that all i need to do is keep the duty cycle constant to generate a PFM?
Generating a squarewave output that varies between 2 or more frequencies can be done with the PWM outputs.
Just define a Pin as PwmOut, set the duty cycle to 50%, set the frequency to its desired value. Code below will toggle the freq every 2 seconds between 1000Hz and 500Hz.
#include "mbed.h"
PwmOut PwmPin (p21);
DigitalOut myled1(LED1);
DigitalOut myled2(LED2);
int main() {
PwmPin.period(0.001); // Set frequency to 1000 Hz (period = 1 ms)
PwmPin.write(0.5); // Set the duty cycle to 50%
myled1 = 1; // Show what is going on
myled2 = 0;
while(1) {
PwmPin.period (0.001); // Set frequency to 1000 Hz (period = 1 ms)
// Dutycycle remains 50%
myled1 = 1; // Show what is going on
myled2 = 0;
wait(2); // wait 2 sec
PwmPin.period (0.002); // Set frequency to 500 Hz (period = 2 ms)
// Dutycycle remains 50%
myled1 = 0; // Show what is going on
myled2 = 1;
wait(2); // wait 2 sec
}
}
Generating a squarewave output that varies between 2 or more frequencies can be done with the PWM outputs.
Just define a Pin as PwmOut, set the duty cycle to 50%, set the frequency to its desired value. Code below will toggle the freq every 2 seconds between 1000Hz and 500Hz.
<<code>>
#include "mbed.h"
PwmOut PwmPin (p21);
DigitalOut myled1(LED1);
DigitalOut myled2(LED2);
int main() {
PwmPin.period(0.001); // Set frequency to 1000 Hz (period = 1 ms)
PwmPin.write(0.5); // Set the duty cycle to 50%
myled1 = 1; // Show what is going on
myled2 = 0;
while(1) {
PwmPin.period (0.001); // Set frequency to 1000 Hz (period = 1 ms)
// Dutycycle remains 50%
myled1 = 1; // Show what is going on
myled2 = 0;
wait(2); // wait 2 sec
PwmPin.period (0.002); // Set frequency to 500 Hz (period = 2 ms)
// Dutycycle remains 50%
myled1 = 0; // Show what is going on
myled2 = 1;
wait(2); // wait 2 sec
}
}
<</code>>
Checkout http://mbed.org/handbook/PwmOut
Important Information for this Arm website
This site uses cookies to store information on your computer.
By continuing to use our site, you consent to our cookies.
If you are not happy with the use of these cookies, please review our
Cookie Policy
to learn how they can be disabled.
By disabling cookies, some features of the site will not work.
Access Warning
You do not have the correct permissions to perform this operation.
Can the mbed implement a Pulse Frequency Modulation (PFM) sort of like the PWM? If so, is there an example out there?
Thanks, Scott