MODULE stepper
TITLE 'Krokovy motorcek AB-BC-CD-DA'

"Definicie pinov
CLOCK PIN 43; " hodiny, skusme GCLK1
STOP  PIN 3;  " tlacitko celkom vpravo
DIR   PIN 2;  " tlacitko hned vedla vlavo

PhaseA PIN 34 ISTYPE 'reg';
PhaseB PIN 36 ISTYPE 'reg';
PhaseC PIN 37 ISTYPE 'reg';
PhaseD PIN 38 ISTYPE 'reg';

STEPS = [PhaseA,PhaseB,PhaseC,PhaseD];
StepAB = [1,1,0,0];
StepBC = [0,1,1,0];
StepCD = [0,0,1,1];
StepDA = [1,0,0,1];


STATE_DIAGRAM STEPS

STATE StepAB:    if STOP then StepAB else if DIR then StepBC else StepDA;
STATE StepBC:    if STOP then StepBC else if DIR then StepCD else StepAB;
STATE StepCD:    if STOP then StepCD else if DIR then StepDA else StepBC;
STATE StepDA:    if STOP then StepDA else if DIR then StepAB else StepCD;

STATE  0: goto StepAB;
STATE  1: goto StepAB;
STATE  2: goto StepAB;
STATE  4: goto StepAB;
STATE  5: goto StepAB;
STATE  7: goto StepAB;
STATE  8: goto StepAB;
STATE 10: goto StepAB;
STATE 11: goto StepAB;
STATE 13: goto StepAB;
STATE 14: goto StepAB;
STATE 15: goto StepAB;

EQUATIONS

STEPS.CLK = CLOCK;
STEPS.OE = [1,1,1,1]; "! Ked bolo len  = 1, tak pochopil iba 0001, cize len PhaseD

END