Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication...

36
Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communicatio n PhD. Kang, Won-Chan

Transcript of Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication...

Page 1: Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication PhD. Kang, Won-Chan.

Computer Interface (STEP Motor)

Chung-Buk HRD Institute of KCCIDept. of Information & Communication

PhD. Kang, Won-Chan

Page 2: Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication PhD. Kang, Won-Chan.

Computer Interface

ON

ON

Page 3: Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication PhD. Kang, Won-Chan.

Computer Interface

Page 4: Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication PhD. Kang, Won-Chan.

Computer Interface

A: Yellow

AVCC: Black

A: Red

B: Blue

AVCC: White

B: Orange

AVCC: 9~24V

6.4Ω

3.2Ω

3.2Ω

Page 5: Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication PhD. Kang, Won-Chan.

Computer Interface

Commercial versionL297 or GAL(16V8)

SLA7024AM

Page 6: Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication PhD. Kang, Won-Chan.

Computer Interface

Page 7: Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication PhD. Kang, Won-Chan.

Computer Interface

Page 8: Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication PhD. Kang, Won-Chan.

Computer Interface

D5 D4 D6D7Power

Page 9: Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication PhD. Kang, Won-Chan.

Computer Interface

1 Phase Control

SLA7024 Input

Data Address

1 Phase Method

Step 1 Step 2 Step 3 Step 4

A D4 1 0 0 0

/A D5 0 0 1 0

B D6 0 1 0 0

/B D7 0 0 0 1

Hex Value 0x01 0x04 0x02 0x08

Page 10: Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication PhD. Kang, Won-Chan.

Computer Interface

2 Phase Control

SLA7024 Input

Data Address

1 Phase Method

Step 1 Step 2 Step 3 Step 4

A D4 0 0 1 1

/A D5 1 1 0 0

B D6 1 0 0 1

/B D7 0 1 1 0

Hex Value 0x06 0x0a 0x09 0x05

Page 11: Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication PhD. Kang, Won-Chan.

Computer Interface

1-2 Phase Control

SLA7024 Input

Data Address

1-2 Phase Method

1 2 3 4 5 6 7 8

A D4 1 1 0 0 0 0 0 1

/A D5 0 0 0 1 1 1 0 0

B D6 0 1 1 1 0 0 0 0

/B D7 0 0 0 0 0 1 1 1

Hex Value 0x01 0x05

0x04

0x06

0x02 0x0a

0x08

0x09

Page 12: Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication PhD. Kang, Won-Chan.

Computer Interface

Example 1

Make a project MFC WizardDialog basedName: StepMotorInput Library: inpout32.libInput Function: timer()

Select hardwareSW4

Using CommandOut32(Port Address, Data)

Page 13: Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication PhD. Kang, Won-Chan.

Computer Interface

IDC_LEFT IDC_STOP IDC_RIGHT

IDC_EXIT

Page 14: Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication PhD. Kang, Won-Chan.

Computer Interface

Page 15: Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication PhD. Kang, Won-Chan.

Computer Interface

Page 16: Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication PhD. Kang, Won-Chan.

Computer Interface

Page 17: Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication PhD. Kang, Won-Chan.

Computer Interface

void CStepMotorDlg::OnLeft() {KillTimer(2);SetTimer(1,10,NULL); Out32(DataAdd,0x90);Sleep(SPEED);Out32(DataAdd,0x80);Sleep(SPEED);Out32(DataAdd,0xa0);Sleep(SPEED);Out32(DataAdd,0x20);Sleep(SPEED);Out32(DataAdd,0x60);Sleep(SPEED);Out32(DataAdd,0x40);Sleep(SPEED);Out32(DataAdd,0x50);Sleep(SPEED);Out32(DataAdd,0x10);Sleep(SPEED); }

void CStepMotorDlg::OnRight() {KillTimer(1);SetTimer(2,10,NULL);

Out32(DataAdd,0x10);Sleep(SPEED);Out32(DataAdd,0x50);Sleep(SPEED);Out32(DataAdd,0x60);Sleep(SPEED);Out32(DataAdd,0x40);Sleep(SPEED);Out32(DataAdd,0x20);Sleep(SPEED);Out32(DataAdd,0xa0);Sleep(SPEED);Out32(DataAdd,0x80);Sleep(SPEED);Out32(DataAdd,0x90);Sleep(SPEED); }

