News:

  • June 25, 2026, 02:32:17 PM

Login with username, password and session length

Author Topic: PWM Output  (Read 10409 times)

PLCwannabe

  • Hero Member
  • *****
  • Posts: 208
PWM Output
« on: February 02, 2023, 08:57:48 AM »
I'd like to use a pwm output  to drive a c bit  50 -100 times per second, to simulate a process. I don't want to use the onboard relay outputs. The pwm device doesn't give me the option of using a c bit. Can this be done?

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3827
    • Host Engineering
Re: PWM Output
« Reply #1 on: February 02, 2023, 09:16:18 AM »
100 hz is on and off 10ms, so 5ms PLC scan time can do that.

A simple Timer set to half the period (e.g. 5ms) then have the T0.Done bit drive a PONOFF instruction to toggle the C bit.

If you need really accurate timing (I doubt it since this is not tied to real I/O), you could utilize a Timed Interrupt and an INTCONFIG instruction to tweak the timing programmatically.

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6161
  • Yes Pinky, Do-more will control the world!
Re: PWM Output
« Reply #2 on: February 02, 2023, 09:25:06 AM »
Or TPROPOUT maybe?
"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

PLCwannabe

  • Hero Member
  • *****
  • Posts: 208
Re: PWM Output
« Reply #3 on: February 02, 2023, 10:44:37 AM »
Pwm won't work cause I see now the Hz has to be a constant. Where can I find Tprop out?

What I want to do, is simulate a hopper unloading grain, using a pid loop to control the flow rate of the grain, and as the pid loop increases its output, I want that pid output to increase the pulses per second  I'm sending to my flow rate (pid.pv),. (Just for simulation)

 Basically i need to programmatically control the pulses per second I'm sending to my flowrate calculation, in a linear fashion. I have been doing like first reply, but it is totally non-linear.



On a side note, is there an instruction that can calculate flow rate,  not from a pulse input, but from a number that is dropping rapidly, like 100 units per second.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3827
    • Host Engineering
Re: PWM Output
« Reply #4 on: February 02, 2023, 11:05:15 AM »
Pwm won't work cause I see now the Hz has to be a constant. Where can I find Tprop out?
See TIMEPROP.  It's in the Analog/Process group in the Tool Box

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6161
  • Yes Pinky, Do-more will control the world!
Re: PWM Output
« Reply #5 on: February 02, 2023, 11:32:36 AM »
Sorry...the function that implements it in the engine is TPROPOUT, but yes, TIMEPROP is the correct name.
"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

PLCwannabe

  • Hero Member
  • *****
  • Posts: 208
Re: PWM Output
« Reply #6 on: February 02, 2023, 01:58:34 PM »
I'm going to rephrase my original question. I want to use a 0-10 vdc signal to control the number of pulses per second for an output.  eg. at 1.0v, output 10 pulses/second, at 10.0v, output  100 pulses/sec, and do this linearly across the 0-10v. TimeProp is not linear, and PMW output is not dynamically configurable. I don't care about the length of the pulses, I only need to change the frequency of the pulses on the fly.

Are there any other options?


Also this:
On a side note, is there an instruction that can calculate flow rate,  not from a pulse input, but from a number that is dropping rapidly, like 100 units per second. I've set up a math box to do this, but there has to be an instruction somewhere.

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6161
  • Yes Pinky, Do-more will control the world!
Re: PWM Output
« Reply #7 on: February 02, 2023, 02:06:43 PM »
I'm going to rephrase my original question. I want to use a 0-10 vdc signal to control the number of pulses per second for an output.  eg. at 1.0v, output 10 pulses/second, at 10.0v, output  100 pulses/sec, and do this linearly across the 0-10v. TimeProp is not linear, and PMW output is not dynamically configurable. I don't care about the length of the pulses, I only need to change the frequency of the pulses on the fly.

Are there any other options?


Also this:
On a side note, is there an instruction that can calculate flow rate,  not from a pulse input, but from a number that is dropping rapidly, like 100 units per second. I've set up a math box to do this, but there has to be an instruction somewhere.

TIMEPROP has a variable to control the period (inverse of frequency), which can be as linear as you need it to be. Use MATH or LERP to convert frequency to period then use the variable period value of TIMEPROP to drive the pulse train.

And the other instruction you are looking for is SLOPE.
"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

PLCwannabe

  • Hero Member
  • *****
  • Posts: 208
Re: PWM Output
« Reply #8 on: February 02, 2023, 02:42:39 PM »
Awesome. Just what I was looking for. Thanks.