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