Stationeers

Stationeers

View Stats:
Bruchbein Mar 11, 2021 @ 1:36am
Need help with IC Programming
hey its my first time programing and i have a big problem with my program my somebody Could help me
The Programm Should Control the pressure in the Tank if the Tank have 14MPa Then the valvehaupt Should close and the valvebyass Should Open so the Problem is that the Programm only Runs from line 18 and i dont Know why 😭


alias TankC02 d0
alias ValveHaupt d1
alias ValveBypass d2
alias maxpressure r0
alias aktpressure r1

move r0 14000



line 10: l r1 d0 Pressure
yield
bgt r1 r0 18
yield
blt r0 r1 23



line 18: s d2 On 1
s d1 On 0
j 10


line 23: s d1 On 1
s d2 On 0
j 10
Originally posted by dupa:
When you say the program runs from line 18 I don't know what you mean.
But there is a logical problem in the program:

line 12: bgt r1 r0 18
line 14: blt r0 r1 23

or in English:
if r1 > r0 jump to 18
if r0 < r1 jump to 23

If you think about it , "r1 > r0" is the same as "r0 < r1". I am not sure that this is what you are trying to achieve.

Also I recommend using line labels for jumps. Example

loop: yield ... ...code... ... j loop

If you add a line of code, line 10 may become line 11 and you have to update it in the code. If you use labels, you can avoid this problem and also if you label things correctly, it will make the reading of the code easier.
< >
Showing 1-10 of 10 comments
Bruchbein Mar 11, 2021 @ 2:34am 
The line Numbers i Wrote are just examples (line 18 line 10 etc ) there are normaly Not in the Code
devblazer Mar 11, 2021 @ 3:16am 
Its difficult to see without the actual devices, save file, ect. But I don't see anything obviously wrong.

My advice it to hook up a console or two (small led display) and then write your actual pressure variable to one before the switch statements. And If that fails, at different parts of code. This way you will know what the value is at different points in code and will be able to easily find out whats wrong.
devblazer Mar 11, 2021 @ 3:18am 
I generally keep my d5 open for a debug console display. And if im using all my connections on the IC, then resort to using the newer sb batch writing feature to write to a console. It's great for live debugging.
Last edited by devblazer; Mar 11, 2021 @ 3:18am
The author of this thread has indicated that this post answers the original topic.
dupa Mar 11, 2021 @ 6:05am 
When you say the program runs from line 18 I don't know what you mean.
But there is a logical problem in the program:

line 12: bgt r1 r0 18
line 14: blt r0 r1 23

or in English:
if r1 > r0 jump to 18
if r0 < r1 jump to 23

If you think about it , "r1 > r0" is the same as "r0 < r1". I am not sure that this is what you are trying to achieve.

Also I recommend using line labels for jumps. Example

loop: yield ... ...code... ... j loop

If you add a line of code, line 10 may become line 11 and you have to update it in the code. If you use labels, you can avoid this problem and also if you label things correctly, it will make the reading of the code easier.
Last edited by dupa; Mar 11, 2021 @ 6:07am
Bruchbein Mar 11, 2021 @ 7:41am 
with line i mean the line of the code but u solved my problem
it should say r1 > r0 and r1 < r0
thanks man i dont see this little mistake
yeah i think i would use labels for now its my first time so im happy that the program is working now :-)
Last edited by Bruchbein; Mar 11, 2021 @ 7:43am
HoschiTv Mar 11, 2021 @ 7:47am 
I see it like Dupa.

It looks like a logical issiue, with the second branch.
and i would try it without a second r?
What you could try. For example


0. start:
1. alias TankCO d0
2. alias HValve d1
3. alias BValve d2
4. alias akt.Pressure r0
5. l r0 d0 Pressure
6. bgt r0 14000 Bypass
7. yield
8. blt r0 14000 Fill
9. j start
10.
11. Bypass:
12. s d1 On 0
13. s d2 On 1
14. j start
15.
16. Fill:
17. s d1 On 1
18. s d2 On 0
19. j start

I think this shoul work ;)
dupa Mar 11, 2021 @ 10:35am 
Originally posted by Bruchbein:
with line i mean the line of the code but u solved my problem
it should say r1 > r0 and r1 < r0
thanks man i dont see this little mistake
yeah i think i would use labels for now its my first time so im happy that the program is working now :-)

Glad I could help.
Norseman Mar 11, 2021 @ 9:44pm 
Using line to jump is bad way of coding imo.
As the slightest change in your code with added lines and you need to alter those line numbers yet again.
Use loop or Start instead etc.
unclesam Mar 13, 2021 @ 7:02pm 
Some little tips for better programming:
Use the aliases which you declare at the beginning. Use marks for jumps and make define statements for constants. Yield must only be used once for one loop. Happy programming!

alias TankC02 d0
alias ValveHaupt d1
alias ValveBypass d2
alias aktpressure r1
define maxpressure 14000

start:
l aktpressure TankC02 Pressure
bgt aktpressure maxpressure bypass
# if the expression above is false, the next line will be executed
# no need to test again and jump somewhere
s ValveHaupt On 1
s ValveBypass On 0
j end
# you could jump to start and put a yield there, but I prefer using a end part for having more structure inside the code

bypass:
s ValveBypass On 1
s ValveHaupt On 0

end:
yield
j start
Last edited by unclesam; Mar 13, 2021 @ 8:13pm
< >
Showing 1-10 of 10 comments
Per page: 1530 50

Date Posted: Mar 11, 2021 @ 1:36am
Posts: 10