handle S1000 on its own line
[clinton/Smoothieware.git] / src / modules / tools / spindle / Spindle.h
1 /*
2 This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl).
3 Smoothie is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
4 Smoothie is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
5 You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>.
6 */
7
8 #ifndef SPINDLE_MODULE_H
9 #define SPINDLE_MODULE_H
10
11 #include "libs/Module.h"
12 #include <stdint.h>
13
14 namespace mbed {
15 class PwmOut;
16 class InterruptIn;
17 }
18
19 // This module implements closed loop PID control for spindle RPM.
20 class Spindle: public Module {
21 public:
22 Spindle();
23 virtual ~Spindle() {};
24 void on_module_loaded();
25
26
27 private:
28 void on_pin_rise();
29 void on_gcode_received(void *argument);
30 uint32_t on_update_speed(uint32_t dummy);
31
32 mbed::PwmOut *spindle_pin; // PWM output for spindle speed control
33 mbed::InterruptIn *feedback_pin; // Interrupt pin for measuring speed
34 bool output_inverted;
35
36 // Current values, updated at runtime
37 bool spindle_on;
38 float current_rpm;
39 float target_rpm;
40 float current_I_value;
41 float prev_error;
42 float current_pwm_value;
43 int time_since_update;
44 uint32_t last_irq;
45
46 // Values from config
47 float pulses_per_rev;
48 float control_P_term;
49 float control_I_term;
50 float control_D_term;
51 float smoothing_decay;
52
53 // These fields are updated by the interrupt
54 uint32_t last_edge; // Timestamp of last edge
55 volatile uint32_t last_time; // Time delay between last two edges
56 volatile uint32_t irq_count;
57 };
58
59 #endif
60