2017-12-19 2 views
0

28BYJ-48 Stepper Motor가 회전의 1/4을 회전하고 멈추도록하려고하는데 코드에서이를 구현하는 데 문제가 있습니다. 내가 찾은 것은 내가 코드에서 숫자를 작게 만들거나 그것이 제대로 작동 할 것이라고 생각하게하는 방법으로 그것을 변경하는 것입니다. 회전을 멈추게 할 수는 없습니다. 아래는 코드의 유용한 부분입니다. Stepper_Seek 여기에 호출되는Stepper Motor가 회전을 멈추지 않습니다

#define STEPPER (*((volatile uint32_t *)0x4000703C)) 

// Move 1.8 degrees clockwise, delay is the time to wait after each step 
void Stepper_CW(uint32_t delay) { 
    Pt = Pt->Next[clockwise];  // circular 
    STEPPER = Pt->Out; // step motor 

    if(Pos==199) {  // shaft angle 
    Pos = 0;   // reset 
    } 
    else { 
    Pos--; // CW 
    } 
SysTick_Wait(delay); 
} 

// Move 1.8 degrees counterclockwise, delay is wait after each step 
void Stepper_CCW(uint32_t delay) { 
    Pt = Pt->Next[counterclockwise]; // circular 
    STEPPER = Pt->Out; // step motor 
    if(Pos==0) {  // shaft angle 
    Pos = 199;   // reset 
    } 
    else { 
    Pos++; // CCW 
    } 
SysTick_Wait(delay); // blind-cycle wait 
} 

// Initialize Stepper interface 
void Stepper_Init(void) { 
    SYSCTL_RCGCGPIO_R |= 0x08; // 1) activate port D 
    SysTick_Init(); 
    Pos = 0;     
    Pt = &fsm[0]; 
           // 2) no need to unlock PD3-0 
    GPIO_PORTD_AMSEL_R &= ~0x0F;  // 3) disable analog functionality on PD3-0 
    GPIO_PORTD_PCTL_R &= ~0x0000FFFF; // 4) GPIO configure PD3-0 as GPIO 
    GPIO_PORTD_DIR_R |= 0x0F;    // 5) make PD3-0 out 
    GPIO_PORTD_AFSEL_R &= ~0x0F;   // 6) disable alt funct on PD3-0 
    GPIO_PORTD_DR8R_R |= 0x0F;   // enable 8 mA drive 
    GPIO_PORTD_DEN_R |= 0x0F;   // 7) enable digital I/O on PD3-0 
} 

// Turn stepper motor to desired position 
// (0 <= desired <= 199) 
// time is the number of bus cycles to wait after each step 
void Stepper_Seek(uint8_t desired, uint32_t time) { 
short CWsteps; 
    if((CWsteps = (desired-Pos))<0) { 
    CWsteps+=200; 
    } 

// CW steps is > 100 
if(CWsteps > 100) { 
    while(desired != Pos) { 
    Stepper_CCW(time); 
    } 
} 
else { 
    while(desired != Pos) { 
    Stepper_CW(time); 
    } 
} 
} 

...

#include <stdint.h> 
#include "stepper.h" 
#define T1ms 16000 // assumes using 16 MHz PIOSC (default setting for clock source) 
int main(void) { 
    Stepper_Init(); 
    Stepper_CW(T1ms); // Pos=1; GPIO_PORTD_DATA_R=9 
    Stepper_CW(T1ms); // Pos=2; GPIO_PORTD_DATA_R=5 
    Stepper_CW(T1ms); // Pos=3; GPIO_PORTD_DATA_R=6 
    Stepper_CW(T1ms); // Pos=4; GPIO_PORTD_DATA_R=10 
    Stepper_CW(T1ms); // Pos=5; GPIO_PORTD_DATA_R=9 
    Stepper_CW(T1ms); // Pos=6; GPIO_PORTD_DATA_R=5 
    Stepper_CW(T1ms); // Pos=7; GPIO_PORTD_DATA_R=6 
    Stepper_CW(T1ms); // Pos=8; GPIO_PORTD_DATA_R=10 
    Stepper_CW(T1ms); // Pos=9; GPIO_PORTD_DATA_R=9 
    Stepper_CCW(T1ms); // Pos=8; GPIO_PORTD_DATA_R=10 
    Stepper_CCW(T1ms); // Pos=7; GPIO_PORTD_DATA_R=6 
    Stepper_CCW(T1ms); // Pos=6; GPIO_PORTD_DATA_R=5 
    Stepper_CCW(T1ms); // Pos=5; GPIO_PORTD_DATA_R=9 
    Stepper_CCW(T1ms); // Pos=4; GPIO_PORTD_DATA_R=10 
    Stepper_Seek(8,T1ms);// Pos=8; GPIO_PORTD_DATA_R=10 
    Stepper_Seek(0,T1ms);// Pos=0; GPIO_PORTD_DATA_R=10 
    while(1) { 
    Stepper_CW(10*T1ms); // output every 10ms 
    } 
} 

나는 그것의 위치를 ​​재설정하고 다시 설정 한 후 다시 시작 유지하지만 그것은 수 있었다 생각도 줄을 주석 후에는 않을 것 고치다.

미리 감사드립니다.

+0

이 스테퍼 기능을 어떻게 사용하고 있는지 보여주는 코드를 게시 할 수 있습니까 (예 : 'Stepper_Seek'가 호출되는 곳 등)? – DigitalNinja

+0

'Pos'를 업데이트하는 곳에서 output/debug 문을 추가하고'desired'와 비교하십시오. 'CW steps is 0 to 199' 그리고'CWsteps'를 100으로 비교하는 주석을 가지고 있습니다. 그냥 붉은 깃발 ..... – KevinDTimm

+0

롤오버 로직은 거꾸로됩니다. Pos - 0에 도달하기위한 검사와 일치해야합니다. Pos ++는 199에 도달했는지 확인해야합니다. –

답변

1

귀하의 랩 어라운드 로직은 Stepper_CW()Stepper_CCW() 모두 역순입니다. 예를 들어 본다. 당신이 198에 도달하기 위해 노력하고 있다고 가정하고, Pos 처음에 1 :

  1. 을 첫 번째 통화에서 Pos이 198 불평등은 0으로 감소되기 때문에 함수가 다시 호출된다.
  2. 두 번째 호출에서 Pos이 199로 감소합니다.이 값은 198와 같지 않으므로 함수가 다시 호출됩니다. 공정 후의 상태 (3)와 동일하다 ....

제 호에서

  • 는 랩 어라운드 경우를 트리거하고 Pos이 198 불평등은 0으로 설정된다 단계 (1) 이후의 상태 - 무한 루프.

    관련 문제