1-2 Phase Method

Page 18: Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication PhD. Kang, Won-Chan.

Computer Interface

void CStepMotorDlg::OnStop() {Out32(DataAdd, 0x00);KillTimer(1);KillTimer(2);}void CStepMotorDlg::OnExit() {MessageBox("STEP MOTOR CONTROL..");MessageBeep((WORD)-2);OnOK();}void CStepMotorDlg::OnTimer(UINT nIDEvent) {if(nIDEvent==1) {OnLeft();}if(nIDEvent==2) {OnRight();}CDialog::OnTimer(nIDEvent);}

Page 19: Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication PhD. Kang, Won-Chan.

Computer Interface

#include "stdafx.h"#include "StepMotor.h"#include "StepMotorDlg.h"#include "step.h"//#include "conio.h“

short _stdcall Inp32(short PortAddress);void _stdcall Out32(short PortAddress, short data);

#define DataAdd 0x378#define StatusAdd 0x379 #define ControlAdd 0x37a#define SPEED 2 //Change speed

// Value up: Low speed// Value down: High speed

Page 20: Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication PhD. Kang, Won-Chan.

Computer Interface

Page 21: Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication PhD. Kang, Won-Chan.

Computer Interface

Question

Change 1 Phase Method?

Change 2 Phase Method?

Page 22: Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication PhD. Kang, Won-Chan.

Computer Interface

Example 2

Make a project MFC WizardDialog basedName: StepMotor2Input Library: inpout32.libInput Function: timer()

Select hardwareSW4

Using CommandOut32(Port Address, Data)

Page 23: Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication PhD. Kang, Won-Chan.

Computer Interface

IDC_LEFT IDC_STOP IDC_RIGHT

IDC_EXITIDC_SLIDER1

IDC_value

Page 24: Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication PhD. Kang, Won-Chan.

Computer Interface

Page 25: Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication PhD. Kang, Won-Chan.

Computer Interface

Page 26: Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication PhD. Kang, Won-Chan.

Computer Interface

Page 27: Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication PhD. Kang, Won-Chan.

Computer Interface

Page 28: Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication PhD. Kang, Won-Chan.

Computer Interface

Page 29: Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication PhD. Kang, Won-Chan.

Computer Interface

void CStepMotor2Dlg::OnLeft() {KillTimer(2);SetTimer(1,10,NULL); Out32(DataAdd,0x90);Sleep(DELAY);Out32(DataAdd,0x80);Sleep(DELAY);Out32(DataAdd,0xa0);Sleep(DELAY);Out32(DataAdd,0x20);Sleep(DELAY);Out32(DataAdd,0x60);Sleep(DELAY);Out32(DataAdd,0x40);Sleep(DELAY);Out32(DataAdd,0x50);Sleep(DELAY);Out32(DataAdd,0x10);Sleep(DELAY); }

void CStepMotor2Dlg::OnRight() {KillTimer(1);SetTimer(2,10,NULL);

Out32(DataAdd,0x10);Sleep(DELAY);Out32(DataAdd,0x50);Sleep(DELAY);Out32(DataAdd,0x40);Sleep(DELAY);Out32(DataAdd,0x60);Sleep(DELAY);Out32(DataAdd,0x20);Sleep(DELAY);Out32(DataAdd,0xa0);Sleep(DELAY);Out32(DataAdd,0x80);Sleep(DELAY);Out32(DataAdd,0x90);Sleep(DELAY);}

1-2 Phase Method

Page 30: Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication PhD. Kang, Won-Chan.

Computer Interface

void CStepMotor2Dlg::OnOutofmemorySlider1(NMHDR* pNMHDR, LRESULT* pResult) {

*pResult = 0;}

