Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

help for capture interrupt

2004-10-29 by dasbento@aeiou.pt

Anybody can help in the following situation:

in the main program I'm enable the capture interrupt and one cycle
while(1) where I can write for UART0 keyboard character.

Initially I write character of keyboard and work whith interrupt at
same time working fine, but past one little time the program no go to
back at cycle while(1), remaining in interrupt and then finish for
crash!!!

Now, the cycle while(1) run only while no happen one capture
interrupt. After it happen the capture interrupt run fine but no go to
back the cycle while(1) in function main().

I think that is problem with the stack!!!


How solve this problem???


Thanks!!!

Regards
       Domingos 





main()
.....
.....
.....
        captura_inicializa();
	captura_timer1_inicializa_cp0(1);
	captura_timer1_inicializa_cp1(1);

	escreve_UART0("Entrou no ciclo principal\n");
	while (1)
	{	
		int c;
		k++;
		
		
		delay(100000);
		escreve_UART0(".");
		c = uart0GetByte();
			if(c!=-1)
				uart0SendByte(c);
			
	}
......
......
......

#include "include/lpc2129.h"
#include "include/processor.h"
#include "include/uart.h"
#include "include/captura.h"

typedef void (*voidFuncPtr)(void);
volatile static voidFuncPtr TimerIntrFunc[TIMER_NUM_INTERRUPTS];
volatile u32 Timer1OverflowCount;


void delay(unsigned long d)
{     
	for(; d; --d)
	{
		asm volatile ("nop");
	}
}


void captura_inicializa(){
	u08 intNum;
	
	
	// detach all user functions from interrupts (limpa o vector das
funcoes associadas as int)
	for(intNum=0; intNum<TIMER_NUM_INTERRUPTS; intNum++)
		timerDetach(intNum);

	// initialize timer0
	//timer0Init();
	 //initialize timer1
	 captura_timer1_inicializa();
	 // enable interrupts
	enableIRQ();
	escreve_UART0("configurada timer 1\n");
	
}




void timerDetach(u08 interruptNum){

	// make sure the interrupt number is within bounds
	if(interruptNum < TIMER_NUM_INTERRUPTS){
		// set the interrupt function to run nothing
		TimerIntrFunc[interruptNum] = 0;
	}
}



void timer1PrescalerSet(u32 clockDiv){
	// timer1 increments every PR+1 cycles
	// subtract 1 so the argument is a true division ratio
	T1PR = clockDiv-1;
}

void captura_timer1_inicializa(void){
	// setup timer1
	// set prescaler
	timer1PrescalerSet(1);
	// reset timer
	T1TCR = TCR_RESET;
	delay(10);
	// start timer
	T1TCR = TCR_ENABLE;
	escreve_UART0("comeca a contar timer 1\n");
	// setup timer1 for IRQ
	// set interrupt as IRQ
	VICIntSelect &= ~(1<<VIC_TIMER1);
	// assign VIC slot
	VICVectCntl5 = VIC_ENABLE | VIC_TIMER1;
	VICVectAddr5 = (u32)captura;
	// enable interrupt
	VICIntEnable |= (1<<VIC_TIMER1);
}



void captura_timer1_inicializa_cp0(int on){
	// setup timer0 capture1
	if(on)
	{
		// pin select
		PINSEL0 &= ~(3<<20);	// clear pin select bits for P0.10 -> GPIO
		PINSEL0 |=  (2<<20);	// set pin select bits for P0.10 -> Capture1.0
		// enable timer1 interrupt on rising edge of CR0 capture
		T1CCR |= TCCR_CR0_I | TCCR_CR0_F;
		escreve_UART0("Activou o pino da captura no porto 0.10 captura 0
timer 1\n");
	}
	else
	{
		// pin select
		PINSEL0 &= ~(3<<20);	// clear pin select bits for P0.4 -> GPIO
		// disable timer0 interrupt on rising edge of CR1 capture
		T1CCR &= ~(TCCR_CR0_I | TCCR_CR0_F);
	}
}

void captura_timer1_inicializa_cp1(int on){
	// setup timer0 capture1
	if(on)
	{
		// pin select
		PINSEL0 &= ~(3<<22);	// clear pin select bits for P0.11 -> GPIO
		PINSEL0 |=  (2<<22);	// set pin select bits for P0.11 -> Capture1.1
		// enable timer1 interrupt on rising edge of CR0 capture
		T1CCR |= TCCR_CR1_I | TCCR_CR1_F;
		escreve_UART0("Activou o pino da captura no porto 0.11 captura 1
timer 1\n");
	}
	else
	{
		// pin select
		PINSEL0 &= ~(3<<22);	// clear pin select bits for P0.11 -> GPIO
		// disable timer0 interrupt on rising edge of CR1 capture
		T1CCR &= ~(TCCR_CR0_I | TCCR_CR0_F);
	}
}



void captura(void){
	ISR_ENTRY();
	char buffer[100]; 
	
	escreve_UART0("Entrou na (interrupcao )captura timer 1\n");
	if(T1IR & TIR_MR0I){
		// clear MR0 Interrupt
		T1IR |= TIR_MR0I;
		Timer1OverflowCount++;
		//uart0SendByte('k');
		//escreve_UART0(" overflow   ");
		// if a user function is defined, execute it
		//if(TimerIntrFunc[TIMER1MATCH0_INT])
		//	TimerIntrFunc[TIMER1MATCH0_INT]();
	}else if(T1IR & TIR_CR0I){
	
		T1IR |= TIR_CR0I;
		
		//sprintf(buffer,"o valor foi %ld", T1CR0);
		//escreve_UART0(buffer);
		
		
	}else if(T1IR & TIR_CR1I){
	
		T1IR |= TIR_CR1I;
		//if(TimerIntrFunc[TIMER1CAPTURE1_INT])
		//	TimerIntrFunc[TIMER1CAPTURE1_INT]();//
		//escreve_UART0(" flanco des cp1 ");
	}
	
	VICSoftIntClr = (1<<VIC_TIMER1);
	VICVectAddr = 0x00000000;             // clear this interrupt from
the VIC
	//escreve_UART0("SAiu na (interrupcao )captura timer 1\n");
	ISR_EXIT();                           // recover registers and return
}

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.