Drive a stepper motor using A4988 with asynchronous. No wait() function.
Diff: AsyncStepper.hpp
- Revision:
- 1:0f8209567b7d
- Parent:
- 0:26fa30c35f74
--- a/AsyncStepper.hpp Thu Jul 12 01:27:04 2018 +0000 +++ b/AsyncStepper.hpp Sat Jul 28 18:22:05 2018 +0000 @@ -17,6 +17,17 @@ #include "mbed.h" +/** + Disable all interuupts and save the status of interrupts. + This macro is usable at ONLY Cortex-M Series. +*/ +#define DISABLE_INTERRUPTS uint32_t primask = __get_PRIMASK(); __disable_irq() +/** + Enable all interuupts when the status of interrupts is ENABLED. + This macro is usable at ONLY Cortex-M Series. +*/ +#define RESTORE_INTERRUPTS if( !(primask & 1) ) __enable_irq() + using namespace std; enum stepMode_e { @@ -49,12 +60,13 @@ stopMode_e stopMode; uint32_t oneRotationSteps; uint64_t pulseWidth_us; - uint32_t halfPulseCount; - uint32_t currentMaxStepCount; - bool stopPulseOut; + volatile uint32_t halfPulseCount; + volatile uint32_t currentMaxStepCount; + volatile bool stopPulseOut; void ISR_PULSEOUT( void ); + public: /*! @brief Create a new AsyncStepper port.