Read Tacho signal using counter

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Read Tacho signal using counter

ソリューションへジャンプ
1,008件の閲覧回数
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 解決策
981件の閲覧回数
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 返答(返信)
944件の閲覧回数
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 件の賞賛
返信
865件の閲覧回数
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 件の賞賛
返信
982件の閲覧回数
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.