Fast GPIO on Kinetis KF22

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

Fast GPIO on Kinetis KF22

Jump to solution
3,844 Views
lous
Contributor III

Hi,

I started a new project on the Freedom kinetis KF22 for get the better speed in my application.

Before I used the atxmega from atmel, but max speed is 32Mhz. So with 120Mhz I think I found the good solution for drive a TFT screen (parallel mode 8bits).

I set with successful the clock speed and all register but I can't drive GPIO faster than 9Mhz for one period = 110ns to full period, so  . (My core clock is 120Mhz and BusClock is 60Mhz).

My instruction for driver GPIO is :

-----------

//Set port to output, mux to gpio, fast slewrate, low drive

while(1)

{

GPIOD_PTOR = 1<<2; //repeated 100 times in code to avoid the while instructions delay

}

----------

I see on another topic the same problem but for L series, and the answer is to use the IOPORT register (FGPIO). I can't found this in datasheet/manual. Only in L series.

(https://community.freescale.com/thread/308402)

Any ideas to my problem ?

Another question : It's possible to group pin into one byte for write the value in one cycle ? On the KF22 pin is splitted

(KDS v2 and SDK 1.1.0)

Best regards

0 Kudos
Reply
1 Solution
2,543 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Lous,

The K series Kinetis MCUs don't integrate the FGPIO module now and I illustrate the port rise and fall time as below, you also find it in datasheet.

However in fact, the slew rate maybe much slower than the datasheet illustrates, as the code execution will cost time too.

pastedImage_0.png
Have a great day,
Ping

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

View solution in original post

0 Kudos
Reply
11 Replies
2,543 Views
lous
Contributor III

Hi,

My new scope arrived today.

I change my code for fast gpio access and you can see the screenshot I have 30Mhz period. (60Mhz change on bus)

Thank you.

NewFile0.png

(Rise and Fall time is not set from the base :smileywink:)

Scope used : DS1052E with 100Mhz mod Probe x1 (capacitance add rise/fall time, and the signal is not on 0v, but 2vpp).

If I set to x10 my probe for capacitance low, I have around 4ns rise/fall time and pretty good square wave at 30Mhz :smileyhappy: (can post screenshot if any one want)

Very good mcu for the price :smileyhappy:

Best regards

0 Kudos
Reply
2,543 Views
gloria
Contributor III

Hi Lous,

Could you tell me which method did you use to output 30MHz square wave? I am using K64F board with 120MHz system clock and 60MHz Bus Clock and I want to output 50MHz square wave. Many thanks!

0 Kudos
Reply
2,543 Views
lous
Contributor III

Hi, is pretty simple, but... :) First : do not rely on bus speed if you are in debug (if you use kdsk lib and gpio_hal or function provided by the ksdk). For max speed, you must use GPIO_PxOR (x = D, T, ...) for clear/set/toggle in the register, not by function :) For 50Mhz with this way is pretty hard, because is not exactly the bus speed. Maybe in pwm, or DMA you can achieve exactly this speed. You have low amount of instruction between each edge, signal change every 20ns and your cpu execute every 8.33ns, set your cpu clock to 100Mhz and bus speed to 50Mhz and it's ok :) * Set cpu/bus clock * Set clock for PORTx (a/b/c/d/e...) * Set to GPIO the pins, and direction output, high speed (rise/falling time, high strength) * Play with GPIO_PxOR. If you want more information tell me :) Best regards

0 Kudos
Reply
2,543 Views
gloria
Contributor III

Hi lous, many thanks for your help. It's very helpful. Since the maximum speed of bus clock is 60MHz, does it mean the maximum speed that I can output is 30MHz ? Could I output the signal which has the same freuqnency with bus clock?

0 Kudos
Reply
2,543 Views
egoodii
Senior Contributor III

It IS possible to output a 'burst' of square-waves at 1/2 CPU-clock.  As noted, getting a 60MHz square-wave to 'look at all square' on a pin requires high-drive, low-load, AND a good scope (>250MHz bandwidth).

But it requires an exacting control over the CPU instruction sequence so that each port-write is exactly one 2-byte instruction.  If you want something 'more' than just a burst of square-waves (like a bit-banged SPI) expect more like 20 instruction-clocks per bit (two clock edges) in an optimized loop.  See:

