Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@iromero91
Created February 16, 2015 23:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iromero91/af094f7009c82406389c to your computer and use it in GitHub Desktop.
Save iromero91/af094f7009c82406389c to your computer and use it in GitHub Desktop.
LDmicro0.1
MICRO=Microchip PIC16F887 40-PDIP
CYCLE=20000
CRYSTAL=20000000
BAUD=2400
COMPILED=Z:\home\cyborgar\projects\washing-machine\compiled-ld\ladder.hex
IO LIST
XDOOR_LOCKED at 19
XLEVEL_FULL at 22
XLEVEL_HALF at 21
XOVERFLOW at 27
XSTART at 28
XWARM at 20
YDOOR_LOCK at 33
YHEATER at 34
YINLET_VALVE at 35
YPUMP at 36
YSPIN at 37
YTUMBLE_CCW at 8
YTUMBLE_CW at 9
END
PROGRAM
RUNG
COMMENT All inputs are complementary in this PLC. so invert them.
END
RUNG
CONTACTS XDOOR_LOCKED 1
COIL RXDOOR_LOCKED 0 0 0
END
RUNG
CONTACTS XWARM 1
COIL RXWARM 0 0 0
END
RUNG
CONTACTS XLEVEL_HALF 1
COIL RXLEVEL_HALF 0 0 0
END
RUNG
CONTACTS XLEVEL_FULL 1
COIL RXLEVEL_FULL 0 0 0
END
RUNG
CONTACTS XOVERFLOW 1
COIL RXOVERFLOW 0 0 0
END
RUNG
CONTACTS XSTART 1
COIL RXSTART 0 0 0
END
RUNG
COMMENT Safety rung
END
RUNG
CONTACTS RXOVERFLOW 1
CONTACTS RXDOOR_LOCKED 0
COIL RSAFE 0 0 0
END
RUNG
COMMENT TODO: Replace this fixed logic with a program selector!
END
RUNG
OPEN
COIL RHALF_LOAD 0 0 0
END
RUNG
OPEN
COIL RSKIP_SPIN 0 0 0
END
RUNG
CONTACTS RXSTART 0
OSR
PARALLEL
MOVE CWASHES 1
MOVE CRINSES 2
END
END
RUNG
PARALLEL
CONTACTS RXSTART 0
SERIES
CONTACTS RRUNNING 0
CONTACTS RSPIN_CYC_DONE 1
END
END
COIL RRUNNING 0 0 0
END
RUNG
COMMENT Wash cycle is the begining of the program (triggered by XSTART)
END
RUNG
PARALLEL
SERIES
CONTACTS RWASH_CYC 0
LEQ CWASHES 0
END
CONTACTS RWASH_CYC_DONE 0
END
COIL RWASH_CYC_DONE 0 0 0
END
RUNG
CONTACTS RRUNNING 0
CONTACTS RWASH_CYC_DONE 1
COIL RWASH_CYC 0 0 0
END
RUNG
COMMENT Rinse cycle, pretty much the same as the wash cycle
END
RUNG
PARALLEL
SERIES
CONTACTS RRINSE_CYC 0
LEQ CRINSES 0
END
CONTACTS RRINSE_CYC_DONE 0
END
COIL RRINSE_CYC_DONE 0 0 0
END
RUNG
CONTACTS RWASH_CYC_DONE 0
CONTACTS RRINSE_CYC_DONE 1
COIL RRINSE_CYC 0 0 0
END
RUNG
COMMENT Spin cycle, just spin the basket for 8 minutes.
END
RUNG
PARALLEL
SERIES
CONTACTS RSPIN_CYC 0
TON TSPIN_TIME 480000000
END
CONTACTS RSPIN_CYC_DONE 0
SERIES
CONTACTS RRINSE_CYC_DONE 0
CONTACTS RSKIP_SPIN 0
END
END
COIL RSPIN_CYC_DONE 0 0 0
END
RUNG
CONTACTS RRINSE_CYC_DONE 0
CONTACTS RSPIN_CYC_DONE 1
COIL RSPIN_CYC 0 0 0
END
RUNG
COMMENT Cycle step logic, when all phases are completed
END
RUNG
CONTACTS RFILL_PH_DONE 0
CONTACTS RTUMBLE_PH_DONE 0
CONTACTS RDRAIN_PH_DONE 0
PARALLEL
COIL RCYCLE_START 0 0 0
SERIES
CONTACTS RWASH_CYC 0
CTD CWASHES 0
END
SERIES
CONTACTS RRINSE_CYC 0
CTD CRINSES 0
END
END
END
RUNG
COMMENT Fill phase, open the valve until the tub gets filled enough.\r\nIt's the beginning of a wash or rinse cycle.
END
RUNG
PARALLEL
SERIES
CONTACTS RFILL_PH 0
PARALLEL
SERIES
CONTACTS RHALF_LOAD 0
CONTACTS RXLEVEL_HALF 0
END
CONTACTS RXLEVEL_FULL 0
END
END
SERIES
CONTACTS RFILL_PH_DONE 0
CONTACTS RCYCLE_START 1
END
END
COIL RFILL_PH_DONE 0 0 0
END
RUNG
PARALLEL
CONTACTS RWASH_CYC 0
CONTACTS RRINSE_CYC 0
END
CONTACTS RFILL_PH_DONE 1
COIL RFILL_PH 0 0 0
END
RUNG
COMMENT Fill phase alarm to prevent overflow/coil burnout\r\n
END
RUNG
CONTACTS RFILL_PH 0
TON TFILL_ALM_TIME 400000000
COIL RFILL_ALM 0 0 0
END
RUNG
COMMENT Tumble phase, do a predefined number of tumbles.\r\nAlways comes after a fill phase.
END
RUNG
PARALLEL
SERIES
CONTACTS RTUMBLE_PH 0
LEQ CTUMBLES 0
END
SERIES
CONTACTS RTUMBLE_PH_DONE 0
CONTACTS RCYCLE_START 1
END
END
COIL RTUMBLE_PH_DONE 0 0 0
END
RUNG
CONTACTS RFILL_PH_DONE 0
CONTACTS RTUMBLE_PH_DONE 1
PARALLEL
COIL RTUMBLE_PH 0 0 0
SERIES
OSR
PARALLEL
SERIES
CONTACTS RWASH_CYC 0
LOOK_UP_TABLE CTUMBLES CWASHES 4 0 0 64 6 6
END
SERIES
CONTACTS RRINSE_CYC 0
LOOK_UP_TABLE CTUMBLES CRINSES 3 0 0 6 32
END
END
END
END
END
RUNG
PARALLEL
SERIES
CONTACTS RDRAIN_PH 0
CONTACTS RXLEVEL_HALF 1
TON TDRAIN_DELAY 20000000
END
SERIES
CONTACTS RDRAIN_PH_DONE 0
CONTACTS RCYCLE_START 1
END
END
COIL RDRAIN_PH_DONE 0 0 0
END
RUNG
CONTACTS RTUMBLE_PH_DONE 0
CONTACTS RDRAIN_PH_DONE 1
COIL RDRAIN_PH 0 0 0
END
RUNG
COMMENT Actual hardware control
END
RUNG
CONTACTS RRUNNING 0
COIL YDOOR_LOCK 0 0 0
END
RUNG
CONTACTS RSAFE 0
CONTACTS RFILL_PH 0
CONTACTS RFILL_ALM 0
COIL YINLET_VALVE 0 0 0
END
RUNG
CONTACTS RSAFE 0
PARALLEL
CONTACTS RTUMBLE_PH 0
CONTACTS RDRAIN_PH 0
END
CONTACTS YTUMBLE_CCW 1
TON TCW_DELAY 5000000
PARALLEL
SERIES
CONTACTS RCW_TIMEOUT 1
COIL YTUMBLE_CW 0 0 0
END
SERIES
TON TCW_TIME 10000000
COIL RCW_TIMEOUT 0 0 0
END
END
END
RUNG
CONTACTS RSAFE 0
PARALLEL
CONTACTS RTUMBLE_PH 0
CONTACTS RDRAIN_PH 0
END
PARALLEL
CONTACTS RCW_TIMEOUT 0
CONTACTS YTUMBLE_CCW 0
END
TON TCCW_DELAY 5000000
PARALLEL
SERIES
CONTACTS RCCW_TIMEOUT 1
COIL YTUMBLE_CCW 0 0 0
END
SERIES
TON TCCW_TIME 10000000
PARALLEL
COIL RCCW_TIMEOUT 0 0 0
SERIES
CONTACTS RTUMBLE_PH 0
CTD CTUMBLES 0
END
END
END
END
END
RUNG
CONTACTS RSAFE 0
CONTACTS RSPIN_CYC 0
CONTACTS YTUMBLE_CW 1
CONTACTS YTUMBLE_CCW 1
COIL YSPIN 0 0 0
END
RUNG
CONTACTS RSAFE 0
PARALLEL
CONTACTS RDRAIN_PH 0
CONTACTS RSPIN_CYC 0
END
COIL YPUMP 0 0 0
END
RUNG
CONTACTS RSAFE 0
OPEN
COIL YHEATER 0 0 0
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment