Parallel Port - how to invert PWM value

  • rodw
  • rodw's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
19 Jul 2026 09:15 #347838 by rodw
 
I decided to build a parallel port LinuxCNC config cos I'd never done one before. All went very easily after firing up stepconf which got motors moving straight out of the box.

But now I got problems with the PWM to control the spindle because the volts were running the wrong way eg 24000 rpm = 0 volts and 0 rpm = 10 volts. I thought it would be easy to invert the signal but to  no avail.

I tried to adjust with a sum2 component so -24000 + Commanded RPM = - desired RPM. This turned out to be a dry gully too.
I figured if I had to  convert it to an absolute number I could do that but halshow promptly showed me that -24000 + 12000 = 0
I got rid of the negative and used a gain of -1 and I still got the same wrong answer...

So what is the trick to invert the PWM value?

Please Log in or Create an account to join the conversation.

  • rodw
  • rodw's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
19 Jul 2026 09:56 #347839 by rodw
Replied by rodw on topic Parallel Port - how to invert PWM value
Hmm, this might work
parport.<p>.pin-<n>-out-invert 

Please Log in or Create an account to join the conversation.

  • tommylight
  • tommylight's Avatar
  • Away
  • Moderator
  • Moderator
More
19 Jul 2026 18:16 #347844 by tommylight
Replied by tommylight on topic Parallel Port - how to invert PWM value
Some examples of PWM stuff:
loadrt pwmgen output_type=1
addf pwmgen.make-pulses base-thread
addf pwmgen.update servo-thread
net dout-00 <=  pwmgen.0.pwm
setp pwmgen.0.pwm-freq 1000.0
setp pwmgen.0.scale 6.0
setp pwmgen.0.offset 0.2
setp pwmgen.0.dither-pwm true

net dout-00         => parport.0.pin-02-out
Probably more there, but usually all you need is frequency and scale, sometimes also offset.

Please Log in or Create an account to join the conversation.

  • rodw
  • rodw's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
19 Jul 2026 20:47 #347850 by rodw
Replied by rodw on topic Parallel Port - how to invert PWM value
I answered my own question by reading the docs!
setp parport.0.pin-01-out-invert 1
Is exactly what I needed, I went looking for -not pins with no joy and never thought to look at parameters

Please Log in or Create an account to join the conversation.

  • tommylight
  • tommylight's Avatar
  • Away
  • Moderator
  • Moderator
More
19 Jul 2026 22:44 #347852 by tommylight
Replied by tommylight on topic Parallel Port - how to invert PWM value

Hmm, this might work
parport.<p>.pin-<n>-out-invert 

That is why i did not mention it, as that is exactly what you needed.
-
Welcome to the parport club, i bought 3 old PC's with parallel ports (a Pentium 4 and two of Core 2) for 40 euro about 5 days back, and no matter how much fanfare goes on here from time to time about it being obsolete, i still love it as it works perfectly...for nearly 20 years without a single hiccup ever.
And also keep a stock of 2-4 at all times in the shop, so now should be 6...as one went off yesterday to it's new work place.

Please Log in or Create an account to join the conversation.

More
20 Jul 2026 16:00 #347877 by PCW
Replied by PCW on topic Parallel Port - how to invert PWM value
"-not" works for inputs, but not outputs
(without some fairly micky-mouse logic)
The following user(s) said Thank You: tommylight

Please Log in or Create an account to join the conversation.

  • Todd Zuercher
  • Todd Zuercher's Avatar
  • Away
  • Platinum Member
  • Platinum Member
More
20 Jul 2026 19:11 - 20 Jul 2026 19:12 #347887 by Todd Zuercher
Replied by Todd Zuercher on topic Parallel Port - how to invert PWM value
Wouldn't the proper way to invert a PWM be to use a negative value for the PWM scale? (setp pwmgen.N.scale = negative value)
Last edit: 20 Jul 2026 19:12 by Todd Zuercher.

Please Log in or Create an account to join the conversation.

More
20 Jul 2026 21:10 #347891 by PCW
Replied by PCW on topic Parallel Port - how to invert PWM value
If you had signed PWM hardware and you got minus full scale
instead of full scale with a full scale positive PWM value, then  yes,
inverting the PWM scale would fix the problem.

For unsigned PWM when 0% duty cycle PWM gives you full scale output
and 100% duty cycle gives you 0% output, you would need to digitally invert
the PWM pin (and this is the situation here AFAICT)
 

Please Log in or Create an account to join the conversation.

  • rodw
  • rodw's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
21 Jul 2026 07:16 - 21 Jul 2026 07:17 #347907 by rodw
Replied by rodw on topic Parallel Port - how to invert PWM value

Wouldn't the proper way to invert a PWM be to use a negative value for the PWM scale? (setp pwmgen.N.scale = negative value)


I thought this too. But I was wrong!

For unsigned PWM when 0% duty cycle PWM gives you full scale output
and 100% duty cycle gives you 0% output, you would need to digitally invert
the PWM pin (and this is the situation here AFAICT)


Peter has it right. You need to use the parameter for the pin to invert it

setp parport.0.pin-01-out-invert 1
Last edit: 21 Jul 2026 07:17 by rodw.

Please Log in or Create an account to join the conversation.

Time to create page: 0.138 seconds
Powered by Kunena Forum