User Tools

Site Tools


en-us_commands:reference:analogread2avg

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:analogread2avg [2026/09/08 00:53] – 바깥 편집 127.0.0.1en-us_commands:reference:analogread2avg [2026/09/14 20:30] (current) – external edit 127.0.0.1
Line 14: Line 14:
  
 ===== Example ===== ===== Example =====
 +
 +Connect an X input module to MPAINO-8A8R(T) and select **Analog Input Module → X**. Set CH0 DIP switches 20mA and GND to ON, then connect the 4–20mA signal.
  
 <code cpp> <code cpp>
Line 21: Line 23:
  
 void loop() { void loop() {
-  uint16_t raw2 = analogRead2(0);  // Read the 4–20mA-adjusted input value of the specified channel. +  const int32_t value = analogRead2Avg(0, 5);  // Read the integer moving average of up to five recent valid values. 
-  int32_t filtered2 = analogRead2Avg(0, 5);  // Return the integer average of 4–20mA input values. +  if (value == ANALOG_READ2_AVG_ERROR) { 
-  float filtered2f = analogRead2Avgf(0, 5);  // Return the floating-point average of 4–20mA input values. +    Serial.println(F("4-20mA input error")); 
-  float currentmA = IanalogRead2f(0, 4.0F, 20.0F);  // Map the 4–20mA input value to the specified floating-point range. +  } else { 
- +    Serial.println(value);
-  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 35:
 ===== Precautions ===== ===== Precautions =====
  
-  * Set the module DIP switches and wiring for 0~20mA current I/O.+  * Set the MPAINO X module CH0 DIP switches 20mA and GND to ON, and wire the current input with the correct polarity.
   * 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/analogread2avg.1788796395.txt.gz · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki