Generate Tone frequency using GPIO Pin

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Generate Tone frequency using GPIO Pin

1,566 Views
mayursavaj
Contributor III

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

Labels (1)
9 Replies

1,074 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

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.

PPG_LDD PPG1_SetFrequencyHz.png


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.

MK22FX512VLL12 FTM0-FTM3.png


And MK22FX512VLL12 is Not Recommended for New Design, please select another K22 MCU.

Not Recommended for New Design.png

Best Regards,

Robin

 

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

0 Kudos

1,074 Views
mayursavaj
Contributor III

Hi Robin,

We are using MK22Fx512VLL12. But my issue is that buzzer don't have FTM functionality.So I have use as a GPIO.

pastedImage_1.png

0 Kudos

1,074 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi Mayur,

I don't know the type of your buzzer.

Do you want a waveform to drive the buzzer like this:

piezo-buzzer-circuit.png

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.

Example of generated signal PPG_LDD.png

The pin with FTMx_CHx have that capability. For example Pin93 PTD2.

FTM3_CH0 pin93.png

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!
---------------------------------------------------------------------------------------------------------------------

0 Kudos

1,074 Views
mayursavaj
Contributor III

Hi Robin,

According to data sheet pin 90 don't have FTM capability.

Please suggest me alternate method.

Thanks,

Mayur

0 Kudos

1,074 Views
mjbcswitzerland
Specialist V

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

1,074 Views
mayursavaj
Contributor III

Hi Robin,

I am using Pin 90. We can't change Pin because all other pins have connected to other peripheral.

0 Kudos

1,074 Views
mayursavaj
Contributor III

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

0 Kudos

1,074 Views
markwyman
Contributor III

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.

0 Kudos

1,074 Views
mjbcswitzerland
Specialist V

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

0 Kudos