This article applies to:
DolphinAPI
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?
This can be done with the Dolphin. There are more approaches:
Before starting developing please consider this restrictions:
You need to configure the API, please perform this steps:
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
void timer1_getTimerCounter
function. Either exit when the counter value you specified in DolphinStudio was reached or it stopped changing – the interrupted stopped the timer1 counter.
FAQ Single Template
Finden Sie den richtigen Händler für unsere Module, Komponenten und Endprodukte in Ihrer Region!
Der EnOcean-Newsletter informiert Sie regelmäßig über spannende Projekte aus den Bereichen IoT und Smart Building sowie über aktuelle Veranstaltungen und neue Produkte.
© 2024 EnOcean GmbH. Alle Rechte vorbehalten.