Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: serial_connected_mcu_nucleo rotary_encoder_mbed serial_connected_mcu_nucleo omuni_speed_pid ... more
Fork of rotary_encoder by
Revision 3:65021ea3fae5, committed 2016-03-31
- Comitter:
- inst
- Date:
- Thu Mar 31 04:42:31 2016 +0000
- Parent:
- 2:4580c3869b7b
- Child:
- 4:d07f58c46a79
- Commit message:
Changed in this revision
--- a/rotary_encoder_abz_phase/rotary_encoder_abz_phase.cpp Fri Feb 26 16:08:52 2016 +0000
+++ b/rotary_encoder_abz_phase/rotary_encoder_abz_phase.cpp Thu Mar 31 04:42:31 2016 +0000
@@ -12,7 +12,7 @@
}
int32_t rotary_encoder_abz_phase::get_counts() const {
- int32_t counts = timer_handler_->Instance->CNT;
+ int32_t counts = timer_handler_.Instance->CNT;
if (counts > (max_counts_ >> 1)) {
return counts - max_counts_;
@@ -21,22 +21,22 @@
}
void rotary_encoder_abz_phase::intr_z_phase_first() {
- counts_in_prev_intr_ = timer_handler_->Instance->CNT;
+ 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;
+ uint32_t counts = timer_handler_.Instance->CNT;
// Z相の割り込みが入る時は、前回とのカウントの差は分解能で割り切れるはず
int64_t error = (counts - counts_in_prev_intr_) % resolution_;
- timer_handler_->Instance->CNT -= error;
+ 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;
+ timer_handler_.Instance->CNT = 0;
}
} /* namespace mbed_stl */
--- a/rotary_encoder_abz_phase/rotary_encoder_abz_phase.hpp Fri Feb 26 16:08:52 2016 +0000
+++ b/rotary_encoder_abz_phase/rotary_encoder_abz_phase.hpp Thu Mar 31 04:42:31 2016 +0000
@@ -30,7 +30,6 @@
virtual ~rotary_encoder_abz_phase() {}
virtual int32_t get_counts() const;
-
virtual void reset();
private:
--- a/rotary_encoder_base/rotary_encoder_base.cpp Fri Feb 26 16:08:52 2016 +0000
+++ b/rotary_encoder_base/rotary_encoder_base.cpp Thu Mar 31 04:42:31 2016 +0000
@@ -1,22 +1,24 @@
#include "rotary_encoder_base.hpp"
#include "rotary_encoder.hpp"
+#include "mbed.h"
namespace mbed_stl {
rotary_encoder_base::rotary_encoder_base(TIM_TypeDef* timer_type,
uint32_t encoder_mode,
size_t resolution) : rotary_encoder(resolution) {
- TIM_Encoder_InitTypeDef encoder;
- timer_handler_ = new TIM_HandleTypeDef;
+ static size_t cnt = 0;
+ //printf("cnt : %d\n", cnt);
- timer_handler_->Instance = timer_type;
- timer_handler_->Init.Period = max_counts_;
- timer_handler_->Init.CounterMode = TIM_COUNTERMODE_UP;
- timer_handler_->Init.Prescaler = 0;
- timer_handler_->Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
-
+ timer_handler_.Instance = timer_type;
+ timer_handler_.Init.Period = max_counts_;
+ timer_handler_.Init.CounterMode = TIM_COUNTERMODE_UP;
+ timer_handler_.Init.Prescaler = 0;
+ timer_handler_.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
+
+ TIM_Encoder_InitTypeDef encoder;
encoder.EncoderMode = encoder_mode;
-
+
encoder.IC1Filter = 0x0F;
encoder.IC1Polarity = TIM_INPUTCHANNELPOLARITY_RISING;
encoder.IC1Prescaler = TIM_ICPSC_DIV4;
@@ -26,34 +28,41 @@
encoder.IC2Polarity = TIM_INPUTCHANNELPOLARITY_FALLING;
encoder.IC2Prescaler = TIM_ICPSC_DIV4;
encoder.IC2Selection = TIM_ICSELECTION_DIRECTTI;
-
- if (HAL_TIM_Encoder_Init(timer_handler_, &encoder) != HAL_OK) {
- error("couldn't init encoder\r\n");
+
+ ////////////////////////////////////////
+ //printf("t:%d, e:%d", &timer_handler_, &encoder);
+/*
+ if (HAL_TIM_Encoder_Init(&timer_handler_, &encoder) != HAL_OK) {
+ error("couldn't init encoder\n");
}
+*/
+ //printf("%d end\n", cnt++);
+ ///////////////////////////////////////////
}
+rotary_encoder_base::~rotary_encoder_base() {}
+
int32_t rotary_encoder_base::get_counts() const {
- int32_t counts = timer_handler_->Instance->CNT;
+ int32_t counts = timer_handler_.Instance->CNT;
if (counts > (max_counts_ >> 1)) {
return counts - max_counts_;
}
-
return counts;
}
void rotary_encoder_base::reset() {
- timer_handler_->Instance->CNT = 0;
+ timer_handler_.Instance->CNT = 0;
}
void rotary_encoder_base::start() {
- if(HAL_TIM_Encoder_Start(timer_handler_, TIM_CHANNEL_1) != HAL_OK) {
+ if(HAL_TIM_Encoder_Start(&timer_handler_, TIM_CHANNEL_1) != HAL_OK) {
error("couldn't start encoder\r\n");
}
}
void rotary_encoder_base::stop() {
- if(HAL_TIM_Encoder_Stop(timer_handler_, TIM_CHANNEL_1) != HAL_OK) {
+ if(HAL_TIM_Encoder_Stop(&timer_handler_, TIM_CHANNEL_1) != HAL_OK) {
error("couldn't start encoder\r\n");
}
}
--- a/rotary_encoder_base/rotary_encoder_base.hpp Fri Feb 26 16:08:52 2016 +0000
+++ b/rotary_encoder_base/rotary_encoder_base.hpp Thu Mar 31 04:42:31 2016 +0000
@@ -10,7 +10,7 @@
rotary_encoder_base(TIM_TypeDef* timer_type,
uint32_t encoder_mode,
size_t resolution);
- virtual ~rotary_encoder_base() {}
+ virtual ~rotary_encoder_base();
virtual int32_t get_counts() const;
@@ -19,7 +19,7 @@
virtual void stop();
protected:
- TIM_HandleTypeDef* timer_handler_;
+ TIM_HandleTypeDef timer_handler_;
};
