Up counter not working on Uno

Edit:
I have found that the up-counter is not working. See Up counter not working on Uno - #7 by cybershell

Hello,

I am using the Uno for school, and I ran into an issue where the analog outputs (holding registers) don't display data or hold data. I am using ScadaBR to build views and display the values from various outputs. I am using MODBUS over RTU and building ladder logic in OpenPLC Editor.

For reference, I am expanding the design in the video below.

The counter in the video is the starting component in a model of a nuclear reactor.

Earlier this week I had an analog output (holding register) reading correctly a value from an up-counter current value. Yesterday it stopped displaying a value.
I am using another analog output (holding register) to write values to a max counter. This value is fine because I can see my changes when I use a ScadaBR component to track the change, it displays fine.

I am at my wit's end with this. I would appreciate any tips.

CyberShell

Check the code,maybe there is a problem there ?

What’s a ‘holding register’ ?

A holding register is a Modbus data type for analog outputs.

It holds values up to 0 – 65535.

https://openplcproject.com/docs/2-5-modbus-addressing/

I have tried everything I can think of. Changing default values, moving stuff around on the ladder logic.

@srnet

Here is the code:

PROGRAM nuclear_reactor
  VAR
    TON0 : TON;
    TOF0 : TOF;
    CTU0 : CTU;
  END_VAR
  VAR
    stopSteamGeneration AT %QX0.0 : BOOL := False;
    turbinesLocked AT %QX0.1 : BOOL := False;
    steamEnabled AT %QX0.2 : BOOL := True;
    nuclearProcess AT %QX0.3 : BOOL := True;
    generatorCycle AT %IX0.0 : BOOL;
    turbineCycle AT %IX0.1 : BOOL;
    steamPulse AT %IX0.2 : BOOL;
    waterFlowing AT %IX0.3 : BOOL;
    currentPressure AT %QW0 : INT := 2;
    maxPressure AT %QW1 : INT := 4;
  END_VAR
  VAR
    turbineMax : INT := 6;
    CTU1 : CTU;
    TP0 : TP;
    TP1 : TP;
    R_TRIG1 : R_TRIG;
    R_TRIG2 : R_TRIG;
  END_VAR

  R_TRIG1(CLK := waterFlowing AND steamEnabled);
  CTU0(EN := TRUE, CU := R_TRIG1.Q, R := steamPulse OR stopSteamGeneration, PV := maxPressure);
  steamPulse := CTU0.Q;
  R_TRIG2(CLK := CTU0.Q);
  CTU1(EN := CTU0.ENO, CU := R_TRIG2.Q, R := turbineCycle OR turbinesLocked, PV := turbineMax);
  TP0(IN := CTU1.Q, PT := T#2s);
  turbineCycle := TP0.Q;
  TP1(EN := CTU1.ENO, IN := TP0.Q, PT := T#4s);
  generatorCycle := TP1.Q;
  IF CTU0.ENO THEN
      currentPressure := CTU0.CV;
  END_IF;
  TON0(EN := TRUE, IN := NOT(waterFlowing) AND nuclearProcess, PT := T#500ms);
  TOF0(EN := TON0.ENO, IN := TON0.Q, PT := T#500ms);
  waterFlowing := TOF0.Q;
END_PROGRAM


CONFIGURATION Config0

  RESOURCE Res0 ON PLC
    TASK task0(INTERVAL := T#20ms,PRIORITY := 0);
    PROGRAM instance0 WITH task0 : nuclear_reactor;
  END_RESOURCE
END_CONFIGURATION

I have the following ladder logic (truncated):

I have found the root cause: the up-counter is not running.

Here is the code:

PROGRAM nuclear_reactor
  VAR
    TON0 : TON;
    TOF0 : TOF;
    CTU0 : CTU;
  END_VAR
  VAR
    stopSteamGeneration AT %QX0.0 : BOOL := False;
    turbinesLocked AT %QX0.1 : BOOL := False;
    steamEnabled AT %QX0.2 : BOOL := True;
    nuclearProcess AT %QX0.3 : BOOL := True;
    generatorCycle AT %IX0.0 : BOOL;
    turbineCycle AT %IX0.1 : BOOL;
    steamPulse AT %IX0.2 : BOOL;
    waterFlowing AT %IX0.3 : BOOL;
    currentPressure AT %QW0 : INT;
    maxPressure AT %QW1 : INT := 4;
  END_VAR
  VAR
    turbineMax : INT := 6;
    CTU1 : CTU;
    TP0 : TP;
    TP1 : TP;
    R_TRIG1 : R_TRIG;
    R_TRIG2 : R_TRIG;
  END_VAR

  R_TRIG1(CLK := waterFlowing);
  CTU0(EN := TRUE, CU := R_TRIG1.Q, R := steamPulse OR stopSteamGeneration, PV := maxPressure);
  steamPulse := CTU0.Q;
  R_TRIG2(CLK := CTU0.Q);
  CTU1(EN := CTU0.ENO, CU := R_TRIG2.Q, R := turbineCycle OR turbinesLocked, PV := turbineMax);
  TP0(IN := CTU1.Q, PT := T#2s);
  turbineCycle := TP0.Q;
  TP1(EN := CTU1.ENO, IN := TP0.Q, PT := T#4s);
  generatorCycle := TP1.Q;
  IF CTU0.ENO THEN
      currentPressure := CTU0.CV;
  END_IF;
  TON0(EN := TRUE, IN := NOT(waterFlowing) AND nuclearProcess, PT := T#500ms);
  TOF0(EN := TON0.ENO, IN := TON0.Q, PT := T#500ms);
  waterFlowing := TOF0.Q;
END_PROGRAM


CONFIGURATION Config0

  RESOURCE Res0 ON PLC
    TASK task0(INTERVAL := T#20ms,PRIORITY := 0);
    PROGRAM instance0 WITH task0 : nuclear_reactor;
  END_RESOURCE
END_CONFIGURATION

I have merged your topics due to them having too much overlap on the same subject matter @cybershell.

In the future, please only create one topic for each distinct subject matter and be careful not to cause them to converge into parallel discussions.

The reason is that generating multiple threads on the same subject matter can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.

Thanks in advance for your cooperation.

1 Like

Arduino and the Nuclear Reactor.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.