<?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[How to measure AC Line frequency using Lopy??]]></title><description><![CDATA[<p dir="auto">I like to measure the AC line frequency using Lopy module. I am using optocoupler to convert 50Hz AC signal into a 50Hz pulse. Is there any builtin function (like PulseIn, micros as Arduino) by which i can do that. Please need expert advise to solve the problem.</p>
]]></description><link>https://forum.pycom.io/topic/3430/how-to-measure-ac-line-frequency-using-lopy</link><generator>RSS for Node</generator><lastBuildDate>Mon, 20 Apr 2026 18:37:38 GMT</lastBuildDate><atom:link href="https://forum.pycom.io/topic/3430.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 03 Jul 2018 04:06:43 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to measure AC Line frequency using Lopy?? on Tue, 03 Jul 2018 04:06:43 GMT]]></title><description><![CDATA[<p dir="auto">I like to measure the AC line frequency using Lopy module. I am using optocoupler to convert 50Hz AC signal into a 50Hz pulse. Is there any builtin function (like PulseIn, micros as Arduino) by which i can do that. Please need expert advise to solve the problem.</p>
]]></description><link>https://forum.pycom.io/post/20592</link><guid isPermaLink="true">https://forum.pycom.io/post/20592</guid><dc:creator><![CDATA[mahmud021]]></dc:creator><pubDate>Tue, 03 Jul 2018 04:06:43 GMT</pubDate></item><item><title><![CDATA[Reply to How to measure AC Line frequency using Lopy?? on Tue, 03 Jul 2018 06:23:17 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.pycom.io/uid/1496">@mahmud021</a> Off the top of my head there are two ways you could approach it.</p>
<p dir="auto">Have a look at RMT <a href="https://docs.pycom.io/chapter/tutorials/all/rmt.html" target="_blank" rel="noopener noreferrer nofollow">https://docs.pycom.io/chapter/tutorials/all/rmt.html</a>  allows you to send/receive pulses.  - i haven't tried this.</p>
<p dir="auto">Alternately is used pin iterrupts to measure RPM (hall effect) this would be accurate for RPM, but I doubt it would be for AC Freq</p>
<p dir="auto">anyway</p>
<pre><code>class RPM:
    
    def __init__(self, pin):
        self._pin = Pin(pin,mode=Pin.IN)
        self._intvl = 0
        self._pin.callback(Pin.IRQ_RISING,handler=self._callback,arg=self)
        self._timer = Timer.Chrono()
        self._timer.start()

    def _callback(self,obj):
        self._intvl = self._timer.read_ms()
        self._timer.reset()   

    def rpm(self):
        return 60000 / self._intvl 
</code></pre>
<p dir="auto">I can simulate the RPM within reason by using PWM output on one of the other PINS.<br />
That was accurate enough for my needs.</p>
]]></description><link>https://forum.pycom.io/post/20594</link><guid isPermaLink="true">https://forum.pycom.io/post/20594</guid><dc:creator><![CDATA[timh]]></dc:creator><pubDate>Tue, 03 Jul 2018 06:23:17 GMT</pubDate></item><item><title><![CDATA[Reply to How to measure AC Line frequency using Lopy?? on Tue, 03 Jul 2018 07:07:15 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.pycom.io/uid/1496">@mahmud021</a> I assume that rmt is the best approach you can get. ISR's have a pretty varying latency. The longest pulse you can get with rmt is ~18ms. At 50Hz, the high/low pulses are ~10ms, if the trigger point is symmetric. If you for a a longer period, the accuracy you can get is pretty well.</p>
]]></description><link>https://forum.pycom.io/post/20595</link><guid isPermaLink="true">https://forum.pycom.io/post/20595</guid><dc:creator><![CDATA[robert-hh]]></dc:creator><pubDate>Tue, 03 Jul 2018 07:07:15 GMT</pubDate></item><item><title><![CDATA[Reply to How to measure AC Line frequency using Lopy?? on Sun, 08 Jul 2018 06:24:23 GMT]]></title><description><![CDATA[<p dir="auto">Can you suggest me a working code. I have tried some , but still no luck..</p>
]]></description><link>https://forum.pycom.io/post/20702</link><guid isPermaLink="true">https://forum.pycom.io/post/20702</guid><dc:creator><![CDATA[mahmud021]]></dc:creator><pubDate>Sun, 08 Jul 2018 06:24:23 GMT</pubDate></item><item><title><![CDATA[Reply to How to measure AC Line frequency using Lopy?? on Sun, 15 Jul 2018 10:09:29 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.pycom.io/uid/1496">@mahmud021</a> At least I can confirm, that get_pulses() does not work as specified, or as I read it. It requites a timeout at the input to return, instead of returning after x pulses.<br />
I'll glance into the sources.</p>
]]></description><link>https://forum.pycom.io/post/20882</link><guid isPermaLink="true">https://forum.pycom.io/post/20882</guid><dc:creator><![CDATA[robert-hh]]></dc:creator><pubDate>Sun, 15 Jul 2018 10:09:29 GMT</pubDate></item><item><title><![CDATA[Reply to How to measure AC Line frequency using Lopy?? on Sun, 15 Jul 2018 12:26:32 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.pycom.io/uid/1496">@mahmud021</a> The sources are strange, at least. get_pulses() will not finish until it gets a timeout, and with AC Lines that should not happen. And even if, it will then always return 128 pulses and not the specified number. But, i found a trick, shown in the sample script below. Before I run get_pulses(), I start a timer which will reconfigure the Pin after a while, and doing this force a timeout for get_pulses(). Nasty style, and you should not feed the signal to your device with a low impedance. So add a guard resistor into the line, like 1kOhm.</p>
<pre><code>from machine import RMT, Timer, Pin
def kill_rmt(x):
    pin = Pin(&quot;P10&quot;,mode=Pin.OUT)
    pin(0)

