Hi,
We are using MK22Fx512 controller.
I was trying to generate Frequency using PIT timer. its working some frequency but not all. We need to generate frequency between 2k to 4k Hz. I am getting some noise intermediate.
Please suggest me how to resolve this issue.
Thanks in advance,
Mayur
Hi Mayur,
The PPG_LDD can be used generated PWM signal from 2kHz to 4kHz. It was based on modify the FTMx_MOD of FTM module. If you don't want to use the code generated by Processor Expert, you can also use the FTM examples in Kinetis SDK V2.
If you are using MK22FX512VLL12, it have four FTM modules. So I am not sure why you want to generate Tone frequency using GPIO instead of using FTM module.
And MK22FX512VLL12 is Not Recommended for New Design, please select another K22 MCU.
Best Regards,
Robin
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
---------------------------------------------------------------------------------------------------------------------
Hi Robin,
We are using MK22Fx512VLL12. But my issue is that buzzer don't have FTM functionality.So I have use as a GPIO.
Hi Mayur,
I don't know the type of your buzzer.
Do you want a waveform to drive the buzzer like this:
The FTM module can be used output waveform with 3.3v. And the PPG1_SetFrequencyHz can be used to change the frequency of waveform at runtime.
The PPG_LDD can be used to output PWM waveform with 50% Ratio. You can set the Ratio to 50% using PPG1_SetRatio16 function.
The pin with FTMx_CHx have that capability. For example Pin93 PTD2.
And would you please tell us which pin are you using? Or can you select another pin with FTM capability?
Best Regards,
Robin
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
---------------------------------------------------------------------------------------------------------------------
Hi Robin,
According to data sheet pin 90 don't have FTM capability.
Please suggest me alternate method.
Thanks,
Mayur
Hi Mayur
I'll repeat a final time that DMA is the way to do it as shown a number of times now.
Since you are not making any progress after what looks like 3 weeks from your original question, why not simply change the pin used on the HW to one that allows the FTM to be used? This HW modification probably costs less that the SW development/workaround in the long run.
Also remember when the next HW is designed to connect pins suitably to make use of the processor's HW capabilities.
Regards
Mark
Hi Robin,
I am using Pin 90. We can't change Pin because all other pins have connected to other peripheral.
Hi Robin,
Can I use GPIO pin as PWM (if Pin don't have that capability)? If yes than please send me some example.
Thanks,
Mayur
A PIT timer appears to be more optimized for internal peripheral timing, it doesn't appear to have a hardware connection to a I/O pin so you have to toggle a GPIO. Can you use a general purpose timer and PWM output instead? That way interrupt latency and other interrupt events in your processor wont get in the way of the pin toggling on time. What you are seeing now are other events blocking and delaying the pin from toggling.
Hi Mayur
As mentioned in your other thread, the only serious way to use a PIT channel to generate a stable frequency on a GPIO pin is to use DMA: Generate Frequency using GPIO Pin
If you prefer to use interrupts, for example, you may need to accept some jitter/noise; If your only possibility is to use interrupts make sure that you give the interrupt highest priority and, where possible, don't globally block the interrupt when other interrupts are handled or in critical code regions (use the interrupt mask setting rather than global interrupt mask).
Generally I still maintain that resorting to interrupts when DMA is a fairly simple possibility (I already posted code for it which operates on all GPIOs on all Kinetis parts with a free DMA channel) is poor practice, only for use in hobby projects and not in professional product design.
Regards
Mark