Read Tacho signal using counter

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Read Tacho signal using counter

跳至解决方案
866 次查看
vivekgourav
Contributor I

Hello Guys,

I am using LPC824 board and want to read tacho signals from one of the pins.I have problems with enabling the right interrupts and clearing the flags. Could you help me

#include "fsl_debug_console.h"

#include "pin_mux.h"

#include "board.h"

#include "fsl_gpio.h"

 

#include <stdbool.h>

#include <stdio.h>

 

/*******************************************************************************

* Definitions

******************************************************************************/

 

#define BOARD_LED_PORT 0U

#define BOARD_LED_PIN 12U

#define TACHO_PIN 17U

 

volatile uint32_t captureCounter = 0;

volatile bool captureEnabled = true;

 

/*******************************************************************************

* Code

******************************************************************************/

 

void GPIO_IRQHandler(void)

{

// Check if the interrupt is caused by TACHO_PIN rising edge

if (GPIO_PinRead(GPIO, 0, TACHO_PIN))

{

captureCounter++;

 

// Clear the interrupt flag

//GPIO_PortClearInterruptFlags(GPIO, 0, 1U << TACHO_PIN);

}

}

 

void delay(uint32_t ms)

{

uint32_t ticks = ms * (SystemCoreClock / 1000U);

while (ticks--)

{

__asm("nop");

}

}

 

int main(void)

{

/* Init board hardware */

BOARD_InitBootPins();

BOARD_InitBootClocks();

BOARD_InitDebugConsole();

 

/* Configure TACHO_PIN as an input with interrupt on rising edge */

gpio_pin_config_t pinConfig = {

kGPIO_DigitalInput,

0,

};

GPIO_PinInit(GPIO, 0, TACHO_PIN, &pinConfig);

 

// Enable the GPIO interrupt

NVIC_EnableIRQ(PIN_INT0_IRQn);

 

while (1)

{

// Capture for approximately 1 second

delay(1000000U);

 

// Disable GPIO interrupt

NVIC_DisableIRQ(PIN_INT0_IRQn);

 

// Print the frequency over the last second

PRINTF("\r\nFrequency (last second): %u Hz\r\n", captureCounter);

 

// Reset the capture counter for the next measurement

captureCounter = 0;

 

// Enable GPIO interrupt for the next measurement

NVIC_EnableIRQ(PIN_INT0_IRQn);

}

}

@nxp 

标签 (1)
0 项奖励
回复
1 解答
839 次查看
Miguel04
NXP TechSupport
NXP TechSupport

Hi @vivekgourav 

Under the LPC824max's SDK file you will find an example called lpcxpresso824max_pint_pin_interrupt, which shows how to use the PINT to make the pin interrupt events.

I hope this helps, let me know if you have a question.

Best Regards, Miguel.

在原帖中查看解决方案

3 回复数
802 次查看
vivekgourav
Contributor I

Hi, 

Thanks for your quick response. 
Also, On the LPC824, I wanted to use two timers, 1 timer for capturing PWM signal. and the other timer enables the pin interrupt at t second and disables at t+1 second. How to implement this

0 项奖励
回复
723 次查看
Miguel04
NXP TechSupport
NXP TechSupport

Hi @vivekgourav 

I recommend you to look into example lpcxpresso824max_sctimer_16bit_counter, it might help you with the PWM match routine.

I'm not understanding your second inquiry, "other timer enables the pin interrupt at t second and disables at t+1 second."

Usually the interrupts are configured and only called when the event occurs, there is no need to disable or enable it, can you provide more details about this implementation?

Best Regards, Miguel.

0 项奖励
回复
840 次查看
Miguel04
NXP TechSupport
NXP TechSupport

Hi @vivekgourav 

Under the LPC824max's SDK file you will find an example called lpcxpresso824max_pint_pin_interrupt, which shows how to use the PINT to make the pin interrupt events.

I hope this helps, let me know if you have a question.

Best Regards, Miguel.