Frequency Meter Asynchronous Driver

In Frequency Meter (FREQM) asynchronous driver, a callback function can be registered in the driver by the application and triggered when measurement is done to let the application know the result.

Summary of the API's Functional Features

The API provides functions to:
  • Initialize and deinitialize the driver and associated hardware

  • Enable or disable Frequency Meter

  • Set measurement parameter (measure period, frequency or period measurement)

  • Hookup callback handlers on frequency measurement done

  • Start frequency measurement

Summary of Configuration Options

Below is a list of the main FREQM parameters that can be configured in START. Many of these parameters are used by the freqmeter_async_init function when initializing the driver and underlying hardware.
  • Clock to be measured

  • Reference clock

  • Number of reference clock cycles (measure period)

Driver Implementation Description

The driver uses a ring buffer to store the results of measurements. When the done interrupt is raised, the result is stored in the ring buffer at the next free location. When the ring buffer is full, the next sample will overwrite the oldest sample in the ring buffer.

To read the results from the ring buffer, the function freqmeter_async_read is used. This function reads the number of measurement results asked for from the ring buffer, starting from the oldest byte. If the number of bytes asked for are more than currently available in the ring buffer, the number of available bytes is read. The freqmeter_async_read function returns the actual number of bytes read from the buffer back to the caller. If the number of bytes asked for is less than the available bytes in the ring buffer, the remaining bytes will be kept until a new call to freqmeter_async_read or it's overwritten because the ring buffer is full.

Example of Usage

The following shows a simple example of using the FREQM. The FREQM must have been initialized by ac_async_init. This initialization will configure the operation of the FREQM, such as clock to be measured, reference clock, etc.

The example registers a callback function for measurement ready and enables FREQM, finally starts a frequency measurement.

          static void freqmeter_cb(const struct freqmeter_async_descriptor *const descr)
          {
              uint32_t value;
              freqmeter_async_read(&FREQUENCY_METER_0, &value, 1);
              freqmeter_async_start(&FREQUENCY_METER_0);
          }
          void FREQUENCY_METER_0_example(void)
          {
              freqmeter_async_register_callback(&FREQUENCY_METER_0, FREQMETER_ASYNC_MEASUREMENT_DONE, freqmeter_cb);
              freqmeter_async_enable(&FREQUENCY_METER_0);
              freqmeter_async_start(&FREQUENCY_METER_0);
          }
        

Dependencies

  • FREQM peripheral and its related I/O lines and clocks

  • NVIC must be configured so that FREQM interrupt requests are periodically serviced.