User Tools

Site Tools


en-us_commands:reference:ianalogwrite2f

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
en-us_commands:reference:ianalogwrite2f [2026/09/08 00:53] – 바깥 편집 127.0.0.1en-us_commands:reference:ianalogwrite2f [2026/09/14 20:30] (current) – external edit 127.0.0.1
Line 14: Line 14:
  
 ===== Example ===== ===== Example =====
 +
 +Connect a Y output module to MPAINO-8A8R(T) and select **Analog Output Module → Y**. Set the CH0 DIP switch to OFF and measure the 4–20mA output at ''I+'' and ''−''.
  
 <code cpp> <code cpp>
-void setup() { +void setup() {}
-  Serial.begin(115200); +
-}+
  
 void loop() { void loop() {
-  uint16_t raw2 = analogRead2(0);  // Read the 4–20mA-adjusted input value of the specified channel. +  IanalogWrite2f(0, 0.0F100.0F, 25.0F);  // Scale 25% to the 4–20mA range and output about 8mA.
-  int32_t filtered2 = analogRead2Avg(0, 5);  // Return the integer average of 4–20mA input values. +
-  float filtered2f = analogRead2Avgf(0, 5);  // Return the floating-point average of 4–20mA input values. +
-  float currentmA = IanalogRead2f(04.0F, 20.0F);  // Map the 4–20mA input value to the specified floating-point range+
- +
-  if (raw2 == ANALOG_READ2_ERROR || filtered2 == ANALOG_READ2_AVG_ERROR || +
-      filtered2f == (float)ANALOG_READ2_AVG_ERROR || +
-      currentmA == (float)ANALOG_READ2_ERROR) { +
-    Serial.println("4-20mA input error"); +
-    delay(500); +
-    return; +
-  } +
- +
-  int32_t percent = Iscale((int32_t)raw2, 0, 32767, 0, 100);  // Map an integer input to the specified integer range. +
- +
-  IanalogWrite2(0, 0, 100, 50);       // 50% → approx. 12mA +
-  IanalogWrite2f(1, 0.0F, 10.0F, 2.5F); // 25% → approx. 8mA +
- +
-  Serial.print("4-20mA raw: "); +
-  Serial.println(raw2); +
-  Serial.print("4-20mA filtered: "); +
-  Serial.println(filtered2); +
-  Serial.print("4-20mA filtered float: "); +
-  Serial.println(filtered2f, 2); +
-  Serial.print("percent: "); +
-  Serial.println(percent); +
-  Serial.print("current: "); +
-  Serial.println(currentmA, 2); +
   delay(500);   delay(500);
 } }
Line 56: Line 28:
 ===== Precautions ===== ===== Precautions =====
  
-  * Set the module DIP switches and wiring for 0~20mA current I/O.+  * Set the MPAINO Y module CH0 DIP switch to OFF and connect the 4–20mA output to ''I+'' and ''−''.
   * An input of approximately 3.6~4.0mA returns the normal value ''0''; inputs below 3.6mA return an error value.   * An input of approximately 3.6~4.0mA returns the normal value ''0''; inputs below 3.6mA return an error value.
   * Error values help detect open circuits. The user must implement final alarms and safety actions in the program.   * Error values help detect open circuits. The user must implement final alarms and safety actions in the program.
en-us_commands/reference/ianalogwrite2f.1788796397.txt.gz · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki