Subversion Repositories Code-Repo

Rev

Rev 312 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 312 Rev 315
Line 1... Line 1...
1
#include "defines.h"
1
#include "defines.h"
2
#include "STEPPER.h"
2
#include "STEPPER.h"
-
 
3
#include "OLED_SSD1306.h"
-
 
4
 
-
 
5
static STEPPER_MICROSTEP currStep = STEP_1_1;
-
 
6
static STEPPER_SPEED currSpeed = DELAY_1000MS;
-
 
7
static uint8_t autoOn = 0;
3
 
8
 
4
void STEPPER_Set_Microstep(STEPPER_MICROSTEP step) {
9
void STEPPER_Set_Microstep(STEPPER_MICROSTEP step) {
5
#ifdef DVR8825
10
#ifdef DVR8825
6
    if (step == STEP_1_1) {
11
    if (step == STEP_1_1) {
7
        M0_LAT = 0;
12
        M0_LAT = 0;
Line 29... Line 34...
29
        M2_LAT = 1;
34
        M2_LAT = 1;
30
    }
35
    }
31
#endif
36
#endif
32
}
37
}
33
 
38
 
-
 
39
void STEPPER_Set_Next_Step() {
-
 
40
    switch (currStep) {
-
 
41
        case STEP_1_1:
-
 
42
            currStep = STEP_1_2;
-
 
43
            break;
-
 
44
        case STEP_1_2:
-
 
45
            currStep = STEP_1_4;
-
 
46
            break;
-
 
47
        case STEP_1_4:
-
 
48
            currStep = STEP_1_8;
-
 
49
            break;
-
 
50
        case STEP_1_8:
-
 
51
            currStep = STEP_1_16;
-
 
52
            break;
-
 
53
        case STEP_1_16:
-
 
54
            currStep = STEP_1_32;
-
 
55
            break;
-
 
56
        case STEP_1_32:
-
 
57
        default:
-
 
58
            currStep = STEP_1_1;
-
 
59
            break;
-
 
60
    }
-
 
61
    STEPPER_Set_Microstep(currStep);
-
 
62
}
-
 
63
 
-
 
64
STEPPER_MICROSTEP STEPPER_Get_Cur_Step(void) {
-
 
65
    return currStep;
-
 
66
}
-
 
67
 
34
void STEPPER_Set_Direction(char dir) {
68
void STEPPER_Set_Next_Delay() {
-
 
69
    switch (currSpeed) {
-
 
70
        default:
-
 
71
        case DELAY_1000MS:
-
 
72
            currSpeed = DELAY_500MS;
-
 
73
            break;
-
 
74
        case DELAY_500MS:
-
 
75
            currSpeed = DELAY_333MS;
-
 
76
            break;
-
 
77
        case DELAY_333MS:
-
 
78
            currSpeed = DELAY_250MS;
-
 
79
            break;
-
 
80
        case DELAY_250MS:
-
 
81
            currSpeed = DELAY_100MS;
-
 
82
            break;
-
 
83
        case DELAY_100MS:
-
 
84
            currSpeed = DELAY_50MS;
-
 
85
            break;
-
 
86
        case DELAY_50MS:
-
 
87
            currSpeed = DELAY_25MS;
-
 
88
            break;
-
 
89
        case DELAY_25MS:
-
 
90
            currSpeed = DELAY_10MS;
-
 
91
            break;
-
 
92
        case DELAY_10MS:
-
 
93
            currSpeed = DELAY_5MS;
-
 
94
            break;
-
 
95
        case DELAY_5MS:
-
 
96
            currSpeed = DELAY_1MS;
-
 
97
            break;
-
 
98
        case DELAY_1MS:
-
 
99
            currSpeed = DELAY_1000MS;
-
 
100
            break;
-
 
101
    }
-
 
102
}
-
 
103
 
-
 
104
STEPPER_SPEED STEPPER_Get_Cur_Speed(void) {
-
 
105
    return currSpeed;
-
 
106
}
-
 
107
 
-
 
108
void STEPPER_Toggle_Auto() {
35
    if (dir) {
109
    if (autoOn == 0) {
36
        DIR_LAT = 1;
110
        autoOn = 1;
37
    } else {
111
    } else {
38
        DIR_LAT = 0;
112
        autoOn = 0;
39
    }
113
    }
40
}
-
 
41
114
}
-
 
115
 
-
 
116
STEPPER_SPEED STEPPER_Get_Auto() {
-
 
117
    if (autoOn == 0) {
-
 
118
        return DELAY_STOPPED;
-
 
119
    } else {
-
 
120
        return currSpeed;
-
 
121
    }
-
 
122
}
-
 
123
 
-
 
124
void STEPPER_Step() {
-
 
125
    STEP_LAT = 1;
-
 
126
    __delay_us(2);
-
 
127
    STEP_LAT = 0;
-
 
128
}
-
 
129