Frequency measurement with hardware interrupt handler

  • Hi there!

    I need to measure frequency output of a flow meter 0-1000Hz.
    (Core2, Pin GPIO27)
    I have setup some code in UIFlow and defined IRQ and handler in "Execute Code" block.
    Reading works but very unstable (Jumps between 300..1000).
    Probably I need to run the handler in IRAM?
    Where/ how can I put the IRAM_ATTR?

    My execute code block:
    *def event_interrupt(pin0):
    global counter, semaphore
    if Semaphore:

    handler= event_interrupt)*

    Thanks a lot!
    0_1630190352278_2021-08-29 00_38_29-M5Flow.png

  • Anybody, anyhow?

  • Hi @amani4791 ,
    Did you try download to device and run it?

  • @iamliubo
    Yes, I ran it on Core2.
    It measures frequency but very unstable.
    I meanwhile found that it's better if I introduce a wait loop. Looks like writing to the display consumes too much time.
    But I think there should be a possibility to use iram. It shouldn't happen that such a relatively "slow" signal can be missed?...

  • Somewhere I read that it's possible to use the "button" element to get interrupt: but how to link GPIO to the button?

  • @amani He means did you save it to the Core2 so that it loads when the core2 powers up and not just press the > button.
    Have you looked under the Hardwares>pin menu and tried with these blocks?0_1632510223551_Screenshot 2021-09-24 at 20.03.25.png

  • @ajb2k3 : thanks for clarification. I really only used "play" button 😬
    So after donloading and booting directly from Core2 it performed better.
    But after I reintroduced temperature sensor reading (i2c) it was again very unstable.
    To me it looks like there is not really interrupt driven counting activated...
    (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?...