Dave Hugg
I have been trialing OpenPLC for several weeks now and have discovered what I believe is a error in the software.
 
I am trying to build a temperature control application that reads several chamber temperatures and turns on/off a Peltier cooler or electric heater to try and maintain the temperature at a specific value.
 
I am using an Arduino Nano and am directly downloading to this physical device from OpenPLC Editor. I have configured the Nano as a Modbus RTU slave so that I can view variables using RMMS (Radzio).
 
I have built an OpenPLC application that reads several temperatures on two separate input pins using the DS18B20 and DS18B20_2_OUT blocks and writes these values to Modbus. I can verify from RMMS that this application is working correctly.
I have also built an application that turns on and off digital outputs. This logic makes use of TON and TOF blocks. I have LEDs connected to the digital outputs and can confirm that this logic also works correctly.
 
However, if I try to combine these two applications together, I have discovered that the logic does not work as expected. It appears that the presence of a DSB1820-type block somehow prevents the TON/TOF logic from functioning correctly.
 
I verified this by running a DS18B20 read, followed by a simple energizing of a single digital output. This logic worked correctly. But then I tried to modify the application to energize the same digital output through a TON block and I discovered that the digital output never energizes. It is as if the DS18B20-type block prevents the TON from functioning correctly.
 
Has anyone else experienced this issue, and if so, have you found a work-around?
 
Thanks, Dave Hugg
Reply 0 0
thiagoralves
DS18B20 sensors are VERY slow. Since Arduino boards are single core and single threaded, everything runs in sequence. Because these sensors are slow, if you place a DS18B20 block in a program, it will delay the execution of the program significantly, making it out of sync with the scan cycle period (the default is 20ms). Timer blocks depend on the scan cycle period to measure time. If your 20ms scan cycle is taking 500ms or more because of your DS18B20 block, then the timers won’t count time accurately. The ideal usage of these blocks is to place them in a separate program, running on a very slow task (for example with a 5 seconds scan cycle time). Use global variables to share the readings from the slow temp reading program and your main program running at 20ms. Also, avoid using more than one DS18B20 block, as this can degrade performance even more. Put all your sensors on the same pin and use a single DS18B20 block with multiple outputs.
Reply 0 0
Dave Hugg
Thiago,
 
Thank you for the prompt reply to my question.
 
I am going to try to proto-thread the DS18B20 functions on the Arduino side of the OpenPLC application. I only need 15-30 second temperature data for my application to work correctly. If successful I will make sure to post the results.
 
Failing that, I will move the DS18B20 functions to a separate Arduino and will share the results with OpenPLC using Modbus.
Reply 0 0
thiagoralves
Doing it on the Arduino side will make it worse. The Arduino Extension runs at the same pace as the fastest scan cycle. The ideal approach is to place it on a separate program. On the OpenPLC Editor, click on the grey plus button on the left panel and select “program” to create a new program. Then on Res0, create a task and instance to run this new program. Make sure the task interval is quite large (5s or more depending on your temperature reading needs). Then place your ds18b20 block in this separate program
Reply 0 0
Dave Hugg
Thiago,
 
Thanks again for the assistance. My program is now working. My knowledge of the multi-program nature of OpenPLC is limited. I will read through the Beremiz documentation to increase my understanding.
 
I do have one final question if you don't mind. I note that all of the DS18B20-style function blocks return temperatures in increments of 0.5 DegC. I realize that the DS18B20 is only accurate to +/-0.5 degC, but my temperature control range is only about +/-2.0 degC, so I would like the DS18B20 readings to not be so granular. Could you tell me how I could change the DS18B20-style blocks to return temperatures in 0.1 degC increments?
Reply 0 0
thiagoralves
I don’t think that’s possible. If it is, you would have to change the source code of the block. Not very straightforward.
Reply 0 0
Dave Hugg
Thanks for the info. I may have a stab at changing the code anyway. Are there any documentation resources to explain how to modify and te-compile code?
Reply 0 0
Dave Hugg
Thiago,
 
I just read through the section that explains how to add custom blocks to the system. I will work with that explanation to see how I go. To save myself some time/effort, I am going to modify your original DS18B20-style block types. I realize that these changes will be lost if/when I update the OpenPLC Editor software.
Reply 0 0
thiagoralves
Yes. Arduino-specific code for the blocks are inside the editor/arduino/examples/Baremetal/modules
Reply 0 0
Dave Hugg
Thiago, I found the code. In the file OpenPLC_Editor\editor\arduino\examples\Baremetal\modules\ds18b20.c I see that no resolution has explicitly been set. I reviewed data from an Arduino forum, and the default resolution is nine(9) bits, which only updates by increments of 0.5 degC, as observed. Ten bits provides increments of 0.25 degC, 11 bits is 0.125 degC, and 12 bits is 0.0625 degC. I am going to add a Dallas temperature sensor.setResolution(11) command to the file mentioned above, and hopefully this will give me the resolution I am seeking.
 
Once again, thanks for all of your help.
Reply 0 0
Reply