News:

  • May 06, 2026, 12:41:05 AM

Login with username, password and session length

Author Topic: Clamp analog output?  (Read 19986 times)

Tark

  • Jr. Member
  • **
  • Posts: 16
Clamp analog output?
« on: December 17, 2015, 11:41:36 AM »
I'm using an F2-02DA-2, do I need to clamp the WYn value to make sure it doesn't go over 4095?  Reason I'm asking is because my logic could try to write a value higher than 4095 to WYn because the SCALE instruction.  What happens if a value greater than 4095 is written to Wyn?

plcnut

  • Hero Member
  • *****
  • Posts: 814
    • premiersi.com
Re: Clamp analog output?
« Reply #1 on: December 17, 2015, 06:32:01 PM »
I do not know of any issues with going above the modules range. If you are concerned, then a simple MATH box would fix it:
MATH:
Result: WY0
Expression: If(WY0>4095,4095,WY0)

EDIT: Fixed the WY0. (Thanks Mike)
« Last Edit: December 18, 2015, 06:58:18 PM by plcnut »
Circumstances don't determine who we are, they only reveal it.

~Jason Wolthuis
Premier Systems Integration, LLC
http://premiersi.com

Mike Nash

  • Hero Member
  • *****
  • Posts: 652
Re: Clamp analog output?
« Reply #2 on: December 18, 2015, 06:52:16 PM »
You should definitely clamp the value before putting it in WY0, etc. The simulator shows WY0 gets whatever you send it, but if you are sending it a value greater than 32767 it gets interpreted as two's complement negative. Above 65535 it throws away the bits above that and starts over. Play in the simulator to see this.

I like the CLAMP instruction simply because it is clean and neat and handles upper and lower limits.

BTW, plcnut's example should be showing WY0 as opposed to WX0

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3607
  • Darth Ladder
Re: Clamp analog output?
« Reply #3 on: December 18, 2015, 10:32:12 PM »
Or just AND it with 4095 to mask off any potential excess bits.  Probably quicker than the IIF.
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

Mike Nash

  • Hero Member
  • *****
  • Posts: 652
Re: Clamp analog output?
« Reply #4 on: December 19, 2015, 10:05:12 AM »
Or just AND it with 4095 to mask off any potential excess bits.  Probably quicker than the IIF.

Hmm,
Math
Result WY0
Expression D10 & 4095

If D10 = -12, then WY0 = 4084

I still like CLAMP as it handles squirrelly values in a nicely refined manner when changing between data types.

Tark

  • Jr. Member
  • **
  • Posts: 16
Re: Clamp analog output?
« Reply #5 on: December 19, 2015, 11:58:05 AM »
So the answer is, Yes you need to make sure the value does not go over 4095, else you'll have unexpected results.  After I tested it I said, Duh of course.  The F2-02DA-2 is a 12-bit analog output card hence,  4095 = 0000_1111_1111_1111 and 4096 = 0001_0000_0000_0000, if you write 4096 to the output card it's output value will go to 4mA.  Any value greater than 4095 will yield unexpected results.

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6154
  • Yes Pinky, Do-more will control the world!
Re: Clamp analog output?
« Reply #6 on: December 19, 2015, 12:41:15 PM »
I don't think the driver layer is clamping, although it is possible. We tend to keep driver code lean for performance considerations. I'll check it when I'm back near the code. CLAMP will definitely work perfectly, since that's exactly what it's for. ;)
"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

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3607
  • Darth Ladder
Re: Clamp analog output?
« Reply #7 on: December 19, 2015, 10:34:54 PM »
If D10 = -12, then WY0 = 4084


Hmmm....good point!  If your data can go negative, masking's not going to work well.
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6154
  • Yes Pinky, Do-more will control the world!
Re: Clamp analog output?
« Reply #8 on: December 20, 2015, 11:54:36 AM »
N bits of precision plus 2's complement yields multiple considerations. Not hard, but must be accounted for.
"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

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3607
  • Darth Ladder
Re: Clamp analog output?
« Reply #9 on: December 20, 2015, 02:09:14 PM »
In the SLC era, AB's analog modules were typically 12-bit, but they still spread it over a 15-bit integer range, 0-32767, so they were using the most significant 12 bits.  I always preferred that over the ADC way of using 4095.

