Jump to content

Sign in to follow this  

Проблема с LPTIMER

Recommended Posts

Все мне нравиться в кинетис за исключением их убогих таймеров.

Настраиваю таймер как счетчик милисекунд

void LPTMR_Setup(void)
    lptmr_config_t lptmr_config;

    lptmr_config.timerMode = kLPTMR_TimerModeTimeCounter;
    lptmr_config.pinSelect = kLPTMR_PinSelectInput_0;
    lptmr_config.pinPolarity = kLPTMR_PinPolarityActiveHigh;
    lptmr_config.enableFreeRunning = true;
    lptmr_config.bypassPrescaler = true;
    lptmr_config.prescalerClockSource = kLPTMR_PrescalerClock_1; //1Khz - 1ms
    lptmr_config.value = kLPTMR_Prescale_Glitch_0;

    LPTMR_Init(LPTMR0, &lptmr_config);

    LPTMR_SetTimerPeriod(LPTMR0, 0xFFFF);

    LPTMR_EnableInterrupts(LPTMR0, kLPTMR_TimerInterruptEnable);


uint32_t LPTMR_GetCount(void)
	uint32_t count = LPTMR_GetCurrentTimerCount(LPTMR0);

	uint32_t total_ms = count + added_val;

	return total_ms;

void LPTMR0_IRQHandler(void)
    LPTMR_ClearStatusFlags(LPTMR0, kLPTMR_TimerCompareFlag);

    added_val += 0xFFFF;

    Workaround for TWR-KV58: because write buffer is enabled, adding
    memory barrier instructions to make sure clearing interrupt flag completed
    before go out ISR


   time_stamp = LPTMR_GetCount();
   if (time_stamp >= t1)
       t1 = time_stamp + PERIOD_1;
       GPIO_PortToggle(LED_PORT, (1<<LEDR_PIN));

LED красиво мигает... до первого прерывания. и все.

поначалу я подумал что прерывание отсыхает. поставил брекпоинт на added_val += 0xFFFF; вижу на каждое прерывание на added_val апдейтируется правильно.

поставил брекпоинт  на uint32_t count = LPTMR_GetCurrentTimerCount(LPTMR0); вижу  count  не апдейтируется.

LPTMR_GetCurrentTimerCount тоже хитромудрая функция

static inline uint32_t LPTMR_GetCurrentTimerCount(LPTMR_Type *base)
    /* Must first write any value to the CNR. This synchronizes and registers the current value
     * of the CNR into a temporary register which can then be read
    base->CNR = 0U;
    return (uint32_t)((base->CNR & LPTMR_CNR_COUNTER_MASK) >> LPTMR_CNR_COUNTER_SHIFT);

Вобщем непонятно как то с этим таймером.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this