toucan-2e735c
I am playing around with the cycle interval in the resource config and I dont think I understood this.
 
I have an ESP8266 NodeMCU (80MHz, can also be run on 160MHz), but I will stick to 80MHz.
 
now 80MHz has 12.5ns (nanoseconds) cycle. if I say T#0.000013ms in the resource config, nothing works anymore. beside the editor crashing, also the timers dont seem to work at all.
 
I was hoping that the MQTT receiving would be faster with this setting. (I get the mqtt msg on my linux terminal [mqttui] with low latency, as soon as I send them). but on the nodemcu it can delay up to a second sometimes. but other times it is fast.
 
so I hoped with a higher cycle setting I could "increase" the CPU frequency of the board (beside the fact that while uploading it still says Crystal 26MHz no matter what cycle interval I use).
 
am I doing this right? is this how you set the right clock speed? and in general, what does cycle interval really represent in OpenPLC? what does it exactly mean?
 
I slowly incremented the cycle interval until the timers worked again and everything works well at 1ms it seems.
but 1ms is something in the Hz area (instead of MHz).
 
what is the right setting for my esp8266 nodemcu?
Reply 0 0
toucan-2e735c
hmm, but then again at 1ms even mqtt seems to work fine, sometimes even receiving faster than on my terminal. I should consider that this is wifi and latency can vary.
 
anyway, I still would like to know what this cycle interval is all about and what the right settings for my nodemcu are.
 
EDIT: I noticed it is fast at the beginning (after rebooting the device) then it is getting slower over time, until I hit around 3s to 4s to receive each message. that was on 1ms cycle interval. this effect does not happen with >=10ms cycle interval.
Reply 0 0
thiagoralves
The cycle time internal has nothing to do with your ESP8266 clock. PLCs are cyclic machines. The cycle time interval is the time you give to the PLC runtime to execute your full program once. If you give it too short of a time, it will struggle to keep the pace right and you will loose the real time effect of the system, as you saw in your attempts at reducing the cycle time interval. Ideally, you should have this time be as large as you can for the system you’re controlling. Long cycle times free up the CPU to do other things (like networking for example). Short cycle times increase the burden on the CPU to run your program cycle more frequently
Reply 0 0
toucan-2e735c
Ive set the cycle time to 100ms (just to be on the safe side). I can still observe the same effect: initially after reboot the mqtt msg are coming in almost instantly, but it gradually becomes slower and slower, up to a point where it takes 6 seconds until the LED turns off (as soon as mqtt msg is received).
 
it looks some kind of congestion to me. maybe memory, maybe the more it cycles the slower it gets for part of the program.
 
what could be the reason for this? anyone experiencing the same problem?
Reply 0 0
thiagoralves
It’s hard to tell without knowing exactly what your setup looks like. I would suggest you put a heartbeat led that blinks at every scan cycle. This will help you determine if the program is in fact freezing or if you’re having network congestion or something else
Reply 0 0
toucan-2e735c
while Im at it, let me ask another question:
Ive set up a simple PWM with 10k pot to A0 (input) to A1 (output) with a LED. two variable located at IW0 and QW0, connected together in LD.
 
I can observe the following on my scope:
  • from 0 to 16255 I get a 1kHz PWM, ranging from 0mV [Vavg], 300mV [Vrms] to 2.34V [avg], 2.37V [Vrms]
  • from 16255 to 65535 I get unpulsed (no frequency) DC (constant 2.36V [Vavg] and 2.38V [Vrms])
  • potentiometer turning til the end it goes above 65535 (debugger says 0) and voltage drops to 0
so Im turning from start to somewhere in the middle of the pot and I get 1kHz pulse. the other half of the pot is constant DC and the end is off (0V).
 
is this normal behaviour? shouldnt I get the full range of 0 - 65535? for example in arduino you would use analogRead() with 10 bits resulting in integer values from 0 to 1023. how does openplc do the mapping here?
 
this is an esp8266 with A0 at 10-bit resolution and 1kHz frequency.
Reply 0 0
thiagoralves
OpenPLC uses the same analogRead() call, and scales it up to 65535, so the behavior should be exactly the same. Check the editor/arduino/hals/esp8266.cpp file to verify the behavior. If you find anything odd there let us know please.
Reply 0 0
Reply