<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Frequency measurement with hardware interrupt handler]]></title><description><![CDATA[<p dir="auto"><strong>Hi there!</strong></p>
<p dir="auto">I need to measure frequency output of a flow meter 0-1000Hz.<br />
(Core2, Pin GPIO27)<br />
I have setup some code in UIFlow and defined IRQ and handler in "Execute Code" block.<br />
Reading works but very unstable (Jumps between 300..1000).<br />
Probably I need to run the handler in IRAM?<br />
Where/ how can I put the IRAM_ATTR?</p>
<p dir="auto">My execute code block:<br />
*def event_interrupt(pin0):<br />
global counter, semaphore<br />
if Semaphore:<br />
counter+=1</p>
<p dir="auto">pin0.irq(trigger=machine.Pin.IRQ_FALLING,<br />
handler= event_interrupt)*</p>
<p dir="auto">Thanks a lot!<br />
<img src="/assets/uploads/files/1630190349395-2021-08-29-00_38_29-m5flow-resized.png" alt="0_1630190352278_2021-08-29 00_38_29-M5Flow.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://community.m5stack.com/topic/3550/frequency-measurement-with-hardware-interrupt-handler</link><generator>RSS for Node</generator><lastBuildDate>Wed, 29 Apr 2026 01:19:33 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/3550.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 28 Aug 2021 22:40:58 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Frequency measurement with hardware interrupt handler on Fri, 18 Feb 2022 03:20:53 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/amani" aria-label="Profile: Amani">@<bdi>Amani</bdi></a> , I also need to measure frequency using an M5 Stack Core 2. I was looking at your code and wondering if you ever solved this problem? I see that you're using a counter that's incremented in an interrupt handler. How do you get the frequency from that?</p>
<p dir="auto">The way I understand Micro Python interrupts is that they're soft and give you jitter of some milliseconds, like over 2. Because the M5 Stack UIFlow runs on top of Micro Python, it does not seem likely that interrupts with adequate resolution are possible. You'll be lucky to measure a 500Hz signal.</p>
<p dir="auto">But I'm very interested to hear if you came up with a solution.</p>
<p dir="auto">I'm planning to solve this problem with a frequency to voltage converter. TI makes a low voltage part, LM331. The output is a voltage proportional to frequency that can be input to an ADC pin. Here's a link to the datasheet, <a href="https://www.ti.com/lit/ds/symlink/lm331.pdf" target="_blank" rel="noopener noreferrer nofollow ugc">https://www.ti.com/lit/ds/symlink/lm331.pdf</a></p>
<p dir="auto">I don't see another way to solve this problem using an M5 Stack. I'm hoping you found one that you can tell me about.</p>
<p dir="auto">Thanks</p>
]]></description><link>https://community.m5stack.com/post/16698</link><guid isPermaLink="true">https://community.m5stack.com/post/16698</guid><dc:creator><![CDATA[stanely]]></dc:creator><pubDate>Fri, 18 Feb 2022 03:20:53 GMT</pubDate></item><item><title><![CDATA[Reply to Frequency measurement with hardware interrupt handler on Mon, 27 Sep 2021 21:23:40 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ajb2k3" aria-label="Profile: ajb2k3">@<bdi>ajb2k3</bdi></a> : thanks for clarification. I really only used "play" button 😬<br />
So after donloading and booting directly from Core2 it performed better.<br />
But after I reintroduced temperature sensor reading (i2c) it was again very unstable.<br />
To me it looks like there is not really interrupt driven counting activated...<br />
(If I e.g. load the frequency measurement only and only update LCD w/o delay the frequency reading is totally off (too small count). With some delay it is better. But with some more workload it is not reliable that way?...</p>
]]></description><link>https://community.m5stack.com/post/15007</link><guid isPermaLink="true">https://community.m5stack.com/post/15007</guid><dc:creator><![CDATA[Amani]]></dc:creator><pubDate>Mon, 27 Sep 2021 21:23:40 GMT</pubDate></item><item><title><![CDATA[Reply to Frequency measurement with hardware interrupt handler on Fri, 24 Sep 2021 19:03:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/amani" aria-label="Profile: amani">@<bdi>amani</bdi></a> He means did you save it to the Core2 so that it loads when the core2 powers up and not just press the &gt; button.<br />
Have you looked under the Hardwares&gt;pin menu and tried with these blocks?<img src="/assets/uploads/files/1632510224962-screenshot-2021-09-24-at-20.03.25.png" alt="0_1632510223551_Screenshot 2021-09-24 at 20.03.25.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://community.m5stack.com/post/14971</link><guid isPermaLink="true">https://community.m5stack.com/post/14971</guid><dc:creator><![CDATA[ajb2k3]]></dc:creator><pubDate>Fri, 24 Sep 2021 19:03:50 GMT</pubDate></item><item><title><![CDATA[Reply to Frequency measurement with hardware interrupt handler on Fri, 24 Sep 2021 11:09:14 GMT]]></title><description><![CDATA[<p dir="auto">Somewhere I read that it's possible to use the "button" element to get interrupt: but how to link GPIO to the button?</p>
]]></description><link>https://community.m5stack.com/post/14960</link><guid isPermaLink="true">https://community.m5stack.com/post/14960</guid><dc:creator><![CDATA[Amani]]></dc:creator><pubDate>Fri, 24 Sep 2021 11:09:14 GMT</pubDate></item><item><title><![CDATA[Reply to Frequency measurement with hardware interrupt handler on Tue, 21 Sep 2021 14:03:24 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/iamliubo" aria-label="Profile: iamliubo">@<bdi>iamliubo</bdi></a><br />
Yes, I ran it on Core2.<br />
It measures frequency but very unstable.<br />
I meanwhile found that it's better if I introduce a wait loop. Looks like writing to the display consumes too much time.<br />
But I think there should be a possibility to use iram. It shouldn't happen that such a relatively "slow" signal can be missed?...</p>
]]></description><link>https://community.m5stack.com/post/14917</link><guid isPermaLink="true">https://community.m5stack.com/post/14917</guid><dc:creator><![CDATA[Amani]]></dc:creator><pubDate>Tue, 21 Sep 2021 14:03:24 GMT</pubDate></item><item><title><![CDATA[Reply to Frequency measurement with hardware interrupt handler on Mon, 06 Sep 2021 02:45:31 GMT]]></title><description><![CDATA[<p dir="auto">Hi <a class="plugin-mentions-user plugin-mentions-a" href="/user/amani4791" aria-label="Profile: amani4791">@<bdi>amani4791</bdi></a> ,<br />
Did you try download to device and run it?</p>
]]></description><link>https://community.m5stack.com/post/14812</link><guid isPermaLink="true">https://community.m5stack.com/post/14812</guid><dc:creator><![CDATA[IAMLIUBO]]></dc:creator><pubDate>Mon, 06 Sep 2021 02:45:31 GMT</pubDate></item><item><title><![CDATA[Reply to Frequency measurement with hardware interrupt handler on Fri, 03 Sep 2021 09:26:07 GMT]]></title><description><![CDATA[<p dir="auto">Anybody, anyhow?</p>
]]></description><link>https://community.m5stack.com/post/14794</link><guid isPermaLink="true">https://community.m5stack.com/post/14794</guid><dc:creator><![CDATA[Amani]]></dc:creator><pubDate>Fri, 03 Sep 2021 09:26:07 GMT</pubDate></item></channel></rss>