News:

  • May 14, 2026, 07:17:57 PM

Login with username, password and session length

Author Topic: PWM INPUT  (Read 15957 times)

Garyhlucas

  • Hero Member
  • *****
  • Posts: 421
PWM INPUT
« on: September 08, 2022, 01:47:02 PM »
I see we have PWM OUT on the BRX but not in.  We have some ClearPath servos that can output torque via PWM which I suspect they did that way because they made it bidirectional.  We need this for a project.  Suggestion on how to read this?  I am thinking two high speed inputs used as timers and then compared to get percentage range.

Thanks,

Bolt

  • Hero Member
  • *****
  • Posts: 598
Re: PWM INPUT
« Reply #1 on: September 08, 2022, 04:00:48 PM »
Can you use a High Speed Edge Timer (or Counter) along with the attached Interval Scaling?

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6156
  • Yes Pinky, Do-more will control the world!
Re: PWM INPUT
« Reply #2 on: September 08, 2022, 06:38:20 PM »
If the PWM period is known and fixed, you can do it with a single HS timer and a small bit of math. It If isn't, you can do it with two timers, one rising to falling and one rising to rising, and then use some math to convert to percentage.

That's actually how I tested the PWM function.  ;)
« Last Edit: September 08, 2022, 09:55:52 PM by BobO »
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

Garyhlucas

  • Hero Member
  • *****
  • Posts: 421
Re: PWM INPUT
« Reply #3 on: September 08, 2022, 09:05:26 PM »
Yes the period is known and fixed so I?ll try the single timer because I need them for other stuff too.

Thanks,

Garyhlucas

  • Hero Member
  • *****
  • Posts: 421
Re: PWM INPUT
« Reply #4 on: September 09, 2022, 09:19:31 PM »
Single timer works!

SceneryDriver

  • Jr. Member
  • **
  • Posts: 15
Re: PWM INPUT
« Reply #5 on: January 29, 2026, 06:52:44 PM »
BobO
At the risk of resurrecting a zombie thread from four years ago, any chance someone can share a code snippet?  I'm just not seeing how to use a single timer.  I too have to monitor torque on a Teknic servo.  Alternatively, a dedicated PWMIN instruction would be very helpful.

The servo can provide a PWM signal at either 45Hz or 482Hz (user selectable):

5% duty cycle = 100% peak torque, CW direction
50% duty cycle = zero torque
95% duty cycle = 100% peak torque CCW direction.



Thanks,

SceneryDriver

Garyhlucas

  • Hero Member
  • *****
  • Posts: 421
Re: PWM INPUT
« Reply #6 on: January 30, 2026, 10:35:31 PM »
If you contact me at gary@zaicdesign.com I'll share the code we use for this.

SceneryDriver

  • Jr. Member
  • **
  • Posts: 15
Re: PWM INPUT
« Reply #7 on: February 06, 2026, 10:17:01 PM »
If anyone sees this, I solved it - I'm always annoyed with threads that don't detail the solution.  I used a high-speed timer, set to dual-edge on same input.  It's measuring the time from the rising edge to the falling edge. Named $MotorTorque, and set to free-run.

The PWM signal from the Teknic servo has a known frequency of 45Hz.  To get the duty cycle, I use a MATH instruction:

($MotorTorque.LastTime / 22.22) / 10 = D0

This gives me a whole-number percentage of the duty cycle of the PWM signal.

I hope this helps someone!


SceneryDriver