Fan speed signal measure

cancel
Showing results for 
Search instead for 
Did you mean: 

Fan speed signal measure

48 Views
DavidChang0
Contributor I

-------------------------------------

3-Wire Fan speed monitor (Tacho signal measurement) 

-------------------------------------
#include <stdio.h>
#include "board.h"
#include "peripherals.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "MIMXRT1052.h"
#include "fsl_debug_console.h"
#include "fsl_qtmr.h"
/* TODO: insert other include files here. */

/* TODO: insert other definitions and declarations here. */
#define QTMR_BASEADDR TMR3
#define QTMR_INPUT_CAPTURE_CHANNEL kQTMR_Channel_0
#define QTMR_Counter_InputPIn kQTMR_Counter0InputPin

#define QTMR_IRQ_ID TMR3_IRQn
#define QTMR_IRQhandler TMR3_IRQHandler

#define QTMR_PRIMARY_SOURCE (kQTMR_ClockDivide_64)
#define QTMR_CLOCK_SOURCE_DIVIDER (64U)

#define QTMR_SOURCE_CLOCK (CLOCK_GetFreq(kCLOCK_IpgClk) / QTMR_CLOCK_SOURCE_DIVIDER)

 

volatile bool qtmrIsrFlag = false;


void QTMR_IRQhandler(void)
{
QTMR_ClearStatusFlags(TMR3, kQTMR_Channel_0, kQTMR_EdgeFlag);
qtmrIsrFlag = true;
__DSB();
}
/*
* @brief Application entry point.
*/
int main(void) {
qtmr_config_t qtmrConfig;
uint32_t timeCapt = 0;
uint32_t count = 0;
uint32_t tacho_freq = 0;
uint32_t RPM =0;

/* Init board hardware. */
BOARD_ConfigMPU();
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitBootPeripherals();
#ifndef BOARD_INIT_DEBUG_CONSOLE_PERIPHERAL
/* Init FSL debug console. */
BOARD_InitDebugConsole();
#endif

QTMR_GetDefaultConfig(&qtmrConfig);

qtmrConfig.primarySource = QTMR_PRIMARY_SOURCE;

QTMR_Init(TMR3, kQTMR_Channel_0, &qtmrConfig);

QTMR_SetupInputCapture(TMR3, kQTMR_Channel_0, kQTMR_Counter0InputPin, false, true,
kQTMR_RisingEdge);

EnableIRQ(QTMR_IRQ_ID);

QTMR_EnableInterrupts(TMR3, kQTMR_Channel_0, kQTMR_EdgeInterruptEnable);


QTMR_StartTimer(TMR3, kQTMR_Channel_0, kQTMR_PriSrcRiseEdge);


/* Check whether occur interrupt and wait the capture frequency stable */
while (count<5 || timeCapt == 0)
{
while (!(qtmrIsrFlag))
{
}
qtmrIsrFlag = false;
count++;
timeCapt=TMR3->CHANNEL[kQTMR_Channel_0].CAPT;
}

while(1)
{
timeCapt=TMR3->CHANNEL[kQTMR_Channel_0].CAPT;
PRINTF("\r\ntimeCapt=%d\n",timeCapt);
PRINTF("\r\ntacho_freq=%d Hz\n", tacho_freq = QTMR_SOURCE_CLOCK/timeCapt);
PRINTF("\r\nFAN_SPEED=%d RPM\n", RPM = tacho_freq*60/2);
SDK_DelayAtLeastUs(1000000, SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY);
}

}
// With this code i can measure the external signal from signal generator. Even when i change the input signal frequency from signal generator, firmware can detect the updated signal frequency//

But the issue is when i connect the tacho signal form the fan, firmware can't measure the tacho signal anymore. It shows some gurabge value. How to solve this issue??Please help.

Thanks in advance.

Regard's

David

 

Labels (1)
0 Kudos
1 Reply

39 Views
victorjimenez
NXP TechSupport
NXP TechSupport

Hello, 

The code looks fine, otherwise, it wouldn't work with the signal generator either. So, it seems that the problem is with the fan signal. How does this signal look in an oscilloscope? Can you measure the frequency of the fan signal with an oscilloscope? If so, what happens if you generate this frequency with the signal generator? Are you able to measure it? What is the voltage of the fan signal? 

Regards,
Victor 

0 Kudos