void CStepMotor2Dlg::OnStop() {

Out32(DataAdd, 0x00); KillTimer(1);

KillTimer(2);}void CStepMotor2Dlg::OnTimer(UINT nIDEvent) {

if(nIDEvent==1){OnLeft();}if(nIDEvent==2){OnRight();}CDialog::OnTimer(nIDEvent);

}void CStepMotor2Dlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) {

CSliderCtrl* pSlider = (CSliderCtrl*)pScrollBar;SetDlgItemInt(IDC_value,pSlider->GetPos());DELAY = pSlider->GetPos();CDialog::OnHScroll(nSBCode, nPos, pScrollBar);

}

Page 31: Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication PhD. Kang, Won-Chan.

Computer Interface

void CStepMotor2Dlg::OnExit() {

KillTimer(1);KillTimer(2);MessageBox("STEP MOTOR CONTROL..");MessageBeep((WORD)-2);OnOK();

}===============================================CStepMotor2Dlg::CStepMotor2Dlg(CWnd* pParent /*=NULL*/)

: CDialog(CStepMotor2Dlg::IDD, pParent){

//{{AFX_DATA_INIT(CStepMotor2Dlg)m_slider1 = 0;m_value = _T("");//}}AFX_DATA_INITm_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

}void CStepMotor2Dlg::DoDataExchange(CDataExchange* pDX){

CDialog::DoDataExchange(pDX);//{{AFX_DATA_MAP(CStepMotor2Dlg)DDX_Slider(pDX, IDC_SLIDER1, m_slider1);DDX_Text(pDX, IDC_value, m_value);//}}AFX_DATA_MAP

}

Page 32: Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication PhD. Kang, Won-Chan.

Computer Interface

BOOL CStepMotor2Dlg::OnInitDialog(){

CDialog::OnInitDialog();

// Add "About..." menu item to system menu.

// IDM_ABOUTBOX must be in the system command range.ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);ASSERT(IDM_ABOUTBOX < 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE);if (pSysMenu != NULL){

CString strAboutMenu;strAboutMenu.LoadString(IDS_ABOUTBOX);if (!strAboutMenu.IsEmpty()){

pSysMenu->AppendMenu(MF_SEPARATOR);pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);

}}

CSliderCtrl* m_slider1 = (CSliderCtrl*)GetDlgItem(IDC_SLIDER1);DELAY=0;SetDlgItemInt(IDC_value,DELAY);m_slider1->SetRange(0,50);m_slider1->SetPos(5);

Page 33: Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication PhD. Kang, Won-Chan.

Computer Interface

// StepMotor2Dlg.cpp : implementation file//

#include "stdafx.h"#include "StepMotor2.h"#include "StepMotor2Dlg.h"//#include "conio.h"short _stdcall Inp32(short PortAddress);void _stdcall Out32(short PortAddress, short data);

#define DataAdd 0x378#define StatusAdd 0x379 #define ControlAdd 0x37a

Page 34: Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication PhD. Kang, Won-Chan.

Computer Interface

// StepMotor2Dlg.h : header file//

#if !defined(AFX_STEPMOTOR2DLG_H__E5468166_973D_11D5_AF0E_00C026DD8C89__INCLUDED_)#define AFX_STEPMOTOR2DLG_H__E5468166_973D_11D5_AF0E_00C026DD8C89__INCLUDED_

#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000

/////////////////////////////////////////////////////////////////////////////// CStepMotor2Dlg dialog

class CStepMotor2Dlg : public CDialog{// Constructionpublic:

int DELAY;CStepMotor2Dlg(CWnd* pParent = NULL); // standard constructor

// Dialog Data//{{AFX_DATA(CStepMotor2Dlg)enum { IDD = IDD_STEPMOTOR2_DIALOG };int m_slider1;CString m_value;//}}AFX_DATA

// ClassWizard generated virtual function overrides//{{AFX_VIRTUAL(CStepMotor2Dlg)protected:virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support//}}AFX_VIRTUAL

Page 35: Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication PhD. Kang, Won-Chan.

Computer Interface

Page 36: Computer Interface (STEP Motor) Chung-Buk HRD Institute of KCCI Dept. of Information & Communication PhD. Kang, Won-Chan.

END