Dependents: serial_connected_mcu_nucleo rotary_encoder_mbed serial_connected_mcu_nucleo omuni_speed_pid ... more
Fork of rotary_encoder by
このライブラリは以下のプログラムに基いています https://developer.mbed.org/users/gregeric/code/Nucleo_Hello_Encoder/
Revision 8:0a217d9f31c7, committed 2016-05-21
- Comitter:
- inst
- Date:
- Sat May 21 02:52:16 2016 +0000
- Parent:
- 7:3b51e2c660b6
- Child:
- 9:d1e6284a13ab
- Commit message:
- ;
Changed in this revision
--- a/rotary_encoder_abz_phase/rotary_encoder_abz_phase.cpp Sat May 21 02:50:07 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -#include "mbed.h" -#include "rotary_encoder_abz_phase.hpp" -#include "rotary_encoder_base.hpp" - -rotary_encoder_abz_phase::rotary_encoder_abz_phase(TIM_TypeDef* timer_type, PinName z_pin, size_t resolution) : - rotary_encoder_base(timer_type, TIM_ENCODERMODE_TI12, resolution), - z_phase_intr_(z_pin), - counts_in_prev_intr_(0) { - z_phase_intr_.fall(this, &rotary_encoder_abz_phase::intr_z_phase_first); -} - -int32_t rotary_encoder_abz_phase::get_counts() const { - int32_t counts = timer_handler_.Instance->CNT; - - if (counts > (max_counts_ >> 1)) { - return counts - max_counts_; - } - return counts; -} - -void rotary_encoder_abz_phase::intr_z_phase_first() { - counts_in_prev_intr_ = timer_handler_.Instance->CNT; - z_phase_intr_.fall(this, &rotary_encoder_abz_phase::intr_z_phase); -} - -void rotary_encoder_abz_phase::intr_z_phase() { - uint32_t counts = timer_handler_.Instance->CNT; - // Z相の割り込みが入る時は、前回とのカウントの差は分解能で割り切れるはず - int64_t error = (counts - counts_in_prev_intr_) % resolution_; - timer_handler_.Instance->CNT -= error; - - counts_in_prev_intr_ = counts; -} - -void rotary_encoder_abz_phase::reset() { - counts_in_prev_intr_ = 0; - timer_handler_.Instance->CNT = 0; -}
--- a/rotary_encoder_abz_phase/rotary_encoder_abz_phase.hpp Sat May 21 02:50:07 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -#ifndef INCLUDED_MBED_STL_ROTARY_ENCODER_ABZ_PHASE_H -#define INCLUDED_MBED_STL_ROTARY_ENCODER_ABZ_PHASE_H - -#include "rotary_encoder_base.hpp" -#include "mbed.h" - -class rotary_encoder_abz_phase : public rotary_encoder_base { -public: - rotary_encoder_abz_phase(TIM_TypeDef* timer_type, PinName z_pin, size_t resolution); - virtual ~rotary_encoder_abz_phase() {} - - virtual int32_t get_counts() const; - virtual void reset(); - -private: - void intr_z_phase_first(); - void intr_z_phase(); - - InterruptIn z_phase_intr_; - uint32_t counts_in_prev_intr_; -}; - -#endif