Function generator input to FRDM K64F board

cancel
Showing results for 
Search instead for 
Did you mean: 

Function generator input to FRDM K64F board

Jump to solution
1,604 Views
kirantujare
Contributor IV

I am working on a project using FRDM K64F wherein I want to read an input (pulse of 500ms) from Function generator to the micro controller and then output two pulses 1. With 180us delay and 2. Other same as input (500ms). on the scope. Please let me know how I could approach this problem? How could I use FlexTimer for this purpose? Is there another approach?

1 Solution
418 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Kirantujare,

    I help you create a KDS project, the function is capture the input wave rising and falling, and output the wave.

    In my project, I use the FRDM-K64 as the platform, connect PTC1, PTC2 together, and as the waveform generator input pin, PTB18 as the output pin. When capture the rising, then set the PTB18,

when capture the falling, then clear the PTB18.

  Attached is my test project, just for your reference, If you want have delay, please try to add it by yourself.

if you still have question, just let me know!

Have a great day,

Jingjing

-----------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. Thank you!

-----------------------------------------------------------------------------------------------------------------------

View solution in original post

20 Replies
418 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Kiran,

    Could you tell me 500ms pulse is fixed or variable?

  If it is fixed, and you know the frequent, you can just use the GPIO as the rising input trigger, when receive the rising wave from your function generator, then use timer delay 180us, after 180us is get, then use the FTM output the fixed PWM wave.

  But if your function generator wave is not fixed, and it is variable, you just want to out put the same wave and have 180us delay, you should use the FlexTimer and the GPIO. FlexTimer use two capture channels, one is for rising edge, another is for falling edge, just like the following picture:

72.jpg

    When the rising edged is captured, start a 180us timer, and associate with an index variable which can identify it is the rising edge, after 180us is got, you can refer to the index variable to output high in the GPIO pin, and disable the 180us timer. Similarly,  when the falling edge is captured, start a 180us timer, and associate with an index variable which can identify it is the falling edge, after 180us is got, you can refer to the index variable to output low in the GPIO pin, and disable the 180us timer.

  About the timer, you can use the flextimer, PIT, LPTMER, ect.

Wish it helps you!

If you still have question, please let me know!


Have a great day,
Jingjing

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
418 Views
kirantujare
Contributor IV

Hi Jingjing,
Thank you for the reply. It is very helpful. 500ms pulse is variable.
Do you have any example code for the use of FlexTimer? Can it be done with Processor Expert?

Also, to get the input from a function generator do I set the clock to external?

I have tried to write a code using reference from "Features of the FlexTimer Module"
I haven't added the 180us part. I would appreciate any help.

Best Regards,
Kiran Tujare

0 Kudos
418 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Kiran

  The KSDK have the K64 FTM driver, if you already download the KSDK2.0_K64, you can find it in this path: SDK_2.0_FRDM-K64F\devices\MK64F12\drivers\fsl_ftm.c

  Of course, you can use the Processor Expert, here have a post about the FTM PWM:

C:\Freescale\SDK_2.0_FRDM-K64F\devices\MK64F12\drivers

https://community.freescale.com/message/548043#comment-548043

  You can choose the input capture mode.

Wish it helps you!

If you still have question, please contact me!


Have a great day,
Jingjing

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
418 Views
kirantujare
Contributor IV

Hi Jingjing,
Thank you for the reply. In the link above, I didn't understand this part of the code?
What are the hex values? How do I write 180microseconds in hex value?

temp = FTM2_C0V;

    if(temp < 0x4000){

    FTM2_C0V = temp + 0x10;

    } else {

    FTM2_C0V = 0x10;

    }

0 Kudos
418 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Kiran,

    FRM2_C0V contain the captured FTM counter value for the input modes or the match value for the output modes.

  Your code which you mentioned should fromt he output modes, it just define the match value, after the FTM match this value, the PWM will change the signal, it normally used to change the duty of the PWM.

  If you want to write the 180ms, you should associate with your FTM module clock, then calcuate 180ms equal to how many FTM clocks, then define the MOD, or you can use other timer, eg, PIT.

Wish it helps you!

If you still have question, please contact me!


Have a great day,
Jingjing

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
418 Views
kirantujare
Contributor IV

Hi Jingjing,
Thank you for the your help. Although, I am not understanding how to use FlexTimer. I guess I need to understand the concept more in depth.
Please let me know if there are more examples available? I appreciate your patience with me.
Also, can fsl_ftm output more than one pwm signal? or it works only for 1 PWM signal?

0 Kudos
418 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Kiran,

    If you want to understand the FTM concept, you can read the K64 reference manual ,FTM chapter, then you will know more.

  About the FTM sample code, you can download the KSDK1.3.0,  you will find the ftm code in folder: C:\Freescale\KSDK_1.3.0\examples\twrk64f120m\driver_examples\ftm

  For one FTM module, it has a lot of channels, you can find it in the reference manual, 3.8.2.1 Instantiation Information.

  So, one FTM, different channel, can output more PWM signals, not just one. one channel can out put one PWM.

