Subversion Repositories Code-Repo

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
312 Kevin 1
#include "defines.h"
2
#include "STEPPER.h"
315 Kevin 3
#include "OLED_SSD1306.h"
312 Kevin 4
 
315 Kevin 5
static STEPPER_MICROSTEP currStep = STEP_1_1;
6
static STEPPER_SPEED currSpeed = DELAY_1000MS;
7
static uint8_t autoOn = 0;
8
 
312 Kevin 9
void STEPPER_Set_Microstep(STEPPER_MICROSTEP step) {
10
#ifdef DVR8825
11
    if (step == STEP_1_1) {
12
        M0_LAT = 0;
13
        M1_LAT = 0;
14
        M2_LAT = 0;
15
    } else if (step == STEP_1_2) {
16
        M0_LAT = 1;
17
        M1_LAT = 0;
18
        M2_LAT = 0;
19
    } else if (step == STEP_1_4) {
20
        M0_LAT = 0;
21
        M1_LAT = 1;
22
        M2_LAT = 0;
23
    } else if (step == STEP_1_8) {
24
        M0_LAT = 1;
25
        M1_LAT = 1;
26
        M2_LAT = 0;
27
    } else if (step == STEP_1_16) {
28
        M0_LAT = 0;
29
        M1_LAT = 0;
30
        M2_LAT = 1;
31
    } else if (step == STEP_1_32) {
32
        M0_LAT = 1;
33
        M1_LAT = 0;
34
        M2_LAT = 1;
35
    }
36
#endif
37
}
38
 
315 Kevin 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
 
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() {
109
    if (autoOn == 0) {
110
        autoOn = 1;
312 Kevin 111
    } else {
315 Kevin 112
        autoOn = 0;
312 Kevin 113
    }
315 Kevin 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
}