Altera_Forum
Honored Contributor
14 years agoNEEK II GPIO edge trigger interrupt problem
HI, i had a problem about the NEEK ii GPIO with external interrupt. The program together with the result was show as below:
The purpose of this program was used to measure the time between a input pulse. The input pulse was generated by the frequency generator and connect it directly to one of the GPIO pin. I'm using edge trigger to capture the raising edge, but i fail to get the actual time between the pulses. Can anyone tell me is the program problem or it cause by the noise of input pulse?#include <stdio.h>
# include "system.h"
# include "alt_types.h"
# include "sys/alt_irq.h"
# include "altera_avalon_pio_regs.h"
# include "includes.h"
# include "sys/alt_timestamp.h"
INT32U start = 0;
INT32U stop = 0;
//global
BOOLEAN first_capture = 0;
BOOLEAN test = 0;
INT32U rpm_measurement_finish = 0;
INT32U rpm_measurement_start = 0;
float rpm_total_time = 0.0;
INT32U rpm_total_tick = 0;
INT8U check = 1;
/* A variable to hold the value of the button pio edge capture register. */
volatile int edge_capture;
/* button IRQ function */
static void handle_button_interrupts(void* context, alt_u32 id)
{
if(!first_capture)
{
alt_timestamp_start();
rpm_measurement_start = alt_timestamp();
first_capture = 1;
}else
{
alt_ic_irq_disable(GPIO_IN_IRQ_INTERRUPT_CONTROLLER_ID, GPIO_IN_IRQ);
rpm_measurement_finish = alt_timestamp();
rpm_total_tick = rpm_measurement_finish - rpm_measurement_start;
rpm_total_time = ((float)(rpm_measurement_finish - rpm_measurement_start))/60000000;
test = 1;
first_capture = 0;
}
IOWR_ALTERA_AVALON_PIO_EDGE_CAP(GPIO_IN_BASE, 0);
}
/* Initialize the button_pio. */
static void init_button_pio()
{
void* edge_capture_ptr = (void*) &edge_capture;
/* Enable all 4 button interrupts. */
IOWR_ALTERA_AVALON_PIO_IRQ_MASK(GPIO_IN_BASE, 0x1);
/* Reset the edge capture register. */
IOWR_ALTERA_AVALON_PIO_EDGE_CAP(GPIO_IN_BASE, 0);
/* Register the interrupt handler. */
alt_irq_register( GPIO_IN_IRQ, edge_capture_ptr, handle_button_interrupts );
}
int main()
{
printf("Testing measurement\n\n");
init_button_pio();
while (1){
if(test)
{
test = 0;
printf("total tick: %lu\n", rpm_total_tick);
printf("total rpm time: %10.9f\n", rpm_total_time);
printf("rpm start : %lu\n", rpm_measurement_start);
printf("rpm finish : %lu\n\n", rpm_measurement_finish);
usleep(1000000);
alt_ic_irq_enable(GPIO_IN_IRQ_INTERRUPT_CONTROLLER_ID, GPIO_IN_IRQ);
}
}
return 0;
}
here is the input pulse http://www.alteraforum.com/forum/attachment.php?attachmentid=5168&stc=1&d=1323263961 Hope anyone here can let me know whats going on. Thanks.