Automatic restart of the 1-Wire bus

The 1-Wire bus is prone to EMI which can result in sensors being “stuck” and disabling the whole bus communication. With our PLCs you are able to turn the power off for the whole 1-Wire bus and forcing the sensors to reset.

Patron
Neuron
Axon

In Mervis, the property controlling the power supply for the 1-Wire bus is called OW_off_1. By setting the value to TRUE, the bus will be disconnected from the power supply and by resetting back to FALSE the power supply will be connected back.

You can reset the power supply manually, but with the help of commerror attributes, you can let Mervis do it automatically. The attributes are available on the particular device or the whole channel and they indicate when the Mervis wasn't able to read the datapoints for given device/channel.

We will start the project in the Full mode, attaching to the controller, creating a FBD program and setting a task executing this program. Next we create ModbusTCP channel for the IOs of the PLC and 1-Wire channel for the 1-Wire bus. Then deploy the solution and detect the 1-Wire sensors. Your workspace should look like this:

As you can see, we have one 1-Wire thermometer, which we renamed to “office”. Now double click on the 1-Wire channel in the Left panel. You will be presented by all the available datapoints:

The most important is the attribute commerror, which indicates if there is a communication error with any of the connected sensors. The attribute's type is bool and when the value is TRUE, it means there is a communication error and once the error disappears, the attribute is FALSE. As you can see, attribute of the same name is in the office section as well. This attribute indicates communication error only for the sensor called office.

The solution for automatic restart needs to check the value of the commerror and when it is TRUE we need to briefly set the OW_off_1 to TRUE and then set it back to FALSE. Better yet, if the commerror stays in TRUE we will try resetting the bus periodically. For this function, we can use block Pulse Generator (BD2):

By default the block has visible input Enable. If the input is TRUE, the block will generate square signal on the Out output. You can set the length of the pulse and the pause via the hidden inputs Tfalse and Ttrue.

As you probably guessed, we will use the commerror attribute as a input and we can directly wire the Out output to the OW_off_1 variable:

All we need to alter is the length of the pulse and the pause between pulses to some reasonable values such as Ttrue = 1 s and Tfalse = 4 s, deploy the solution and start debugging. Then you can unplug the 1-Wire sensor and you will see that the measured values are red and the commerror attribute is TRUE and the Pulse Generator is sending reset pulses to the bus: