Timer0 com duas interrupções LPC1768

Software e Hardware para linha ARM

Moderadores: 51, guest2003, Renie, gpenga

Timer0 com duas interrupções LPC1768

Mensagempor caetanowagner » 23 Ago 2011 08:33

Bom dia pessoal. Preciso de uma ajuda.Estou usando o CoIDE para fazer um projeto simples com uso de duas interrupções no Timer0 do LPC1768. Porém o programa executa somente uma das interrupções e não consegui encontrar o erro. Durante o debug observei que os bits que habilitam a interrupção (MR0 e MR1) estavam ativos, porém vi no registro que o bit de interrupção pendente (IR) somente uma delas ficava ativa. Interessante quando desabilitava a chamada de uma função que configura o timer, a outra funcionava perfeitamente. Alguém poderia me ajudar? Segue código abaixo:

#include "lpc_types.h"
#include "lpc17xx_clkpwr.h"
#include "lpc17xx_gpio.h"
#include "lpc17xx_libcfg_default.h"
#include "lpc17xx_nvic.h"
#include "lpc17xx_pinsel.h"
#include "lpc17xx_timer.h"

void TIMER0_IRQHandler (void);
uint8_t temp0 = 0, temp1 = 0;

/*
* @brief Timer 0 interrupt
* @param None.
* @return None.
*/

void Timer0_ch1_init()
{
TIM_TIMERCFG_Type TMR0_Cfg;
TIM_MATCHCFG_Type TMR0_Match;

/* On reset, Timer0/1 are enabled (PCTIM0/1 = 1), and Timer2/3 are disabled (PCTIM2/3 = 0).*/
/* Initialize timer 0, prescale count time of 100uS */
TMR0_Cfg.PrescaleOption = TIM_PRESCALE_USVAL;
TMR0_Cfg.PrescaleValue = 1000;
/* Use channel 0, MR0 */
TMR0_Match.MatchChannel = 1;
/* Enable interrupt when MR0 matches the value in TC register */
TMR0_Match.IntOnMatch = ENABLE;
/* Enable reset on MR0: TIMER will reset if MR0 matches it */
TMR0_Match.ResetOnMatch = TRUE;
/* Don't stop on MR0 if MR0 matches it*/
TMR0_Match.StopOnMatch = FALSE;
/* Do nothing for external output pin if match (see cmsis help, there are another options) */
TMR0_Match.ExtMatchOutputType = TIM_EXTMATCH_NOTHING;
/* Set Match value, count value of 500000 (500 * 1000uS = 500000us = 0,5s --> 0,5 Hz) */
TMR0_Match.MatchValue = 500;
/* Set configuration for Tim_config and Tim_MatchConfig */
TIM_Init(LPC_TIM0, TIM_TIMER_MODE, &TMR0_Cfg);
TIM_ConfigMatch(LPC_TIM0, &TMR0_Match);

/* Preemption = 1, sub-priority = 1 */
NVIC_SetPriority(TIMER0_IRQn, ((0x01<<3)|0x02));
/* Enable interrupt for timer 0 */
NVIC_EnableIRQ(TIMER0_IRQn);
/* Start timer 0 */
TIM_Cmd(LPC_TIM0, ENABLE);
}

void Timer0_ch0_init()
{
TIM_TIMERCFG_Type TMR0_Cfg;
TIM_MATCHCFG_Type TMR0_Match;

/* On reset, Timer0/1 are enabled (PCTIM0/1 = 1), and Timer2/3 are disabled (PCTIM2/3 = 0).*/
/* Initialize timer 0, prescale count time of 100uS */
TMR0_Cfg.PrescaleOption = TIM_PRESCALE_USVAL;
TMR0_Cfg.PrescaleValue = 1000;
/* Use channel 0, MR0 */
TMR0_Match.MatchChannel = 0;
/* Enable interrupt when MR0 matches the value in TC register */
TMR0_Match.IntOnMatch = ENABLE;
/* Enable reset on MR0: TIMER will reset if MR0 matches it */
TMR0_Match.ResetOnMatch = TRUE;
/* Don't stop on MR0 if MR0 matches it*/
TMR0_Match.StopOnMatch = FALSE;
/* Do nothing for external output pin if match (see cmsis help, there are another options) */
TMR0_Match.ExtMatchOutputType = TIM_EXTMATCH_NOTHING;
/* Set Match value, count value of 10000 (10000 * 100uS = 1000000us = 1s --> 1 Hz) */
TMR0_Match.MatchValue = 1000;
/* Set configuration for Tim_config and Tim_MatchConfig */
TIM_Init(LPC_TIM0, TIM_TIMER_MODE, &TMR0_Cfg);
TIM_ConfigMatch(LPC_TIM0, &TMR0_Match);

/* Preemption = 1, sub-priority = 1 */
NVIC_SetPriority(TIMER0_IRQn, ((0x01<<3)|0x01));
/* Enable interrupt for timer 0 */
NVIC_EnableIRQ(TIMER0_IRQn);
/* Start timer 0 */
TIM_Cmd(LPC_TIM0, ENABLE);
}

void TIMER0_IRQHandler (void)
{
if ((TIM_GetIntStatus(LPC_TIM0, TIM_MR1_INT))==SET){//executa esta ou a do MR0
/* Clear Interrupt */
TIM_ClearIntPending(LPC_TIM0,TIM_MR1_INT);
/* Code...*/
if(0 == temp1){
GPIO_SetValue(2, 0X02);
temp1 = 1;
}
else{
GPIO_ClearValue(2, 0X02);
temp1 = 0;
}
}

if ((TIM_GetIntStatus(LPC_TIM0, TIM_MR0_INT))==SET){//executa esta ou a do MR1
/* Clear Interrupt */
TIM_ClearIntPending(LPC_TIM0,TIM_MR0_INT);
/* Code...*/
if(0 == temp0){
GPIO_ClearValue(2, 0X01);
temp0 = 1;
}
else{
GPIO_SetValue(2, 0X01);
temp0 = 0;
}
}
}

int main(void)

{

//uint8_t temp0 = 0,temp1 = 1;

/* definition for led */
unsigned long LED_PINS = ((uint32_t)1<<0)|((uint32_t)1<<1)|((uint32_t)1<<2)|((uint32_t)1<<3)|((uint32_t)1<<4)|((uint32_t)1<<5)|((uint32_t)1<<6)|((uint32_t)1<<7);
/* LEDs on PORT2.2 defined as Output */
GPIO_SetDir(2, LED_PINS, 1);
GPIO_ClearValue(2, 0XFF);

Timer0_ch1_init();//Quando deixo comentado uma das duas
Timer0_ch0_init();//chamadas, a interrupção funciona normal
//para os dois canais

while(1)
{
}
}

Obrigado!!!!!!

Wagner
caetanowagner
 
Mensagens: 4
Registrado em: 11 Abr 2010 18:34

Voltar para ARM

Quem está online

Usuários navegando neste fórum: Nenhum usuário registrado e 1 visitante

x