Newer AB systems like the CLX and some other brands offer quite a few choices in range config, such as percent, what they call "engineering units" but actually refers to the electrical EU at the terminal (V, ma, mv, whatever) and not the actual process EU, and so on.

Back in the hoary old PLC5 days, the analogs were even scalable to true process EU in the module, which was kind of cool, at least some of them; I don't know if all the modules were.

Anyway, this thread started me thinking that analog range customization might be a nice thing to consider building into future Do-More analog if you haven't already.  It seems to be fairly widespread these days.
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6154
  • Yes Pinky, Do-more will control the world!
Re: Clamp analog output?
« Reply #10 on: December 20, 2015, 02:52:40 PM »
New hardware will have scaling integrated into the channel, which can be configured from raw counts or electrical values. Clamping is also an option, and works on both inputs and outputs. We were also planning to have electrical values be an optional channel (re)format in status displays, but the opinion of some was that it isn't helpful (after scaling) and might be confusing. Such concerns have rarely stopped us from feature creeping things to death, so we'll see what falls out in the end.

I was a proponent of left justifying values to 16 or 32 bits to dissociate bits of resolution from channel range, but that didn't compute for many, so...
"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

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3607
  • Darth Ladder
Re: Clamp analog output?
« Reply #11 on: December 20, 2015, 03:00:14 PM »
New hardware will have scaling integrated into the channel, which can be configured from raw counts or electrical values. Clamping is also an option, and works on both inputs and outputs. We were also planning to have electrical values be an optional channel (re)format in status displays, but the opinion of some was that it isn't helpful (after scaling) and might be confusing. Such concerns have rarely stopped us from feature creeping things to death, so we'll see what falls out in the end.

Cool -- looks like that gives me all the options I ever need.  Thanks!

Quote
I was a proponent of left justifying values to 16 or 32 bits to dissociate bits of resolution from channel range, but that didn't compute for many, so...

Hmmm....that's too bad (and surprising, IMO)
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3607
  • Darth Ladder
Re: Clamp analog output?
« Reply #12 on: December 20, 2015, 03:04:17 PM »
If there's EU scaling built it, I assume then then EU is what will be displayed in native mode for a channel so configured, or will there be a new display format for that?

(I took what you said in your post about no EU display format to refer to literal, terminal electrical EU as a display format, and I agree, I don't care much about that.  It doesn't seem to be to be any more useful than any other non-process-EU display, such as 0-32767 raw or 0-20000 raw)  Not that those modes aren't used or useful, but the ones that already exist are adequate, no use adding another one if it doesn't give you anything new.
« Last Edit: December 20, 2015, 03:06:14 PM by Controls Guy »
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6154
  • Yes Pinky, Do-more will control the world!
Re: Clamp analog output?
« Reply #13 on: December 20, 2015, 03:15:50 PM »
When you configure the scale, you can specify the "raw" value in counts or electrical units (v or ma as appropriate). The scale is actually targeting a new memory type (scale memory) that corresponds to the raw channel, i.e., WXn scales to RXn and RYn scales to WYn. The raw channel input/output will still be present in WX/WY and the EU will be in RX/RY. Because the relationship is known, we are going to try to make it easy to get whatever part you want from whatever part you have, wherever you want it. Since electrical units are present, we also liked the idea of being able to point at a channel and get the current volts or milliamps too, but that may or may not not happen.

Clear as mud?
"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

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3607
  • Darth Ladder
Re: Clamp analog output?
« Reply #14 on: December 20, 2015, 03:18:41 PM »
When you configure the scale, you can specify the "raw" value in counts or electrical units (v or ma as appropriate). The scale is actually targeting a new memory type (scale memory) that corresponds to the raw channel, i.e., WXn scales to RXn and RYn scales to WYn. The raw channel input/output will still be present in WX/WY and the EU will be in RX/RY. Because the relationship is known, we are going to try to make it easy to get whatever part you want from whatever part you have, wherever you want it. Since electrical units are present, we also liked the idea of being able to point at a channel and get the current volts or milliamps too, but that may or may not not happen.

Clear as mud?

Definitely understandable (and a cool approach)!
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.