def run():
    alarm = Timer.Alarm(kill_rmt, 2, periodic=False)
    rmt = RMT(channel=4)
    rmt.init(gpio=&quot;P10&quot;, rx_idle_threshold=20000)

    data = rmt.pulses_get()
    sum = 0
    for _ in data[2:]:
        print(_[0], _[1])
        sum += _[1]
    print(sum, len(data), ((len(data) - 2) * 1.e6)/sum/2)

run()
</code></pre>
<p dir="auto">The question then is, how precise you want to get the result. Obviously it is limited by two factors:</p>
<ul>
<li>the precision of the xxPy clock. If its deviation is more or less stable, you can compensate</li>
<li>the length of the pulses_get sequence. You can take 63 periods. At 50Hz this is 1.260 s. And so the error is about 10E-6.</li>
</ul>
<p dir="auto">In my test set-up here with a waveform generator set to 50Hz the script returns something like 50.0002x Hz. But I do not know the error of either component.</p>
]]></description><link>https://forum.pycom.io/post/20884</link><guid isPermaLink="true">https://forum.pycom.io/post/20884</guid><dc:creator><![CDATA[robert-hh]]></dc:creator><pubDate>Sun, 15 Jul 2018 12:26:32 GMT</pubDate></item><item><title><![CDATA[Reply to How to measure AC Line frequency using Lopy?? on Wed, 18 Jul 2018 08:14:37 GMT]]></title><description><![CDATA[<p dir="auto">If the wareform <a href="http://www.dieselgeneratortech.com/generator-set/" target="_blank" rel="noopener noreferrer nofollow">generator set</a> to 50HZ,  how can the scrip get returns</p>
]]></description><link>https://forum.pycom.io/post/20939</link><guid isPermaLink="true">https://forum.pycom.io/post/20939</guid><dc:creator><![CDATA[VancleVector]]></dc:creator><pubDate>Wed, 18 Jul 2018 08:14:37 GMT</pubDate></item><item><title><![CDATA[Reply to How to measure AC Line frequency using Lopy?? on Wed, 18 Jul 2018 08:23:22 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.pycom.io/uid/2948">@vanclevector</a> I do not know how you interface the diesel generator to you xxPy device. At leat the AC generated by the unit must be transformed to a clean 3.3 V square wave signal. I understood that this part is done. Do you have a schematic of the interface circuit of a oscilloscope dump of the signal the gets out of that?</p>
]]></description><link>https://forum.pycom.io/post/20941</link><guid isPermaLink="true">https://forum.pycom.io/post/20941</guid><dc:creator><![CDATA[robert-hh]]></dc:creator><pubDate>Wed, 18 Jul 2018 08:23:22 GMT</pubDate></item></channel></rss>