Measuering an external signal of 100Hz generated by signal generator by imxrt1050 evkb

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Measuering an external signal of 100Hz generated by signal generator by imxrt1050 evkb

Jump to solution
708 Views
DavidChang0
Contributor I

With the following code i want to measure 100 Hz external signal generated by signal generator.But i am getting the following value- After calculation i don't get exact time period of external signal. Can anyone tell me where i have done mistake or suggest me the corection of code please. 

***********************

timeCapt=18708

cnt_val1=18708

cnt_val2=46875

cnt_diff=28167

*****************************
/* 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_32)

 

volatile bool qtmrIsrFlag = false;

uint32_t counter = 0;
uint32_t cnt_val1= 0;
uint32_t cnt_val2= 0;
uint32_t cnt_diff= 0;

void QTMR_IRQhandler(void)
{
QTMR_ClearStatusFlags(TMR3, kQTMR_Channel_0, kQTMR_EdgeFlag);
qtmrIsrFlag = true;

counter++;
if(counter==1){
cnt_val1= TMR3->CHANNEL[kQTMR_Channel_0].CAPT;
}
else if(counter>=2){
cnt_val2= TMR3->CHANNEL[kQTMR_Channel_0].CAPT;

if(cnt_val2>cnt_val1)
{
cnt_diff=cnt_val2-cnt_val1;
}
else if(cnt_val2<cnt_val1)
{
cnt_diff= ((0xFFFF-cnt_val1)+cnt_val2)+1 ;
}
counter = 0;
}

__DSB();
}
/*
* @brief Application entry point.
*/
int main(void) {
qtmr_config_t qtmrConfig;
uint32_t timeCapt = 0;
uint32_t count = 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;
}

 

PRINTF("\r\ntimeCapt=%d\n",timeCapt);
PRINTF("\r\ncnt_val1=%d\n",cnt_val1);
PRINTF("\r\ncnt_val2=%d\n",cnt_val2);
PRINTF("\r\ncnt_diff=%d\n",cnt_diff);

while(1)
{
}

}

 

***********************

timeCapt=18708

cnt_val1=18708

cnt_val2=46875

cnt_diff=28167

*****************************

#define QTMR_PRIMARY_SOURCE (kQTMR_ClockDivide_32)

Is this kQTMR_ClockDivide_32 is prescaling 150 Mhz ipg_clock?

Please suggest me the proper way to capture or measure the frequency of an external signal?Please help.

Regard's

David

0 Kudos
1 Solution
694 Views
victorjimenez
NXP TechSupport
NXP TechSupport

Hello David, 

This might be due to the frequency of the source clock for the QTMR. Since the frequency you are trying to measure is very low, you will need to speed down the source clock of the QTMR. Please, make these tests on your end and let me know the results. 

Regards,
Victor 

View solution in original post

0 Kudos
2 Replies
695 Views
victorjimenez
NXP TechSupport
NXP TechSupport

Hello David, 

This might be due to the frequency of the source clock for the QTMR. Since the frequency you are trying to measure is very low, you will need to speed down the source clock of the QTMR. Please, make these tests on your end and let me know the results. 

Regards,
Victor 

0 Kudos
680 Views
DavidChang0
Contributor I

Hello Victor,

Thank you for your guidance. Now i can measure the external signal. But i have one confusion about how to continaously measure the external signal as in my case signal frequency will change time to time.

 

Regard's

David

0 Kudos