Ejemplo n.º 1
0
void us_ticker_free(void)
{
    PIT_StopTimer(PIT, kPIT_Chnl_1);
    PIT_StopTimer(PIT, kPIT_Chnl_0);

    TPM_DisableInterrupts(TPM2, kTPM_TimeOverflowInterruptEnable);
    NVIC_DisableIRQ(TPM2_IRQn);

    us_ticker_inited = false;
}
Ejemplo n.º 2
0
void us_ticker_init(void)
{
    /* Common for ticker/timer. */
    uint32_t busClock;
    /* Structure to initialize PIT. */
    pit_config_t pitConfig;

    if (us_ticker_inited) {
        /* calling init again should cancel current interrupt */
        TPM_DisableInterrupts(TPM2, kTPM_TimeOverflowInterruptEnable);
        return;
    }

    PIT_GetDefaultConfig(&pitConfig);
    PIT_Init(PIT, &pitConfig);

    busClock = CLOCK_GetFreq(kCLOCK_BusClk);

    PIT_SetTimerPeriod(PIT, kPIT_Chnl_0, busClock / 1000000 - 1);
    PIT_SetTimerPeriod(PIT, kPIT_Chnl_1, 0xFFFFFFFF);
    PIT_SetTimerChainMode(PIT, kPIT_Chnl_1, true);
    PIT_StartTimer(PIT, kPIT_Chnl_0);
    PIT_StartTimer(PIT, kPIT_Chnl_1);

    /* Configure interrupt generation counters and disable ticker interrupts. */
    tpm_config_t tpmConfig;

    TPM_GetDefaultConfig(&tpmConfig);
    /* Set to Div 32 to get 1MHz clock source for TPM */
    tpmConfig.prescale = kTPM_Prescale_Divide_32;
    TPM_Init(TPM2, &tpmConfig);
    NVIC_SetVector(TPM2_IRQn, (uint32_t)tpm_isr);
    NVIC_EnableIRQ(TPM2_IRQn);

    us_ticker_inited = true;
}
Ejemplo n.º 3
0
/*!
 * @brief Main function
 */
int main(void)
{
    tpm_config_t tpmInfo;
    tpm_chnl_pwm_signal_param_t tpmParam;
    tpm_pwm_level_select_t pwmLevel = kTPM_LowTrue;

    /* Configure tpm params with frequency 24kHZ */
    tpmParam.chnlNumber = (tpm_chnl_t)BOARD_TPM_CHANNEL;
    tpmParam.level = pwmLevel;
    tpmParam.dutyCyclePercent = updatedDutycycle;

    /* Board pin, clock, debug console init */
    BOARD_InitPins();
    BOARD_BootClockRUN();
    BOARD_InitDebugConsole();
    /* Select the clock source for the TPM counter as kCLOCK_PllFllSelClk */
    CLOCK_SetTpmClock(1U);

    /* Print a note to terminal */
    PRINTF("\r\nTPM example to output center-aligned PWM signal\r\n");
    PRINTF("\r\nYou will see a change in LED brightness if an LED is connected to the TPM pin");
    PRINTF("\r\nIf no LED is connected to the TPM pin, then probe the signal using an oscilloscope");

    TPM_GetDefaultConfig(&tpmInfo);
    /* Initialize TPM module */
    TPM_Init(BOARD_TPM_BASEADDR, &tpmInfo);

    TPM_SetupPwm(BOARD_TPM_BASEADDR, &tpmParam, 1U, kTPM_CenterAlignedPwm, 24000U, TPM_SOURCE_CLOCK);

    /* Enable channel interrupt flag.*/
    TPM_EnableInterrupts(BOARD_TPM_BASEADDR, TPM_CHANNEL_INTERRUPT_ENABLE);

    /* Enable at the NVIC */
    EnableIRQ(TPM_INTERRUPT_NUMBER);

    TPM_StartTimer(BOARD_TPM_BASEADDR, kTPM_SystemClock);

    while (1)
    {
        /* Use interrupt to update the PWM dutycycle */
        if (true == tpmIsrFlag)
        {
            /* Disable interrupt to retain current dutycycle for a few seconds */
            TPM_DisableInterrupts(BOARD_TPM_BASEADDR, TPM_CHANNEL_INTERRUPT_ENABLE);

            tpmIsrFlag = false;

            /* Disable channel output before updating the dutycycle */
            TPM_UpdateChnlEdgeLevelSelect(BOARD_TPM_BASEADDR, (tpm_chnl_t)BOARD_TPM_CHANNEL, 0U);

            /* Update PWM duty cycle */
            TPM_UpdatePwmDutycycle(BOARD_TPM_BASEADDR, (tpm_chnl_t)BOARD_TPM_CHANNEL, kTPM_CenterAlignedPwm,
                                   updatedDutycycle);

            /* Start channel output with updated dutycycle */
            TPM_UpdateChnlEdgeLevelSelect(BOARD_TPM_BASEADDR, (tpm_chnl_t)BOARD_TPM_CHANNEL, pwmLevel);

            /* Delay to view the updated PWM dutycycle */
            delay();

            /* Enable interrupt flag to update PWM dutycycle */
            TPM_EnableInterrupts(BOARD_TPM_BASEADDR, TPM_CHANNEL_INTERRUPT_ENABLE);
        }
    }
}
Ejemplo n.º 4
0
void us_ticker_disable_interrupt(void)
{
    TPM_DisableInterrupts(TPM2, kTPM_TimeOverflowInterruptEnable);
}