Wish it helps you!
Have a great day,
Jingjing

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
418 Views
kirantujare
Contributor IV

Hi Jingjing,
I was trying to use Init_FTM from processor expert.
I was wondering if I could increase my period?
Is this(128.002ms) the maximum period I get? I want a period of 500ms.
I have attached the screenshot after changing the prescale value and the modulo counter.

Also, I'm still confused if I have to use external clock since my pulse is from a function generator?
The following post talks about that - How to count external events with flex timer Mo... | NXP Community

0 Kudos
418 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Kiran,

  If you choose the bus clock, set the bus clock as 60Mhz and choose it as the FTM clock source, you just can get 139.810ms as the maximum period.

  But it doesn't matter, you can configure the 100ms as the period of FTM, after it has 5 period, then you can get the 500ms.

78.jpg

    Enable the FTM timer overflow interrupt, define a user variable as the interrupt counter, when you counter 5 times overflow interrupt, it is 500ms, you can disable the FTM.

Wish it helps you!


Have a great day,
Jingjing

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
418 Views
kirantujare
Contributor IV

Hi Jingjing,
Thank you for the reply. My questions may seem silly but please help me out. If it is possible could you create one example project for this in KDS 3.2? I would greatly appreciate it. Please let me know.
I also have the following questions.

1. How to start timer(Enable FTM)?

2. How to STOP timer(Disable FTM)?

3. Do I increment interrupt counter value in for(;;) loop?
4. How to detect rising edge and falling edge?

5. How to do the entire project using processor expert without manually assigning register values?
6. I am not being able to use GPIO+FTM together

0 Kudos
418 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Kiran,

  I will help you to create a FTM project, do you want to output 500ms period PWM? what the duty you want to have?

  1, 2, FTMx_SC[CLKS] can used to enable FTM and Disablet he FTM count.

3, No, just define a variable to increase it in the interrupt.

4, FTMx_CnSC register configration determine the rising edge or falling edge it will capture.

5. You need to choose the according module and configure it, then add the code which needed.

Best Regards,

Jingjing

0 Kudos
418 Views
kirantujare
Contributor IV

Hi Jingjing,
Thank you so much. I want to capture a pulse of 500ms, say 50% duty cycle from function generator. I need two pins
1. To connect function generator input
2. To check the output on scope
I want for FRDM K64F board on KDS 3.2 and KSDK1.3. Thank you once again. I greatly appreciate it.

Best Regards,
Kiran Tujare

0 Kudos
418 Views
kirantujare
Contributor IV

Hi Jingjing,
I apologize for asking again. I cannot move further with my project.
It would really help me if you create one example project. Please let me know if it is possible. I would appreciate it.

Best Regards,
Kiran Tujare

0 Kudos
418 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Kiran,

     Create the project and realize the detail function need time, so please wait patiently, or you can try to create it and add the code by yourself at the same time, if the function can't realized, then tell me where your stopped and upload the project.

  

Best Regards,

   Jingjing

0 Kudos
418 Views
kirantujare
Contributor IV

Hi Jingjing,
Thank you for the reply. I will be waiting for your response.
I tried writing a code and haven't succeeded so far. I am sure I'm missing something. I have attached the code below.

Best Regards,
Kiran Tujare

0 Kudos
418 Views
kerryzhou
NXP TechSupport
NXP TechSupport

This is my test result picture:

6.jpg

This is the PTB18 output in the oscilloscope:

7.jpg

419 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Kirantujare,

    I help you create a KDS project, the function is capture the input wave rising and falling, and output the wave.

    In my project, I use the FRDM-K64 as the platform, connect PTC1, PTC2 together, and as the waveform generator input pin, PTB18 as the output pin. When capture the rising, then set the PTB18,

when capture the falling, then clear the PTB18.

  Attached is my test project, just for your reference, If you want have delay, please try to add it by yourself.

if you still have question, just let me know!

Have a great day,

Jingjing

-----------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. Thank you!

-----------------------------------------------------------------------------------------------------------------------

View solution in original post

418 Views
kirantujare
Contributor IV

Hi Jingjing,
Thank you so much. I greatly appreciate it. It works perfectly.
I have a question. I tried to capture on a single pin. For doing that, I changed the edge control on channel 0 to : "Rising or Falling" and deselected channel 1 completely. I didn't get any input waveform on oscilloscope. To capture on a single pin is it the correct way I tried?
I tried to use "wait" on processor expert for delay. Is that okay?

0 Kudos
418 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Kirantujare,

    You can use the capture on rising or falling edge with one pin, but when the interrupt happen, you don't know the what the edge, you should associate with the GPIO input reading to get it.

   If you want to delay, you can use PIT timer to realize it.

Best Regards,

Jingjing

418 Views
kirantujare
Contributor IV

Hi Jingjing,
Thank you for all the help :smileyhappy:

0 Kudos