Counting Hall Sensor Pulses on Portenta Machine Control

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:

#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

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