MODULE stepper
TITLE 'Krokovy motorcek s mikrokrokom A-AB-B-BC-C-CD-D-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];
StepA  = [1,0,0,0];  " 8
StepAB = [1,1,0,0]; " 12
StepB  = [0,1,0,0]; " 4
StepBC = [0,1,1,0]; " 6
StepC  = [0,0,1,0]; " 2
StepCD = [0,0,1,1]; " 3
StepD  = [0,0,0,1]; " 1
StepDA = [1,0,0,1]; " 9

STATE_DIAGRAM STEPS

STATE StepA :    if STOP then StepA  else if DIR then StepAB else StepDA;
STATE StepAB:    if STOP then StepAB else if DIR then StepB  else StepA;
STATE StepB :    if STOP then StepB  else if DIR then StepBC else StepAB;
STATE StepBC:    if STOP then StepBC else if DIR then StepC  else StepB;
STATE StepC :    if STOP then StepC  else if DIR then StepCD else StepBC;
STATE StepCD:    if STOP then StepCD else if DIR then StepD  else StepC;
STATE StepD :    if STOP then StepD  else if DIR then StepDA else StepCD;
STATE StepDA:    if STOP then StepDA else if DIR then StepA  else StepD;

STATE  0: goto StepA;     " Osetrenie neziaducich stavov...
STATE  5: goto StepA;
STATE  7: goto StepA;
STATE 10: goto StepA;
STATE 11: goto StepA;
STATE 13: goto StepA;
STATE 14: goto StepA;
STATE 15: goto StepA;

EQUATIONS

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

END