10 years, 5 months ago.

How could I output 50MHz waveform by using FRDM-K64F?

How could I output 50MHz waveform by using FRDM-K64F? I use PwmOut.h library in mbed library, but period_us(int us) can only output waveform of which frequency is less than 1MHz. Thanks in advance!

1 Answer

10 years, 5 months ago.

Note that with PWM you can only do integer divisions. Since the K64F runs normally at 120MHz, you can get 60MHz with 50% duty cycle, or 40MHz with 67/33% duty cycle. If you want a 50MHz output you will need a 100MHz clock. This is possible if you modify mbed-src, but you need to look into the reference manual on which settings you need (in your program you need mbed-src instead of mbed, and then navigate to this file: https://github.com/mbedmicro/mbed/blob/master/libraries/mbed/targets/cmsis/TARGET_Freescale/TARGET_MCU_K64F/system_MK64F12.h).

Now regardless if you keep current clock and you go for 40/60MHz, or change the clock, the normal mbed PWM indeed can't go lower than 1MHz. FastPWM can: https://developer.mbed.org/users/Sissors/code/FastPWM/

Erik, many thanks for your help. Could you please tell me what 'system_MK64F12.h' is used for? Should I include it in my program?

posted by Gloria Meng 24 Jun 2015

It is used primarily/exclusively for setting the clock. You don't need to include it since this is done automatically by mbed. You do need to make the modifications in mbed-src, you cannot just add that file.

posted by Erik - 24 Jun 2015

Got it! Could FastPWM can be used in FRDM-K64F? Need I modify the FastPWM library? Thanks a lot!

posted by Gloria Meng 24 Jun 2015

FastPWM should work for the K64F

posted by Erik - 25 Jun 2015

FastPWM is very useful! I can output 50MHz waveform. However, When the frequency is low, I can output square waveform, when the frequency is high like 10MHz, it is more like a sine wave rather than square waveform. Could you please tell me why it is? Many thanks!

posted by Gloria Meng 25 Jun 2015

It is not due to the code, it is due to the hardware. Some pins might be able to be set at high drive strength, but not sure if the K64F has this, and which pins support it. In general it simply means the analog bandwidth is insufficient. Your scope might be limitted in speed, your measurement wire might be, or the load you apply on the pin might be too large. And finally I don't know what the rise/fall times are specced on for the K64F (you can get this from the datasheet).

When measuring the pin, make sure you use a probe with your scope (so not just a random wire), and put the probe in the 10x mode.

posted by Erik - 25 Jun 2015

Hi Erik, thank you very much. I have got the waveform. However, the output voltage from the pin is very small. Do you have any method to change the output voltage?

posted by Gloria Meng 04 Jul 2015

Also that is hardware. However do you take into account that if you put the probe on 10x, it reduces the voltage by a factor 10? You can either just take it manually into account when looking at the scope output, or alternatively, your scope should have an option somewhere to change the input to "10x" mode, where it changes the scale to cancel the 10x reduction of the probe.

posted by Erik - 04 Jul 2015