LPC1114 How to boost frequency of gpio

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

LPC1114 How to boost frequency of gpio

1,656 Views
cancetin
Contributor II

Hi,

I have a problem. I have studied on lpc1114/333 48 pins    and my main clock is 48 MHz (i set it and i saw in o-scope screen from CLKOUT pin ) but I want to adjust my gpio 0_8 pin toggle frequency to10 Mhz but i have shown 1.3 Mhz in o-scope screen. Please help me .

Tags (3)
5 Replies

1,214 Views
johanmyréen
Contributor II

I am surprised you get such a high frequency as 1.3 MHz from the PWM output. Your cycle count is huge: 30000 Timer clock cycles are counted for each cycle of the PWM output. In addition, because the Prescaler counter value is 1, the Timer Clock is PCLK divided by two.

Ps. Your usage of the term GPIO is a bit confusing. Usually GPIO is used to describe programmed I/O lines without any special purpose device connected to it, like a timer with a PWM output.

1,214 Views
sergedemaseneer
Contributor III

I expect you to not reach 10MHz whilst programming in C. There is way too much overhead (calling API's - using libraries).

To reach 10MHz out of a 48MHz clock you get about 4 assembler instructions (please correct me if i am wrong) to get your 10MHz. I say 4 instructions and i am not counting teh branch prediction algorythms used in the LPC when jumping to another part of the code. When the LPC gambles wrong, it must clean the instruction pipeline.

I think that 1.25MHz with a C program is already a lot.

Guys at NXP please tell me that i am wrong.

0 Kudos

1,214 Views
sergedemaseneer
Contributor III

I expect you to not reach 10MHz whilst programming in C. There is way too much overhead (calling API's - using libraries).

To reach 10MHz out of a 48MHz clock you get about 4 assembler instructions (please correct me if i am wrong) to get your 10MHz. I say 4 instructions and i am not counting teh branch prediction algorythms used in the LPC when jumping to another part of the code. When the LPC gambles wrong, it must clean the instruction pipeline.

I think that 1.25MHz with a C program is already a lot.

Guys at NXP please tell me that i am wrong.

0 Kudos

1,212 Views
cancetin
Contributor II

Thank you for response Kerry  I send my code. If  you can shoot a glance my code, I  will be greatful to you.  First  I set main clock 48 Mhz and  I write a toggle code and i have measured gpio frequency with o-scope but i have obtained solely 1.25 Mhz.  

int main(void) {

LPC_SYSCON->SYSAHBCLKCTRL |= (1<<6); // clock for gpio
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<7); //Open SYSAHBCLKCTRL 7. bit
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<16); // clock for iocon pin


LPC_IOCON->PIO0_1 &= 0xFFFFFFF8; //clear FUNC bits (sec. 7.4.4)
LPC_IOCON->PIO0_1 |= 0x01; //set FUNC bits to CLKOUT function (sec. 7.4.4)
LPC_GPIO0->DIR |= (1<<1); //set CLKOUT pin to output (sec. 12.3.2)
LPC_SYSCON->CLKOUTCLKSEL |= 0x3; //sec. 3.5.21
LPC_SYSCON->CLKOUTUEN = 0; //"CLKOUTUEN" has to be toggled for "CLKOTUCLKSEL" to accept the value written to it
LPC_SYSCON->CLKOUTUEN = 1; //"CLKOUTUEN" has to be toggled for "CLKOTUCLKSEL" to accept the value written to it
LPC_SYSCON->CLKOUTDIV = 0x1; //set divider to 1 (sec. 3.5.23)



LPC_SYSCON->MAINCLKSEL &= ~(0x3); //set “main clock” to IRC oscillator, if not system will lock up when PLL turns off!(sec. 3.5.11)
LPC_SYSCON->MAINCLKUEN &= ~(1); //write a zero to the MAINCLKUEN register (sec. 3.5.12), necessary for MAINCLKSEL to update
LPC_SYSCON->MAINCLKUEN |= 1;



LPC_SYSCON->SYSPLLCLKSEL = 0x0;

LPC_SYSCON->SYSPLLCLKUEN &= ~(1); //write a zero to SYSPLLUEN register (sec. 3.5.10), necessary for SYSPLLCLKSEL to update
LPC_SYSCON->SYSPLLCLKUEN |= 1; //write a one to SYSPLLUEN register (sec. 3.5.10), necessary for SYSPLLCLKSEL to update LPC_SYSCON->SYSPLLCTRL = 0x23;

LPC_SYSCON->PDRUNCFG |= (1<<7); //power down the PLL before changing divider values (sec 3.5.35)
LPC_SYSCON->SYSPLLCTRL = 0x23; //set MSEL = 0x00011 and PSEL = 0x01 (sec 3.5.3 and table 46 of sec. 3.11.4.1)
LPC_SYSCON->PDRUNCFG &= ~(1<<7); //power up PLL after divider values changed (sec. 3.5.35)


LPC_SYSCON->SYSAHBCLKCTRL =0x1;

while((LPC_SYSCON->SYSPLLSTAT & 1) == 0); //wait for PLL to lock
LPC_SYSCON->MAINCLKSEL = 0x03; //set system oscillator to the output of the PLL (sec. 3.5.11)
LPC_SYSCON->MAINCLKUEN &= ~(1); //write a zero to the MAINCLKUEN register (sec. 3.5.12), necessary for MAINCLKSEL to update
LPC_SYSCON->MAINCLKUEN |= 1; //write a one to the MAINCLKUEN register (sec. 3.5.12)


LPC_IOCON->PIO0_8 = (LPC_IOCON->PIO0_8 & ~(0x3FF)) | 0x2; //set up pin for PWM use (sec 7.4.23)


LPC_TMR16B0->TCR = 2;
LPC_TMR16B0->TCR = 0 ;

LPC_TMR16B0->PR = 0x01; //set prescaler max value, not used here (sec 18.7.4)
LPC_TMR16B0->MCR = 0x10; //set for reset on counter match (sec 18.7.6)
LPC_TMR16B0->EMR |= 0x20; //set pin 27 to 1 on match (sec 18.7.10)
LPC_TMR16B0->CCR = 0; //set to timer mode (sec 18.7.11)
LPC_TMR16B0->PWMC = 0x1; //set channel zero to PWM mode (sec 18.7.12)
LPC_TMR16B0->MR1 = 30000; //set value for period (sec 18.7.7)
LPC_TMR16B0->MR0 = 15000; //set value for duty cycle (sec 18.7.7)
LPC_TMR16B0->TCR |= 0x3; //enable and reset counter (sec 18.7.2)
LPC_TMR16B0->TCR &= ~(0x2); //clear reset bit (sec 18.7.2)



while(1) //infinite loop


{


}


}


I have set timer for pin 0_8 but let's suppose  I set gpio toggle with register direction again i obtain same freq. value. If you desire look to the  Lpc 1114 user manual

0 Kudos

1,214 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi CAN CENTIN,

    The GPIO toggle speed have limit.

    I don't how you write the GPIO toggle code, you can try to call the register directly, instead of use the API function, besides, don't use the while, just use the toggle code list, then check what the frequence you can realized?

   Please test it again on your side.

   Any updated information, please let me know.

  


Have a great day,
Kerry

 

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