Confirming K22F Clock Frequency

You may also get some benefit in the 'K' series from the bit-banding single-bit-R/W to peripheral (and/or SRAM_U) space.  Peripheral-access is 'easy' with a macro; working with SRAM involves your toolchain linker, and pretty much requires forced-fixed SRAM allocation for compile-time math.

0 Kudos
Reply
2,543 Views
lous
Contributor III

Hi,

I have not see the 50Mhz square for the frequency :smileyhappy:

With bus clock of 60Mhz max you can't without another component on your board. (Or I don't know how you can reach this speed with this mcu)

But you can check if the cpu can output clock on pins. But you don't have precise control of the clock (like only 100 high pulse).

If you describe more what you need 50Mhz square wave, I can help you in the possiblity of my knowledge :smileyhappy:

Br

0 Kudos
Reply
2,544 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Lous,

The K series Kinetis MCUs don't integrate the FGPIO module now and I illustrate the port rise and fall time as below, you also find it in datasheet.

However in fact, the slew rate maybe much slower than the datasheet illustrates, as the code execution will cost time too.

pastedImage_0.png
Have a great day,
Ping

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

0 Kudos
Reply
2,543 Views
mjbcswitzerland
Specialist V

Lous

If you toggle a port output on the K22 when it is running at 120MHz core and 60MHz bus you will measure about 60MHz (~8ns high and ~8ns low). In fact this will not allow the output to swing fully between '0' and '1' since the slew rate of the output is slower than this (even with the port configured for fast slew rate).

If you measure lower speeds you need to suspect the clock setting that you think that you have.

You can not write a group of bits in a single instuction unless you want to set all to '0' or all to '1' or toggle all.

If you are starting a new design also consider a Kinetis with FlexBus since this allows high speed operations with true memory writes. For TFT with internal controller bit banging is however still fairly fast - a K70 includes a TFT controller that will drive a TFT without internal controller.

Regards

Mark

Kinetis: µTasker Kinetis support

K22: µTasker Kinetis FRDM-K22F support / µTasker Kinetis TWR-K22F120M support

For the complete "out-of-the-box" Kinetis experience and faster time to market

2,543 Views
lous
Contributor III

Hi,

I make a call CLOCK_SYS_GetBusClockFreq and result is 60Mhz.

-> I can trust this answer or I need to check all clock registers/div ?

It's the startup/init code from DevKit (freedom board KF22) shipped in SDK.

Thank you for your answer :smileyhappy:

0 Kudos
Reply
2,543 Views
mjbcswitzerland
Specialist V

Lous

I don't know whether you can trust the code that you are using or not.

However, since the majority of posts in the forum are about difficulties using such code it makes sense to always question and double check everything; whether due to code errors or usage errors.

I use only code from the uTasker project which also shows settings in its simulator and so removes such sources of potential error. (Also check UART2 or other peripheral speeds etc. since these are also based on the bus clock and would immediately show deviations).

Attached is a binary that you can load to a FRDM-K22. It will toggle the green LED at 2.5Hz.

Each time it toggles it will in fact toggle 101 times - this means that there are 50 cycles at each edge that can be measured to see how fast the port output actually is. You will see it is about 50..60MHz and again suggests that your case can't be running at full speed or else you are making an error during measurement.

With this binary you can compare registers and the measurement to see where the deviation is (note that you will need a fast oscilloscope to see all changes but even with a slow one the 50 cycles are seen as an intermediate step (with ripple) in the output voltage level at each change).

Regards

Mark

Kinetis: µTasker Kinetis support

K22: µTasker Kinetis FRDM-K22F support / µTasker Kinetis TWR-K22F120M support

For the complete "out-of-the-box" Kinetis experience and faster time to market


0 Kudos
Reply
2,543 Views
lous
Contributor III

Mark,

I order new scope two days ago, so when received it I can check if my old scope is not enough to check the signal (100Mhz). (and my frequency counter is 20Mhz limit :smileysad:).

I check your code when the new oscilloscope is in my office.

Regards

0 Kudos
Reply