Measurement of a ADIO Pin frequency

 Question

I have a Sensor that provides the values as a frequency. There is a PIN that toggles LOW and HIGH in a certain frequency. This frequency represents the value. If I connect this PIN to an ADIO Pin input of the Dolphin, how to measure a frequency of this ADIO Pin?

 Instructions

This can be done with the Dolphin. There are more approaches:

Have a constant time and measure how many ticks happened during this period

  • This approach is less accurate.

  • It recommended to measure with it frequencies from 0 up to 1000 Hz.

  • Ticks counting is realized in software.

Before starting developing please consider this restrictions:

  1. the scheduler must be off – the scheduler gets called every 1 ms. This would massively devalue your measurement.

  2. the Radio RX must be off – if the radio interrupt gets called when a telegram is received. This would massively devalue your measurement.

  3. the UART RX must be turned off – receiving UART bytes also cases major devalue of your measurements.

You need to configure the API, please perform this steps:

  1. Select a ADIO PIN for the measurements

  2. Configure the API trough DolphinStudio.

  3. Select the PIN

  4. Select either the callback is executed by falling or rising edge

Configure the timer1 as a counter. Set your period. (16 MHz clock, 1 tick = 62.5 ns)

The measurement is performed in these steps:

Prepare the timer1. Set and enable call back function. For details see the DolphinAPI Manual, Modules -> timer1 -> TIMER1 functions

timer1_initCB timer1_enableCB

Initialize and start the external call back 0 or 1. Depends on the ADIO Pin you have selected. For details see the DolphinAPI Manual, Modules -> IO -> IO functions

io_ADIO03initCB io_ADIO03enableCB or io_ADIO47initCB io_ADIO47enableCB

In the callback function of the external interrupt at the first callback start the timer1 using:

timer1_enable

In all further callback interrupts do only count the tick off your Pin (every interrupt is one tick, so you just have to increment a counter)

In the callback function of the timer1 interrupt disable the external interrupt – stop counting the ticks and disable the timer1 counter and interrupt.

Since we know exactly how long the timer1 period lasts we count the frequency based on the ticks we have counted in the external interrupt during one period of timer1. You can use this formula:

To have a accurate result you can repeat the measurements several times and take the average result frequency.

During the measurements your main application can have a while loop and exit it based on the

function. Either exit when the counter value you specified in DolphinStudio was reached or it stopped changing – the interrupted stopped the timer1 counter.

 

 Related Products

  • DolphinAPI