bassplayer142
Newbie level 5
Hi everyone. I'm trying to determine the frequency of a incoming signal at roughly 7KHz. This signal is correctly identified using a scope and is at correct logic levels. I am using the 16bit Tachometer digital block which adds a second interrupt. It is basically a 16 bit timer with the added interrupt. I have a 1MHz input clock which should get me enough resolution for this. The incoming frequency is fed into the capture port on the block. Now I'm having trouble getting a frequency measurement. Here is some of my code.
I am getting the decimal value of 2222 for "diff" which stays consistent with the frequency at 7.3KHz but can't seem to figure out how to get this value in frequency form. I have searched hours for this and haven't gotten much of anywhere. Any help is greatly appreciated.
Code:
void main(void)
{
LCD_1_Start(); // Initialize LCD hardware
TachTimer16_1_WritePeriod(0xFFFF);
M8C_DisableGInt;
TachTimer16_1_Stop();
TachTimer16_1_EnableInt();
TachTimer16_1_Start();
M8C_EnableGInt;
while(1){
LCD_1_Position(0,0);
lcd_int(diff,5);
freq = (0.000001)*(0x10000-diff);
delay();
TachTimer16_1_WritePeriod(0xFFFF);
TachTimer16_1_Start();
delay();
}
Code:
void MyCounterISRLSB(void) //capture interrupt
{
to = TachTimer16_1_wReadTimer();
if (to < tf) diff = tf-to;//(0xFFFF-tf)+to;
else diff = ((0xFFFF-tf)+to);
tf = to;
TachTimer16_1_Stop();
}
I am getting the decimal value of 2222 for "diff" which stays consistent with the frequency at 7.3KHz but can't seem to figure out how to get this value in frequency form. I have searched hours for this and haven't gotten much of anywhere. Any help is greatly appreciated.