뉴티씨



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


 
다시한번 질문드리겠습니다.
 글쓴이 : 관리자
작성일 : 19-05-21 16:43
조회 : 102  

안녕하세요 고객님,
저희 뉴티씨 제품을 이용하여 주셔서 감사합니다.

동그라미로 표기한 부분의 매개변수를 전부 똑같이 넘겨주기 때문에 그런 겁니다.

고객님이 원하시는대로 방향을 선택하시고 넘겨주셔야 따로 돌겠죠.
아래와 같이 매개변수를 약간씩 변경해서 돌려보시면 감이 오실겁니다.

    > volatile unsigned char stepleft_A = 30, stepright_A = 50,
    >                               stepleft_B = 30, stepright_B = 50;
   
    > stepleft_A = LEFTmotorOneClock(stepleft_A, 0);
    > stepright_A = RIGHTmotorOneClock(stepright_A, 1);
    > stepleft_B = LEFTmotorOneClock(stepleft_B, 0);
    > stepright_B = RIGHTmotorOneClock(stepright_B, 1);


감사합니다.

>
>
> 바쁘신데 죄송합니다.
>
> 말씀하신것처럼 프로그램을 변경하였습니다.
>
>
> 전체 프로그램
>
> #include <avr/io.h>
> #include <avr/interrupt.h>
>
> #define MOTOR_PORTA PORTA
> #define MOTOR_PORTA_DDR DDRA
> #define MOTOR_PORTB      PORTB
> #define MOTOR_PORTB_DDR  DDRB
>
>
> void port_init(void)
> {
> PORTA = 0x00;
> DDRA  = 0xff;
> PORTB = 0x00;
> 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=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;
> }
> }
> 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=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;
> }
> }
> 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_A = 50, stepright_A = 50,
>                               stepleft_B = 50, stepright_B = 50;
>
> init_devices();
>
> MOTOR_PORTA_DDR = 0xff;
> MOTOR_PORTB_DDR = 0xff;
>
> while(1){
>
> stepleft_A = LEFTmotorOneClock(stepleft_A, 1);
> stepright_A = RIGHTmotorOneClock(stepright_A, 1);
>
> stepleft_B = LEFTmotorOneClock(stepleft_B, 1);
> stepright_B = RIGHTmotorOneClock(stepright_B, 1);
>
> delay(3);
>
> MOTOR_PORTA = stepleft_A|stepright_A;
> MOTOR_PORTB = stepleft_B|stepright_B;
> }
> }
>
>
>
>
> =======================================================
>
> 여기서
>
> volatile unsigned char stepleft_A = 50, stepright_A = 50,
>                               stepleft_B = 50, stepright_B = 50;
>
> init_devices();
>
> MOTOR_PORTA_DDR = 0xff;
> MOTOR_PORTB_DDR = 0xff;
>
> while(1){
>
> stepleft_A = LEFTmotorOneClock(stepleft_A, 1);
> stepright_A = RIGHTmotorOneClock(stepright_A, 1);
>
> stepleft_B = LEFTmotorOneClock(stepleft_B, 1);
> stepright_B = RIGHTmotorOneClock(stepright_B, 1);
>
> delay(3);
>
> MOTOR_PORTA = stepleft_A|stepright_A;
> MOTOR_PORTB = stepleft_B|stepright_B;
> }
> }
>
> 이 부분만 임의로 제가 수정을 하였지만 모터의 회전 방향이 변화가 없었습니다.
>
> 코딩이 잘못되었나요??
>