2016-11-17 7 views
0

스테퍼 모터의 작동 방식을 22.5 도의 회전 각도로 시각화하는 스테퍼 모터 코드가 있습니다. 그래도 작동합니다. 하지만 대화식으로 만들려고합니다. 즉, 오른쪽 버튼을 클릭하면 모터가 그런 식으로 회전합니다. 완전한 생각이 아니며 제안에 개방적입니다. 아이디어가 있으십니까? 버튼으로스텝퍼 모터의 예를 대화 형으로 만드는 방법

편집 나는 하드 와이어드 버튼, 사용자 입력의 단지 어떤 형태를 의미하지 않는다. 그것은 마우스 클릭이나 키보드 누르거나 뭐든간에.

PS : 나는 EMU8086

코드를 사용하고 있습니다 :

; this is an example of out instruction. 
; it writes values to virtual i/o port 
; that controls the stepper-motor. 
; c:\emu8086\devices\stepper_motor.exe is on port 7 

#start=stepper_motor.exe# 


name "stepper" 

#make_bin# 

steps_before_direction_change = 10h ; 16 (decimal) 

jmp start 

; ========= data =============== 

; bin data for clock-wise 
; half-step rotation: 
datcw db 6 
     db 4 
     db 3 
     db 2 

; bin data for counter-clock-wise 
; half-step rotation: 
datccw db 3 
     db 1 
     db 6 
     db 2 


; bin data for clock-wise 
; full-step rotation: 
datcw_fs db 1 
     db 3 
     db 6 
     db 0 

; bin data for counter-clock-wise 
; full-step rotation: 
datccw_fs db 4 
      db 6 
      db 3 
      db 0 


start: 
mov bx, offset datcw ; start from clock-wise half-step. 
mov si, 0 
mov cx, 0 ; step counter 

next_step: 
; motor sets top bit when it's ready to accept new command 
wait: in al, 7  
     test al, 10000000b 
     jz wait 

mov al, [bx][si] 
out 7, al 

inc si 

cmp si, 4 
jb next_step 
mov si, 0 

inc cx 
cmp cx, steps_before_direction_change 
jb next_step 

mov cx, 0 
add bx, 4 ; next bin data 

cmp bx, offset datccw_fs 
jbe next_step 

mov bx, offset datcw ; return to clock-wise half-step. 

jmp next_step 
+0

당신은 키보드 입력을 의미합니까? 또는 8086 에뮬레이터에서 마우스 포인터 GUI를 구현하려고합니까? 키보드 또는 마우스 입력을 수락하는 것은 해당 입력 (즉, OUT 명령 실행)과 관련이 없으므로보다 적절한 질문 제목이됩니다. –

+1

@PeterCordes : EMU8086에는 스테퍼 모터, 버튼 생성 등을 수행하는 포트를 통해 액세스되는 가상 장치가 있습니다. –

답변

0

내가 제대로 이해한다면, 인터랙티브 모드에서 당신은 테이블 중 하나에서 4 배 out을 여전히 가지고있다.

그래서 어쩌면 같은 :

direction = ? 
step_type = 0/1 ; half/full 

input_loop: 

input = read buttons ; wait until some legal input is received 
    ; (not sure what you mean by "button", if real HW wire one, 
    ; then also debounce properly here) 

switch(input) { 
    toggle_step_type: step_type ^= 1; 
    right: direction = 0 
    left: direction = 1 
} 
table_address = datcw + direction*4 + step_type*8; 

... "play" the table from table_address as before, 
... but just one cycle (like cx = 1). 
... wait for the motor to be ready (current code would, so it's OK) 

go back to input_loop 
+0

그래서 내가 수집 한 것은 마우스 클릭이나 키보드 누르기와 같은 사용자 입력을 얻은 다음 모터가 그 방향으로 전체 또는 절반 단계? 특정 ASCII 입력에 특정 동작을 발생시키고 화살표 대신 WASD를 사용하게 할 수 있기 때문에 키보드에서 더 쉬울 수도 있습니다. 생각? –