Generating a square wave on Portenta machine control

Hi there,

I'm looking to generate a square wave (more like impulse train) of a given frequency ranging from 0-12kHz on the portenta machine control. It is running several Threads to poll sensors and push data to MQTT. This would be used as the STEP impulse of a servomotor.

I've used the tone() function on a uno in the past, which worked flawlessly for the application but doesn't on the machine control. I've also tried manual digitalWrites to the pin but the high-side switched digital outputs and the programmable I/O are both too slow it seems.

Is there any way to create a reliable square wave/impulse train on the portenta machine control, preferably running parallel to threads ?

Thanks.

To clarify, do you mean an impulse train or a square wave? The latter could be considered a pulse train with 1:1 mark/space ratio.

Hi there,

I guess an impulse train would be enough. A square wave was just easier to code on the Uno at the time. I don't know the minimum "on time" of the impulses required by the servo.

I guess a solution could be to use some kind of I2C-> PWM card if the machine control board is not capable of handling it ?

Both the programmable IO and normal digital outputs are wired to high-side drivers to produce a 24V signal (VCC).

If 3.3 V is enough for you, you might try to use the pins from the I2C Grove connector on the board.
Just an idea.

The I2C pins is not a good idea because it uses I2C3 which is also used for the i2c IO Expanders some it will have conflicts.

Hey there,

Thanks for you input, I didn't think about that !

As far as I know, the I/O expander is only used for the Programmable I/O ? If so I really don't need them for now. I don't see many other exposed pins unless I solder directly to the PI_6/PH-9 before the high side driver ?

I'd like to avoid that if possible considering I would need a mosfet to scale up to +5V at least. I think the easier reliable way might be to build a small I2C-> Square wave from a clock/function generator IC, a gate driver and switching MOS, it would offload the CPU quite a bit and allow me to scale up to 24V.

It's a shame there isn't a jumper to bypass the high-side switch considering how slow it is.

You could attempt to use the AccelStepper library. It doesn't use tone() or any pwm function, it simply switches the output on/off after the required time interval passes. I actually sent tech support an email about the speed of the DOs for the exact same reason, to drive a pulse train output. They responded saying that the switching time of the output is a few microseconds, but they wouldn't confirm if it would work for this application.

If what they say about the response time is true, then the Portenta Machine Control should be able to drive a stepper/servo drive with the AccelStepper library no problem. Here's a guide on how to set up the library for a stepper motor ( Using BIG Stepper Motors with Arduino | DroneBot Workshop). Search for AccelStepper on the page, it's toward the bottom.

Let me know if you have any success, I'm very interested. :+1:

Hey,

The switch is a TPS4H160-Q1. Typical delay after input is 50µs up to 90µs once the input is on, not counting the 0.3V/µs adding another 7.5µs to switch 24V. It is horribly slow.

I'm now using pin PH_8 from the I2C connector to switch an external mosfet. It is a horrendous solution as it messes with the Programmable IO on the I2C bus. This board effectively gets rid of what I'd use an arduino over a PLC for, fast switching times.

I couldn't find documentation to bypass the switch, but it's probably what I'll end up doing. This is far from a professional product. Dual core programming doesn't even work like it does on the portenta and it hasn't been fixed for over a year, the fix is 3 lines of code.

Build your own breakout and avoid the portenta until it gets the attention it deserves.

1 Like

That's sad. It looked like it could have been an excellent product. Thanks for the follow up

For anyone interested in this topic, I'm looking at using the Teknic ClearCore controller, it's programmed using C++ with optional Arduino IDE. It has four dedicated step/direction outputs along with the other generic I/O. I think I'm going to give it a shot.

https://teknic.com/products/io-motion-controller/clcr-4-13/

1 Like

See the thread on using library functions with Portenta Machine Control:

In this case, if you would like to output a tone on digital pin #2, you would simply use:

tone(PinNameToIndex(PJ_9), NOTE_A4, 1000);
noTone(PinNameToIndex(PJ_9));

Please read the thread. The I/Os are much too slow for anything of the sort due to the high side drivers.

Tone doesn't work either on the Portenta machine control, there are additionnal harmonics from god knows where when using both the M4 and M7 cores which destroys the usability of the output signal. For the price of the hardware and the "pro" marketing, you'd expect it not to be worse than an RP2040 with a 10 cent mosfet, but the sad reality is that it is.

1 Like

Agreed, the I/O indeed is too slow, and PMC documentation is practically non-existent.

I have just added my 2 cents on the digital outputs (not the I/O) for anyone stumbling accross the thread in the future. (Tone does work, for me BTW, the board is sitting on the bench, happily humming the imperial march)

Has anyone found a way to get around these slow I/O pins? It makes no sense to me how a PLC industrial grade board has no support to control stepper motors.