![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
First Commit
Dependencies: mbed Crypto_light mbed-rtos
Spin it 2 win it
Diff: main.cpp
- Revision:
- 18:05e5d280a082
- Parent:
- 17:80159ace5ddf
- Child:
- 19:526fd700e1b3
--- a/main.cpp Tue Mar 20 14:49:51 2018 +0000 +++ b/main.cpp Tue Mar 20 15:00:09 2018 +0000 @@ -21,6 +21,7 @@ #define CHAR_ARR_SIZE 18 //Max length of input codes #define MAX_PWM_PERIOD 2000 +#define MAX_TORQUE 1000 //Mapping from sequential drive states to motor phase outputs /* @@ -45,10 +46,10 @@ const int8_t lead = 2; //2 for forwards, -2 for backwards //Rotor offset at motor state 0 -int8_t orState = 0; +volatile int8_t orState = 0; //Set initial torque of 1000 -uint32_t torque = 1000; +volatile uint32_t torque = 1000; enum MSG {MSG_RESET, MSG_HASHCOUNT, MSG_NONCE_OK, @@ -230,7 +231,7 @@ //Basic synchronisation routine int8_t motorHome() { //Put the motor in drive state 0 and wait for it to stabilise - motorOut(0, MAX_PWM_PERIOD); + motorOut(0, MAX_TORQUE); wait(2.0); //Get the rotor state @@ -269,6 +270,11 @@ I2.fall(&photointerrupter_isr); I3.fall(&photointerrupter_isr); + + L1L.period_us(MAX_PWM_PERIOD); + L2L.period_us(MAX_PWM_PERIOD); + L3L.period_us(MAX_PWM_PERIOD); + //Calling the ISR once starts the motor movement photointerrupter_isr();