Counter for measurement of the frequency on G120

Hi all !
I want to use the counter for measurement of the frequency before 1MHz.
Prompt as this better do.

@ rpis - Look at SignalCapture class in the GHI.IO namespace documentation.

https://www.ghielectronics.com/downloads/man/Library_Documentation_v4.3/html/R_Project_NETMF_Libraries_API_Reference.htm

I test this method. result - measured frequency before 40 kHz only :frowning:
I use NETMF 4.2

This is an option
https://www.ghielectronics.com/catalog/product/465

I want use Register class for Timer/Counter from processor. But shall be able I measure frequency 1 MHZ ?

Then the datasheet of the processor is your best option. You can use the register class or RLP to access the processor directly.

I try RLP but why my code not work - interruption does not occur?


 #include "lpc17xx_timer.h"
 #include "lpc17xx_libcfg.h"
 #include "lpc17xx_pinsel.h"
 #include "RLP.h"

 #define STATUS_SUCCESS                0
 #define STATUS_ISR_INSTALL_FAILED    -1
 #define STATUS_OUT_OF_MEMORY        -2
 #define STATUS_MUST_WAIT            -3
 #define STATUS_INVALID_ARG_COUNT    -4
 #define STATUS_INVALID_FORMAT        -5

PINSEL_CFG_Type PinCfg;
TIM_TIMERCFG_Type TIM_ConfigStruct;
TIM_CAPTURECFG_Type TIM_CaptureConfigStruct;
uint32_t capture=0;
BOOL_8 IsrInstalled = FALSE;

void TimerIsr(void *arg)
{
   if (TIM_GetIntCaptureStatus(LPC_TIM2,0))
   {
        TIM_ClearIntCapturePending(LPC_TIM2,0);
  
        RLPext->PostManagedEvent(LPC_TIM2->CR0);

         capture = TIM_GetCaptureValue(LPC_TIM2,0);

         TIM_Cmd(LPC_TIM2,DISABLE);
         TIM_ResetCounter(LPC_TIM2);
         TIM_Cmd(LPC_TIM2,ENABLE);
   }
}

int InitMeasureFreq(void *generalArray, void **args, unsigned int argsCount, unsigned int *argSize)
{
    //Config P0.4 as CAP2.0
    PinCfg.Funcnum = 3;
    PinCfg.OpenDrain = 0;
    PinCfg.Pinmode = 0;
    PinCfg.Portnum = 0;
    PinCfg.Pinnum = 4;
    PINSEL_ConfigPin(&PinCfg);

    // Initialize timer2, prescale count time of 100000uS
    TIM_ConfigStruct.PrescaleOption = TIM_PRESCALE_USVAL;
    TIM_ConfigStruct.PrescaleValue   = 100000; //100mS

    // use channel 0, CAPn.0
    TIM_CaptureConfigStruct.CaptureChannel = 0;
    // Enable capture on CAPn.0 rising edge
    TIM_CaptureConfigStruct.RisingEdge = ENABLE;
    // Enable capture on CAPn.0 falling edge
    TIM_CaptureConfigStruct.FallingEdge = DISABLE;
    // Generate capture interrupt
    TIM_CaptureConfigStruct.IntOnCaption = ENABLE;

    // Set configuration for Tim_config and Tim_MatchConfig
    TIM_Init(LPC_TIM2,TIM_TIMER_MODE,&TIM_ConfigStruct);
    TIM_ConfigCapture(LPC_TIM2, &TIM_CaptureConfigStruct);
    TIM_ResetCounter(LPC_TIM2);

    // Hook our interrupt handlers
    if (!RLPext->Interrupt.Install(TIMER2_IRQn, TimerIsr, NULL)) return STATUS_ISR_INSTALL_FAILED;
    IsrInstalled = TRUE;

    // To start timer2
    TIM_Cmd(LPC_TIM2,ENABLE);

    RLPext->Interrupt.Enable(TIMER2_IRQn);

    RLPext->PostManagedEvent(111);
    return STATUS_SUCCESS;
}

int DeinitMeasureFreq(void *generalArray, void **args, unsigned int argsCount, unsigned int *argSize)
{
    if (IsrInstalled)
    {
        RLPext->Interrupt.Uninstall(TIMER2_IRQn);
        TIM_DeInit(LPC_TIM2);
        IsrInstalled = FALSE;
    }

    return STATUS_SUCCESS;
}

int QueryFreq(unsigned long *generalArray, void **args, unsigned int argsCount, unsigned int *argSize)
{
    RLPext->Interrupt.Disable(TIMER2_IRQn);
    generalArray[0] = capture;
    RLPext->Interrupt.Enable(TIMER2_IRQn);

    return STATUS_SUCCESS;
}


anyone can say where I mistaken?