Revision ca9f6bd5 scout_avr/src/stepper.cpp

View differences:

scout_avr/src/stepper.cpp
13 13

  
14 14
struct step_t {
15 15
  unsigned int speed; // time between steps in ms for sweep. Mininum 40ms
16
  unsigned int sweep_us; //time between calls to sweep  
16
  unsigned int sweep_ms; //time between calls to sweep  
17 17
  unsigned int time;
18 18
  int pos; // position in rotation.
19 19
  int dir; // direction. -1 CCW. 1 CW. 0 OFF
......
22 22
} volatile step;
23 23

  
24 24

  
25
func step_init(unsigned int call_us)
25
func step_init(unsigned int call_ms)
26 26
{
27 27
  /* set update time for sweep */
28
  step.sweep_us = call_us;
28
  step.sweep_ms = call_ms;
29 29
  
30 30
  /* init pos, time, and dir to 0 */
31 31
  step.pos = 0;
......
97 97
/* tick every speed ms in sweep mode */
98 98
void step_sweep_speed(unsigned int speed)
99 99
{
100
  if(speed<40) step.speed = 40000;
101
  else step.speed = speed*1000;
100
  if(speed<40) step.speed = 40;
101
  else step.speed = speed;
102 102
}
103 103

  
104 104

  
......
111 111

  
112 112
void step_sweep()
113 113
{
114
  step.time += step.sweep_us;
114
  step.time += step.sweep_ms;
115 115
  if(step.time >= step.speed)
116 116
  {
117
    step_halfstep();
118
    if((step.dir == 1) && (step.cw <= step.pos)) step.dir=-1;
119
    else if((step.dir == -1) && (step.ccw >= step.pos)) step.dir=1;
117
    step_fullstep();
118
    if((step.dir == 1) && (step.cw <= step.pos)) step_dir(-1);
119
    else if((step.dir == -1) && (step.ccw >= step.pos)) step_dir(1);
120
    step.time = 0;
120 121
  }
121 122
}

Also available in: Unified diff