GPIO speed on the LPC812

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

GPIO speed on the LPC812

2,695件の閲覧回数
mahmoudhosseini
Contributor III

Based on datasheet -page 17:

    GPIO registers are located on the ARM Cortex M0+ IO bus for fastest possible

    single-cycle I/O timing, allowing GPIO toggling with rates of up to 15 MHz.

And I used a tiny code (based on the LPCOPEN library )to test it's speed:

Code: [Select]

      Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 0, 12);
    
    while(1)
    {
         Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 12, true);
         Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 12, false);
    
    }

When I trace this GPIO pin by logic analyzer,It's toggling around 250 KHZ which is far away from mentioned value in datasheet.

I also used PLL to increase main clock and system clock for achieving better speed:

Code: [Select]

    Chip_IRC_SetFreq(96000000, 24000000);

but even for different values 250KHZ is the most frequency which I cant overtake.Decreasing PLL speed cause decrements on output frequency of GPIO and also I know I can achieve better speed with assembly code but 250KHZ is so far away from datasheet & It seems MCU are not able to overtake from this limit(there ara same substance for 60MHZ/30MHZ - 60MHZ/15MHZ and so) Also 250KHZ is maximum speed which pins in the SPI peripheral state can toggled.

ラベル(4)
3 返答(返信)

1,994件の閲覧回数
mahmoudhosseini
Contributor III

Thanks for your replies:

I'm aware that for full speed test ,needed to code in assembly directly with registers ,But as i said before problem is after overtaking from 12MHZ main clock ,GPIO can not toggle faster,and also toggling speed for SPI CLOCK pin is limited to this speed too.

For introduced register based instructions >Gpio can't exceed from 250KHZ toggling speed yet

WBR.

0 件の賞賛
返信

1,994件の閲覧回数
martin_maurer
Contributor III

Have a look what Chip_GPIO_SetPinState() is doing. I assume it is doing checks and calculations, e.g if arguments are valid,

to get right register, to calculate what to write into the register...

Perhaps you can replace it by a single access to a register?

Try to unroll the calls in while. E.g. put 20 "set/reset" pairs one after the other.

Look at assembly code what compiler is really doing with your code.

Perhaps try to increase optimization level of compiler ("optimized for speed").

1,994件の閲覧回数
jonnevalola
Contributor II

Hello Mahmoud

You can't achieve high GPIO toggle speed by using library functions like Chip_GPIO_SetPinState. Those functions always have overhead that slows you down. You need to toggle by writing directly to GPIO registers, like so:

Code: [Select]

LPC_GPIO_T *gp; //make a pointer of type GPIO structure

gp = LPC_GPIO; //point to base address of GPIO registers in memory space

gp->DIR[2]=0xFFFFFFFF; // set all port 2 pins as output

gp->SET[2]=1<<17; // set pin 17 of port 2

gp->CLR[2]=1<<17;// clear pin 17 of port 2

Then, also realize that the while(1) {} loop also slows you down, because you have a conditional check and a jump in each cycle. If you want to see real toggling speed, you need to set and clear in a long unrolled loop:

Code: [Select]

while (1) {

gp->SET[2]=1<<17; // set pin 17 of port 2

gp->CLR[2]=1<<17;// clear pin 17 of port 2

gp->SET[2]=1<<17; // set pin 17 of port 2

gp->SET[2]=1<<17; // set pin 17 of port 2

gp->CLR[2]=1<<17;// clear pin 17 of port 2

gp->CLR[2]=1<<17;// clear pin 17 of port 2

...

}

Please notice that how you do this (writing to GPIO register structure) is dependent on the model of the MCU. This code is intended to show you the idea, it does not necessarily work on LPC812