K20D50 - Toggle IO pin max speed

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

K20D50 - Toggle IO pin max speed

913 Views
paulolouro
Contributor I

Hi

What is the max frequency i can toggle an IO pin using the MK20DX128 with 8Mhz crystal and PLL enabled to output 50Mhz?

I have used the ProcesssorExpert to configure the clock settings  and i got the following configuration output:

Core clock: 50Mhz

Bus clock: 50Mhz

External bus close: 50Mhz

Flash clock 25Mhz

I wrote the code bellow for testing, but according with my scope the toggling frequency is only  3.571Mhz. From the disassembly i can see that 4 instructions are needed to toggle the pin, that makes the core speed at 4 * 2 * 3.571Mhz = 28.568Mhz??? 

while(1)

    {

//RED_TOGGLE;
GPIOC_PTOR = 8;
GPIOC_PTOR = 8;
GPIOC_PTOR = 8;
GPIOC_PTOR = 8;
}

Regards,

Paulo

0 Kudos
3 Replies

454 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi Paulo,

After the GPIO register has been set or clear, there with some delay added to GPIO IO pin. That's why you could find GPIO toggle speed not as expected.

If you want to generate a fast frequency pulse output, you could consider to use FlexTimer module to generate PWM signal output.

Wish it helps.

B.R.

Ma Hui

0 Kudos

454 Views
paulolouro
Contributor I

Hi Hui_Ma,

Thanks for the reply.

Ya i can see there was some different behave from what i was expecting. The propose was only to check that the core clock was working as expected and that we were in fact running at 50Mhz. What i have done to manage that was to implement the SYSTick and then toggle a PIN via the ISR.

So what i have concluded is it that's 4 instructions cycles to process the each line GPIOC_PTOR = 8 and then an extra 3 for something else. Maybe 2 cycles for the bus and 1 for the IO.

Is there a document that explain Bus/FlexModules read write times?

Best regards,

Paulo Louro

0 Kudos

454 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi Paulo,

I would recommend you to use PTC3 pin (ALT5 function is CLKOUT), and with below setting, you could measure the Flash clock 25MHz on scope.

The PTC3 pin function setting:

  SIM_SCGC5 |= SIM_SCGC5_PORTC_MASK;

  SIM_SOPT2 |= SIM_SOPT2_CLKOUTSEL(2);

  PORTC_PCR3 = PORT_PCR_MUX(5);

Wish it helps.

B.R.

Ma Hui

0 Kudos