FRDM-K22F PIT GPIO Toggle Frequency Problem

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

FRDM-K22F PIT GPIO Toggle Frequency Problem

757 Views
jackxu
Contributor III

Hi there,

Recently i'm trying to write some routine with PIT control GPIOs, but it runs in disorder. Part of PIT0_IRQHandler routine as follow:

/****************************PIT0_IRQHandler***********************************************/

cnt1 = (cnt1 + 1) & 0xff;

const1 = 500;

/**********************************************************************************************/

if (const1 >500)

{

     if(cnt1 < 64)

     {

          GPIO_ClearPinsOutput(BOARD_PIN1_GPIO, 1U << BOARD_PIN1_GPIO_PIN);

     }

     else if (cnt1 < 128)

     {

          GPIO_SetPinsOutput(BOARD_PIN1_GPIO, 1U << BOARD_PIN1_GPIO_PIN);

     }

     else

     {

          GPIO_ClearPinsOutput(BOARD_PIN1_GPIO, 1U << BOARD_PIN1_GPIO_PIN);

     }

}

else

     GPIO_ClearPinsOutput(BOARD_PIN1_GPIO, 1U << BOARD_PIN1_GPIO_PIN);

/***************************************************************************************************/

if (cnt1 < 128)

{

     GPIO_ClearPinsOutput(BOARD_PIN2_GPIO, 1U << BOARD_PIN2_GPIO_PIN);

}

else if(cnt1 < 192)

{

     GPIO_SetPinsOutput(BOARD_PIN2_GPIO, 1U << BOARD_PIN2_GPIO_PIN);

}

else

{

     GPIO_ClearPinsOutput(BOARD_PIN2_GPIO, 1U << BOARD_PIN2_GPIO_PIN);

}

/*****************************************************************************************************/

if(cnt1 > 256)

{

     cnt1 = 0;

}

/*****************************************************************************************************/

/********************************Main****************************************************************/

    PIT_SetTimerPeriod(PIT, kPIT_Chnl_0, 2000);

and set my bus clock @ 50MHz, then the PIN1's frequency should @50MHz/2000/256=97.66Hz

But read from my scope is @48.83Hz

also the PIN2's frequency is the same as the PIN1

@. (the first 10.24ms is ok, but there is another 10.24ms, do not know why there is another 10.24ms)

Thanks in advance!

-Jack

3 Replies

582 Views
jackxu
Contributor III

Hi Jorge,

const1 = 510, it's a const, then the PIN1 can be controlled, i wrote a wrong number, yes i pretend to get PIN1 a quarter of 256 counts.

But also want to PIN2 high counts from 128 to 192, and the scope shows PIN2 can be counts to 512, so the PIN2 keeps high only half of a quarter of a cycle, not a quarter of the cycle.

So is the PIN1, after changed const1 = 510

Thanks in advance!

-Jack

0 Kudos
Reply

582 Views
jorge_a_vazquez
NXP Employee
NXP Employee

Hi Jack Xu

I made some tests with your handler routine and it works as it should, so could we assumed that the routine is fine but maybe the timer is not 50 MHz. How did you set up the bus at 50 MHz?

If I undertand correctly you should have a 10.24 ms signal where 2.56 ms should be high and 7.68 should be low, right? could you share your project to try to replicate your issue?


Have a great day,
Jorge Alcala

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

0 Kudos
Reply

582 Views
jorge_a_vazquez
NXP Employee
NXP Employee

Hi Jack

I don't see clear how you change const1 to change the state of PIN1, const1 is always equals to 500, but as I see your "if statements" shouldn't be as you have it, because you keep PIN1 low from cnt1=0 to cnt1=64, from cnt1=65 to cnt1=128 you keep PIN1 high, but then from cnt1=129 to 256 you again keep it low. So you PIN1 is high just a quarter of the 256 counts, is this what you pretend to do?

If you do something like:

    if (cnt1 < 128)

    {

          GPIO_SetPinsOutput(BOARD_PIN1_GPIO, 1U << BOARD_PIN1_GPIO_PIN);

    }

    else

    {

          GPIO_ClearPinsOutput(BOARD_PIN1_GPIO, 1U << BOARD_PIN1_GPIO_PIN);

    }

you will get what you want.


Have a great day,
Jorge Alcala

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