Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # ROOM CONTROLLER IC
- alias MasterIC d0
- alias AtmosSensor d1
- alias IntakeVent d2
- alias OutputVent d3
- define MSG_READY 0
- define MSG_TEMP_STATUS 1
- define MSG_ATMOS_STATUS 2
- define MSG_HEATING_CMD 3
- define MSG_COOLING_CMD 4
- define TEMP_TARGET 293.15
- define O2_TARGET 0.21
- define CO2_MAX 0.005
- define TEMP_TOLERANCE 1.0
- define O2_TOLERANCE 0.01
- alias temp_status r0
- alias atmos_status r1
- alias heating_cmd r2
- alias cooling_cmd r3
- s db Setting MSG_READY
- main:
- yield
- # Force send status every cycle - critical fix
- jal force_send_status
- # check for commands
- jal check_commands
- # Control vents
- jal control_vents
- j main
- force_send_status:
- # Temperature status first
- l r6 MasterIC Setting
- beqz r6 send_temp
- yield
- j force_send_status
- send_temp:
- move r7 MSG_TEMP_STATUS
- s MasterIC Setting r7
- yield
- # wait for master to acknowledge (-1)
- wait_master_ack:
- l r6 MasterIC Setting
- beq r6 -1 temp_ack
- yield
- j wait_master_ack
- temp_ack:
- # Send temperature value
- l r6 AtmosSensor Temperature
- s MasterIC Setting r6
- yield
- # wait for master to process (back to 0)
- wait_master_ready:
- l r6 MasterIC Setting
- beqz r6 atmos_start
- yield
- j wait_master_ready
- atmos_start:
- # Atmosphere status
- move r7 MSG_ATMOS_STATUS
- s MasterIC Setting r7
- yield
- wait_master_ack2:
- l r6 MasterIC Setting
- beq r6 -1 atmos_ack
- yield
- j wait_master_ack2
- atmos_ack:
- # send atmosphere value (1 if needs filtering, 0 if good)
- l r7 AtmosSensor RatioOxygen
- l r8 AtmosSensor RatioCarbonDioxide
- sub r9 r7 O2_TARGET
- abs r10 r9
- sgt r11 r10 O2_TOLERANCE
- sgt r12 r8 CO2_MAX
- or atmos_status r11 r12
- s MasterIC Setting atmos_status
- j ra
- check_commands:
- l r6 db Setting
- beqz r6 no_command
- seq heating_cmd r6 MSG_HEATING_CMD
- seq cooling_cmd r6 MSG_COOLING_CMD
- s db Setting MSG_READY
- j ra
- no_command:
- j ra
- control_vents:
- # Atmosphere / pull dirty air to filters
- s IntakeVent On atmos_status
- s IntakeVent Mode 0 # Outward
- # temperature - push conditioned air to room
- or r6 heating_cmd cooling_cmd
- s OutputVent On r6
- s OutputVent Mode 1 # Inward
- # Reset commands
- move heating_cmd 0
- move cooling_cmd 0
- j ra
Advertisement
Add Comment
Please, Sign In to add comment