Subversion Repositories Code-Repo

Rev

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

Rev 315 Rev 316
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"
3
#include "OLED_SSD1306.h"
-
 
4
#include "ADC.h"
-
 
5
#include "TIMER.h"
4
 
6
 
5
static STEPPER_MICROSTEP currStep = STEP_1_1;
7
static STEPPER_MICROSTEP currStep = STEP_1_1;
6
static STEPPER_SPEED currSpeed = DELAY_1000MS;
-
 
7
static uint8_t autoOn = 0;
8
static uint8_t autoOn = 0;
8
 
9
 
9
void STEPPER_Set_Microstep(STEPPER_MICROSTEP step) {
10
void STEPPER_Set_Microstep(STEPPER_MICROSTEP step) {
10
#ifdef DVR8825
11
#ifdef DVR8825
11
    if (step == STEP_1_1) {
12
    if (step == STEP_1_1) {
Line 63... Line 64...
63
 
64
 
64
STEPPER_MICROSTEP STEPPER_Get_Cur_Step(void) {
65
STEPPER_MICROSTEP STEPPER_Get_Cur_Step(void) {
65
    return currStep;
66
    return currStep;
66
}
67
}
67
 
68
 
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() {
69
void STEPPER_Toggle_Auto() {
109
    if (autoOn == 0) {
70
    if (autoOn == 0) {
-
 
71
        // Turn on automatic stepping
-
 
72
        TIMER_2_Init(STEPPER_Step);
-
 
73
        TIMER_2_Set_Delay((ADC_Read(POT_ADC_CHANNEL) >> 4) + 1);
-
 
74
        TIMER_2_Start();
110
        autoOn = 1;
75
        autoOn = 1;
111
    } else {
76
    } else {
-
 
77
        // Turn off automatic stepping
-
 
78
        TIMER_2_Stop();
112
        autoOn = 0;
79
        autoOn = 0;
113
    }
80
    }
114
}
81
}
115
 
82
 
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() {
83
void STEPPER_Step() {
-
 
84
    // Toggle step pin
125
    STEP_LAT = 1;
85
    STEP_LAT = 1;
126
    __delay_us(2);
86
    __delay_us(2);
127
    STEP_LAT = 0;
87
    STEP_LAT = 0;
-
 
88
    // Set the timer delay for the next step
-
 
89
    TIMER_2_Set_Delay((ADC_Read(POT_ADC_CHANNEL) >> 4) + 1);
128
}
90
}