# Counting Hall Sensor Pulses on Portenta Machine Control

**URL:** <https://forum.arduino.cc/t/counting-hall-sensor-pulses-on-portenta-machine-control/1412737>\
**Category:** Portenta Machine Control\
**Created:** [November 6, 2025, 4:28pm UTC](https://forum.arduino.cc/t/counting-hall-sensor-pulses-on-portenta-machine-control/1412737 "2025-11-06T16:28:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![julien8](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/julien8/32/1128987_2.png) [@julien8](https://forum.arduino.cc/u/julien8)\
**Post date:** [November 6, 2025, 4:28pm UTC](https://forum.arduino.cc/t/counting-hall-sensor-pulses-on-portenta-machine-control/1412737/1 "2025-11-06T16:28:13Z")

</div>

Hey everyone,

I am trying to handle two linear actuators using the Portenta Machine Control.

Regarding the driving of the motors, I am using two external drivers and had no issues setting that up. _ **However,** _ my two actuators are equipped with Hall effect sensors (one sensor in each actuator) that I would like to use to precisely synchronize and position them.

When one actuator is at maximum speed, its sensor is generating a **~40Hz pulse signal** which is not that fast. One pulse is 0.1mm of displacement.

My goal is therefore to count these pulses with the PMC. I have been trying multiple options but the best "semi-solution" I have found as of today is to use the **attachInterrupt()** method.  
Looking at the board pinout, I only found two of the Portenta H7 pins that can be used on the PMC for this : **PI\_5, and PB\_4.**

This solution is unfortunately far from ideal, as these two pins are used for the whole Programmable Digital I/O and Digital Inputs expanders. Not only that, but their behaviours differ when counting the pulses leading to different counts (The PI\_5 count seems to be the correct one. I don't have an explanation for that yet).

Here is the code that I have been using for this:

```arduino
#include <Arduino_PortentaMachineControl.h>

volatile unsigned long pulseCount = 0;
int trigDelay = 15; // Set to filter noise
unsigned long lastStepTime = 0;

void setup() {
  Serial.begin(115200);
  while (!Serial)
    ;

  Wire.begin();
  attachInterrupt(PI_5, countPulse, FALLING); // PB_4 also works but behaves differently ? Pulses count does not match.
}

void loop() {
  static unsigned long lastPrint = 0;
  if (millis() - lastPrint > 100) {
    lastPrint = millis();
    Serial.println(pulseCount);
  }
}

void countPulse() {
  if (millis() - lastStepTime > trigDelay) {
    pulseCount++;
    lastStepTime = millis();
  }
}

```

- The encoder pins of the PMC are expecting a quadrature signal. Sending a single pulse signal, in let's say A0 pin, wouldn't work properly for my application. Still, I was wondering if the encoder pins were interrupt capable, and if yes, how to use them ? I have tried using the attachInterrupt() method with pins: PJ\_8, PH\_12, PH\_11 but the board becomes unresponsive when doing so.

- Would you have any other solution or method that I could look into for the PMC ?

I would like to avoid my last resort that would be to use a separate UNO to count the pulses on pin 2 and 3 and send the variables to the PMC !

Thanks in advance,  
Julien

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2026, 4:29pm UTC](https://forum.arduino.cc/t/counting-hall-sensor-pulses-on-portenta-machine-control/1412737/2 "2026-05-05T16:29:10Z")

</div>

Closed on May 5, 2026, 4:29pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
