![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
This is probably never gonna get done
Diff: main.cpp
- Revision:
- 12:899cd6bf9844
- Parent:
- 10:a4b5723b6c9d
- Child:
- 13:c51d828531d5
diff -r 7286f0c07086 -r 899cd6bf9844 main.cpp --- a/main.cpp Thu Feb 28 10:44:25 2019 +0000 +++ b/main.cpp Thu Feb 28 11:52:05 2019 +0000 @@ -23,6 +23,9 @@ #define MCSPpin A1 #define MCSNpin A0 +int8_t motorHome(); +inline int8_t readRotorState(); +void motorOut(int8_t driveState); //Mapping from sequential drive states to motor phase outputs /* State L1 L2 L3 @@ -49,9 +52,11 @@ DigitalOut led1(LED1); //Photointerrupter inputs -DigitalIn I1(I1pin); -DigitalIn I2(I2pin); -DigitalIn I3(I3pin); +InterruptIn I1(I1pin); +InterruptIn I2(I2pin); +InterruptIn I3(I3pin); + + //Motor Drive outputs DigitalOut L1L(L1Lpin); @@ -61,6 +66,21 @@ DigitalOut L3L(L3Lpin); DigitalOut L3H(L3Hpin); +int8_t orState = 0; //Rotot offset at motor state 0 +int8_t intState = 0; +int8_t intStateOld = 0; + +//interrupt function +void push(){ + //Poll the rotor state and set the motor outputs accordingly to spin the motor + intState = readRotorState(); + if (intState != intStateOld) { + intStateOld = intState; + motorOut((intState-orState+lead+6)%6); //+6 to make sure the remainder is positive + //pc.printf("%d\n\r",intState); + } +} + //Set a given drive state void motorOut(int8_t driveState){ @@ -101,10 +121,6 @@ //Main int main() { - int8_t orState = 0; //Rotot offset at motor state 0 - int8_t intState = 0; - int8_t intStateOld = 0; - //Initialise the serial port Serial pc(SERIAL_TX, SERIAL_RX); pc.printf("Hello\n\r"); @@ -114,14 +130,8 @@ pc.printf("Rotor origin: %x\n\r",orState); //orState is subtracted from future rotor state inputs to align rotor and motor states - //Poll the rotor state and set the motor outputs accordingly to spin the motor - while (1) { - intState = readRotorState(); - if (intState != intStateOld) { - intStateOld = intState; - motorOut((intState-orState+lead+6)%6); //+6 to make sure the remainder is positive - //pc.printf("%d\n\r",intState); - } - } + I1.rise(&push); + I2.rise(&push); + I3.rise(&push); }