void move_stepper(int direction, int s1, int s2, int s3, int s4, int s5) { ioport_set_pin_level(STEP,0); ioport_set_pin_level(DIR, direction); ioport_set_pin_level(SLEEP,1); int i=0; full_step(); for(i=0;i<s1;i++) { ioport_set_pin_level(STEP,1); delay_ms(DELAY_STEP); ioport_set_pin_level(STEP,0); delay_ms(DELAY_STEP); } half_step(); for(i=0;i<s2;i++) { ioport_set_pin_level(STEP,1); delay_ms(DELAY_STEP); ioport_set_pin_level(STEP,0); delay_ms(DELAY_STEP); } quarter_step(); for(i=0;i<s3;i++) { ioport_set_pin_level(STEP,1); delay_ms(DELAY_STEP); ioport_set_pin_level(STEP,0); delay_ms(DELAY_STEP); } either_step(); for(i=0;i<s4;i++) { ioport_set_pin_level(STEP,1); delay_ms(DELAY_STEP); ioport_set_pin_level(STEP,0); delay_ms(DELAY_STEP); } sixteen_step(); for(i=0;i<s5;i++) { ioport_set_pin_level(STEP,1); delay_ms(DELAY_STEP); ioport_set_pin_level(STEP,0); delay_ms(DELAY_STEP); } ioport_set_pin_level(SLEEP,0); }
int perfect_measure_instruction() { int state = STATE_BEFORE_INSTRUCTION; int c = 0; for (int i = 0; i < MAX_CYCLES; i++) { uint16_t ab; uint8_t db; BOOL r_w; full_step(&ab, &db, &r_w); if (state == STATE_DURING_INSTRUCTION && ab > trigger2) { /* * we see the FIRST fetch of the next instruction, * the test instruction MIGHT be done */ state = STATE_FIRST_FETCH; } if (state == STATE_DURING_INSTRUCTION) { instr_rw[c] = r_w; instr_ab[c] = ab; instr_db[c] = db; c++; } if (ab == TRIGGER1) { state = STATE_DURING_INSTRUCTION; /* we're done writing the trigger value; now comes the instruction! */ } if (ab == TRIGGER3) { break; /* we're done dumping the CPU state */ } }; return c; }
int main (void) { init_octopus(); ioport_set_pin_dir(STEP,IOPORT_DIR_OUTPUT); ioport_set_pin_dir(DIR,IOPORT_DIR_OUTPUT); ioport_set_pin_dir(SLEEP,IOPORT_DIR_OUTPUT); ioport_set_pin_dir(MS1,IOPORT_DIR_OUTPUT); ioport_set_pin_dir(MS2,IOPORT_DIR_OUTPUT); ioport_set_pin_dir(MS3,IOPORT_DIR_OUTPUT); ioport_set_pin_level(STEP,0); ioport_set_pin_level(DIR,0); ioport_set_pin_level(SLEEP,0); ioport_set_pin_level(MS1,0); ioport_set_pin_level(MS2,0); ioport_set_pin_level(MS3,0); initial_animation(); for (;;) { int direction; int step1; int step2; int step3; int step4; int step5; scanf("%1i%4x%4x%4x%4x%4x",&direction,&step1,&step2,&step3,&step4,&step5); move_stepper(direction,step1,step2,step3,step4,step5); if(switch_state(SW1) == 0) { ioport_set_pin_level(SLEEP,1); ioport_toggle_pin_level(DIR); full_step(); for(int i=1;i<1000;i++) { ioport_toggle_pin_level(STEP); delay_ms(1); } ioport_set_pin_level(SLEEP,0); move_stepper(1,300,0,0,0,0); // ioport_set_pin_level(LED1,1); // delay_ms(200); // ioport_set_pin_level(LED2,1); // delay_ms(200); // ioport_set_pin_level(LED3,1); // delay_ms(200); // ioport_set_pin_level(LED4,1); // delay_ms(200); // ioport_set_pin_level(LED5,1); // delay_ms(200); // ioport_set_pin_level(LED6,1); // delay_ms(200); } if(switch_state(SW2) == 0) { move_stepper(1,120,60,10,5,5); } } }