Output a kHz range clock through a GPIO?

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

Output a kHz range clock through a GPIO?

1,333 Views
nxa09603
NXP Employee
NXP Employee

Hi

I'm trying to output a 4 kHz 50% duty cycle square waveform through a GPIO. What is the simplest way of doing that? 

It doesn't need to be exactly 4 kHz. I accept some tolerance around the target. 

I was considering to use FAST_IRCLK as time base, divide the clock by 1024 and output it. Is it possible?

 I'm using MCUXpresso with KL02 SDK.

Thank you

Andre VB

2 Replies

1,221 Views
mjbcswitzerland
Specialist V

Hi

See also
https://www.utasker.com/docs/uTasker/uTaskerHWTimers.PDF
https://www.utasker.com/kinetis/FRDM-KL02Z.html

Available as open source on Git Hub "uTasker" including KL02 support and simulation - eg. generating 1kHz 20% output on PTB10:

pastedImage_1.png


Regards

Mark
[uTasker project developer for Kinetis and i.MX RT]

1,221 Views
myke_predko
Senior Contributor III

Hey nxa09603‌,

The simplest way of doing it is to use one of the TPMs (Timer/PWM Modules) built into the KL02 to generate a PWM signal.  Just taking a quick look at the datasheet/RM, you will use one of the TM#_CH# pins as your output. 

I should note that the TPMs are different from the FTMs of other Kinetis parts but there should be an example in the SDK that you can see in MCUXpresso and copy over quickly.  

Good luck,

myke