뉴티씨



  • HOME
  • 고객지원
  • 질문답변


 
안녕하세요 스테핑모터 코딩관련하여 질문드립니다.
 글쓴이 : 전운성
작성일 : 19-05-17 17:22
조회 : 44  
- 스텝모터 : SE-SM9K
- 스텝모터드라이버 : AM-MS2
- mcu : ATmega128a-AU
- 사용 프로그램 : ATMEL STUDIO 7

현재 뉴티씨에서 얻은 코딩값으로 스텝모터 2개 까지는 테스트 성공했습니다.

혹시 4개의 스텝모터를 돌릴려면 코딩 값 어느 부분을 수정해야될까요?

#include <avr/io.h>
#include <avr/interrupt.h>

#define MOTOR_PORT PORTA
#define MOTOR_PORT_DDR DDRA
#define MOTOR_PORT PORTB
#define MOTOR_PORT_DDR DDRB

void port_init(void)
{
PORTA = 0xff;
DDRA  = 0xff;
PORTB = 0xff;
DDRB = 0xff;
}

//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
cli(); //disable all interrupts
XMCRA = 0x00; //external memory
XMCRB = 0x00; //external memory

port_init();

MCUCR = 0x00;
EICRA = 0x00; //extended ext ints
EICRB = 0x00; //extended ext ints
EIMSK = 0x00;
TIMSK = 0x00; //timer interrupt sources
ETIMSK = 0x00; //extended timer interrupt sources

sei(); //re-enable interrupts
//all peripherals are now initialized
}

/* Stepping Motor derive---------------------------*/
unsigned char  LEFTmotorOneClock(unsigned char step, char dir)
{
step = step & 0x0f;
if(dir){
switch(step){
case 0x09: step=0x01; break;
case 0x01: step=0x03; break;
case 0x03: step=0x02; break;
case 0x02: step=0x06; break;
case 0x06: step=0x04; break;
case 0x04: step=0x0c; break;
case 0x0c: step=0x08; break;
case 0x08: step=0x09; break;
default: step=0x0c; break;
}
}else{
switch(step){
case 0x09: step=0x08; break;
case 0x01: step=0x09; break;
case 0x03: step=0x01; break;
case 0x02: step=0x03; break;
case 0x06: step=0x02; break;
case 0x04: step=0x06; break;
case 0x0c: step=0x04; break;
case 0x08: step=0x0c; break;
default: step=0x0c; break;
}
}
return step;

}

/* Stepping Motor derive---------------------------*/
unsigned char  RIGHTmotorOneClock(unsigned char step, char dir)
{
step = step & 0xf0;
if(dir){
switch(step){
case 0x90: step=0x10; break;
case 0x10: step=0x30; break;
case 0x30: step=0x20; break;
case 0x20: step=0x60; break;
case 0x60: step=0x40; break;
case 0x40: step=0xc0; break;
case 0xc0: step=0x80; break;
case 0x80: step=0x90; break;
default: step=0xc0; break;
}
}else{
switch(step){
case 0x90: step=0x80; break;
case 0x10: step=0x90; break;
case 0x30: step=0x10; break;
case 0x20: step=0x30; break;
case 0x60: step=0x20; break;
case 0x40: step=0x60; break;
case 0xc0: step=0x40; break;
case 0x80: step=0xc0; break;
default: step=0xc0; break;
}
}
return step;
}

void delay(int n)
{
volatile int i,j;
for(i=1;i<n;i++)
{
for(j=1;j<100;j++);
}
}

int main(void)
{
volatile unsigned char stepleft=0, stepright=0;

init_devices();

MOTOR_PORT_DDR = 0xff;
while(1){

stepright = RIGHTmotorOneClock(stepright, 50);
stepleft = LEFTmotorOneClock(stepleft, 50);
delay(3);
MOTOR_PORT = stepleft|stepright;
}
return 0;
}