AnsweredAssumed Answered

BF518 Timer WDTH_CAP mode problem

Question asked by BlueIceScream on Feb 12, 2014
Latest reply on Apr 1, 2014 by CraigG

Hi.

 

I'm trying to get period of square signalon one of tmr pins. Original signal frequency is 1kHz. But on the output (after measuring) i have also 2*F, Fsclk/2, Fsclk/3 frequencies. (5-10 wrong values from 1000 right values). The code that i use:

 

 

[code]

#include "FrequencyDetector.h"

#include <stdio.h>

 

#define FD_STARTED 0

#define FD_IN_PROGRESS 1

#define FD_FINISHED 2

 

ADI_TMR_RESULT result;

 

u32 ticks;

u32 FDState;

u32 fsclk;

 

ADI_TMR_GP_CMD_VALUE_PAIR Timer0ConfigurationTable [] = {

          { ADI_TMR_GP_CMD_SET_TIMER_MODE,                              (void *)0x02 },// WDTH_CAP

          { ADI_TMR_GP_CMD_SET_PULSE_HI,                                        (void *)FALSE },// High Edge

          { ADI_TMR_GP_CMD_SET_INPUT_SELECT,                              (void *)FALSE},// TMRx Pins

          { ADI_TMR_GP_CMD_SET_CLOCK_SELECT,                              (void *)FALSE},// SCLK

          { ADI_TMR_GP_CMD_SET_COUNT_METHOD,                              (void *)TRUE },

          { ADI_TMR_GP_CMD_SET_INTERRUPT_ENABLE,                    (void *)TRUE },

          { ADI_TMR_GP_CMD_END,                                                            NULL                     },

};

 

ADI_PORTS_DIRECTIVE Timer0PortConfig[] = {

          ADI_PORTS_DIRECTIVE_TMR0_MUX2

};

 

ADI_TMR_RESULT frequencyDetectorInit(u32 freq)

{

          fsclk = freq;

 

          if (result = adi_tmr_Open(ADI_TMR_GP_TIMER_0)) return result;

 

          adi_tmr_GPControl(ADI_TMR_GP_TIMER_0,

                                                  ADI_TMR_GP_CMD_TABLE, Timer0ConfigurationTable);

 

          if (result = adi_tmr_InstallCallback(ADI_TMR_GP_TIMER_0,

                                                  TRUE,(void *)0,NULL,

                                                  frequencyDetectorCallback)) return result;

 

          adi_ports_Configure(Timer0PortConfig,1);

 

          return ADI_TMR_RESULT_SUCCESS;

}

 

ADI_TMR_RESULT frequencyDetectorStart()

{

          FDState = FD_STARTED;

          return adi_tmr_GPGroupEnable(ADI_TMR_GP_TIMER_0, TRUE);

}

 

ADI_TMR_RESULT frequencyDetectorStop()

{

          FDState = FD_FINISHED;

          return adi_tmr_GPGroupEnable(ADI_TMR_GP_TIMER_0, FALSE);

}

 

static void frequencyDetectorCallback(void *AppHandle, u32 Event, void *pArg)

{

          if ((u32)pArg !=  ADI_TMR_GP_TIMER_0) return;

 

          if (FDState == FD_IN_PROGRESS) {

                    frequencyDetectorStop();

                    adi_tmr_GPControl(ADI_TMR_GP_TIMER_0, ADI_TMR_GP_CMD_GET_PERIOD, &ticks);

          }

          else FDState = FD_IN_PROGRESS;

}

 

float frequencyDetectorValue()

{

          if (!ticks) return -1;

          return float(fsclk) / (float(ticks));

}

 

// this is function that i called

float frequencyDetectorSingleShot()

{

          frequencyDetectorStart();

          while (FDState!=FD_FINISHED);

          return frequencyDetectorValue();

}

 

[/code]

Attachments

Outcomes