rs27

Hi,

first, I would like to congratulate for the great project. The approaches to build the hardware and modular I really liked it. That's why I've considered and already tested how the modular design can be realized. I did the tests with a Raspbery Pi.

The structure of the controller can be seen in the following pdf.


Quote 0 0
thiagoralves
Nice build! Is the RPi built in the module itself or does it connect to it externally? How is that connection made? Cables? Connectors?
Quote 0 0
rs27

There is also a frame for the RPI. Another frame is available for an adapter board where the RPI is plugged in via a ribbon cable. The adapter board then makes the connection to the BUS. With a PI Zero, this could be done easier and with less space, but I wanted to learn first and then optimize. The frames for the controller can be made with a 3D printer. This allows the housing to be designed according to the requirements. The connection of the modules is stabilized by a groove in the frame. The frame will not move laterally. This solves the problem of mechanical stress on the bus connectors.

The bus connector between the modules is a 40 pin pin lead.
bus connector.jpg 
In the near future, I would like to introduce the details and also like to discuss ways to improve.


Quote 0 0
rs27

Hi, in this article I would like to present the circuit of the DIO module and the corresponding documents.

For the 8 inputs, I chose optocouplers, as they allow a larger voltage range at the input. With the resistor R1 and R11, the switching voltage can be adjusted according to the requirements. In this dimensioning the switching threshold is about 8V.
input.jpg 

The output used was 8 pieces of BSP452. It is a high side switch and has the following properties:

  • Short-circuit protection
  • Input protection
  • Overtemperature protection with hysteresis
  • Overload protection
  • Overvoltage protection
  • Switching inductive load
  • Clamp of negative output voltage with inductive loads
  • Undervoltage shutdown
  • Maximum current internally limited
  • Electrostatic discharge (ESD) protection
output.jpg 

In the following files are the PCB Eagel files and a PCB PDF.

Quote 0 0
rs27
Hi, with this post I would like to present the housing for the DIO module which was created with a 3D printer. The following zip folder contains the data for the 3D printer.
Quote 0 0
thiagoralves
Thanks for sharing. Post here also when you have the final prototype. Did you write OpenPLC drivers for it?
Quote 0 0
rs27
I have created a prototype and already tested. I also created an openPLC driver. This works correctly, but I still have something to optimize the detection of the modules. If there is interest, I can also introduce the driver. One point I noticed. For the input / output bool variables an array with uint8_t xxx [1024] [8] is used. This requires 8k bytes in total. Would not be enough array with bool xxx [1024] for the I / O. That would then occupy only 128 bytes?
Quote 0 0
thiagoralves
I would agree that a single 1024 array should be enough if OpenPLC was to run on a small microcontroller. But on a Raspberry Pi with at least 512MB of RAM, it doesn't make any difference at all if the array occupies 8K or 128 bytes of RAM. This is absolutely insignificant given then amount of memory of the main system.

Once you have everything ready, you can share your project files here for the community to use. Thanks!
Quote 0 0
rs27

In this post I would like to discuss the control via I2C. When I created the driver, I oriented myself to the unipi driver (/home/pi/OpenPlc_v3/webserver/core/hardware_layers/unipi.cpp). I used the wiringpi software on the Rasperry Pi for I2C control. The transmission speed for the I2C bus is set to 100 kbit/s. The bitrate can be changed at the RPI in the file /boot/config.txt. In the file, the bitrate is increased to 400 kbit/s with dtparam = i2c_arm_baudrate = 400.

With the unipi driver, the outputs for each line are controlled separately. This means that 8 times the data byte is transmitted for the 8 outputs. Since the transmission for the I2C bus is a bottleneck, I have changed the program so far that I collect the information of the 8 outputs internally in one byte and so I have to transmit only one byte. I also used the same procedure for reading the input information.

Implementation to the port output:
DIO_OUT_driver.jpg

The transmission on the I2C bus takes place in the cycle of 20ms. This is also the cycle time, which is set in the controller.

Sale Bild 1.jpg

The telegram for reading the inputs requires 100μs per module.

Salea Bild 2.jpg

The telegram for writing the outputs also requires 100μs per module

Salea Bild 3.jpg 

For faster data transfer, the clock rate for the I2C bus could be changed to 1 Mbit/s. That would speed up the transmission time by 2.5.

Quote 0 0
rs27

In this post I would like to introduce the power module. The controller should be supplied with a voltage of 24V. In the power module (blue module on the right side), the voltages required for the control are generated from the 24V.
bild1.jpg 

The module currently consists of only three DC / DC converters providing 2 x 5V / 3A and one 12V / 3A for Analog control. One 5V converter is provided for powering the RPI. In addition, there is a voltage regulator on the module for a 3.3V supply.




Quote 0 0
rs27

For the control is still missing the RPI. This is also housed in a frame. Since a frame only has a width of 17.5mm I have to create a frame for the connection to the bus and a frame for the RPI. This part is still in progress, but I can already imagine the framework with the RPI.

RPI Frame.jpg 

The RPI is then connected to the EK-bus connector via a ribbon cable
Quote 0 0
thiagoralves
Nice! Just be careful with increasing I2C speeds. I2C was designed to be an in-circuit protocol (wired on PCB lanes). Having it going on cables and connectors on high speed can be catastrophic. A better design approach would be using RS485. It is a lot more robust against noise since it goes on higher voltage levels and use a differential pair.
Quote 0 0
rs27

At the modbus I have already thought for more modules for sensors and analog values. I would like to look at it. Which lines can I use from the RPI for the RS485 (TxD = GPIO14, RXD = GPIO15, EN = GPIO ??). I then have to set the baud rate to 115200 baud. As a controller, I would then use the ATMega32U4. Then I can program under Arduino. For this building condition, there are already some posts in the forum.

Quote 0 0
thiagoralves
You don't have to use Modbus over RS485. You can use any protocol you want, or even come up with your own. If you want to reuse the current software structure (and save you time), OpenPLC slave devices module uses libmodbus to communicate with slave boards using Modbus. This is very easy to configure and setup from OpenPLC web interface. Just select Generic Modbus RTU from the type list, select the serial port, baud rate, and the registers you want to read/write. The only modification you might need to make on that code is the usage of the EN pin. Currently there is no implementation to use an EN pin, just RX/TX from the selected serial port. I believe that libmodbus offers support for using an EN pin, but I'm not sure.
Quote 0 0
rs27

Unfortunately, my inputs for the mode slave are not accepted. What am I doing wrong?
modbus slave.jpg 
Quote 0 0