Browsed by
Etiqueta: Analog write

Write Analog Outputs Ardbox/MDuino

Write Analog Outputs Ardbox/MDuino

Analog Outputs (0-10Vdc / 8 bits): 

Ardbox

  • Analog: Q0.3, Q0.4, Q0.5, Q0.6, Q0.7, Q0.8, Q0.9 (configurable Analog)
  • Relay:  Q0.0, Q0.1 (Analog).

M-Duino

  • M-Duino 21: Q0.5, Q0.6  Q0.7  (configurable Analog).
  • M-Duino 42: Q0.5, Q0.6  Q0.7, Q1.5, Q1.6  Q1.7 (configurable Analog).
  • M-Duino 58: Q0.5, Q0.6  Q0.7, Q1.5, Q1.6  Q1.7, Q2.5, Q2.6  Q2.7 (NC) (configurable Analog).
  • M-Duino 19R: Q0.0, Q0.1, Q0.2 (configurable Analog).
  • M-Duino 38R: Q0.0, Q0.1, Q0.2, Q1.0, Q1.1, Q1.2 (configurable Analog).
  • M-Duino 57R: Q0.0, Q0.1, Q0.2, Q1.0, Q1.1, Q1.2, Q2.0 (NC), Q2.1, Q2.2 (configurable Analog).

In this post we are going to learn how to define the state of the anlog outputs. In this example analog output Q0.3 (Ardbox Analog)  is set to different voltage values within its operation range 0-10V.

int Q03 = 9;   

void setup() {   
pinMode(Q03, OUTPUT);   

}   
void loop() { 
  
analogWrite(Q03,25); 
delay(500);  // wait 500ms 
analogWrite(Q03,75); 
delay(500); // wait 500ms 
analogWrite(Q03,125); 
delay(500); // wait 500ms 
analogWrite(Q03,175); 
delay(500); // wait 500ms 
analogWrite(Q03,225); 
delay(500); // wait 500ms 
analogWrite(Q03,250); 
delay(500); // wait 500ms   
}

As seen on the code, the analogWrite command  requires two inputs; the output reference (Q03) and the output value.   The Analog Output range is 0-10V 8 bits, so the  output values range on Arduino IDE is 0-255. i.e.:  for a 5V output the analogWrite value is   5*255/10 ≈127

AB_analogWrite

The digital outputs pinout can be checked on the User Guides for each PLC. Otherwise,  Arduino IDE start files contain all I/O already declared and with the suitable pinMode defined. To reproduce the same code for the other outputs the pin number should be replaced by the corresponding Arduino pin matching the new Output.
i.e. (Ardbox Analog):

int Q01 = 11;

void setup(){
pinMode(Q01, OUTPUT);

}