|
@@ -70,14 +70,21 @@ void encoder_lock_position(bool enable) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+static __INLINE float _pll_over_comp(void) {
|
|
|
|
|
+ u8 dir = ENC_DIR_DOWN;
|
|
|
|
|
+#ifdef ENCODER_CC_INVERT
|
|
|
|
|
+ dir = ENC_DIR_UP;
|
|
|
|
|
+#endif
|
|
|
|
|
+ if(ENC_Direction() == dir){
|
|
|
|
|
+ return -((float)g_encoder.cpr);
|
|
|
|
|
+ }
|
|
|
|
|
+ return (float)g_encoder.cpr;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
static __INLINE void encoder_run_pll(float cnt) {
|
|
static __INLINE void encoder_run_pll(float cnt) {
|
|
|
float pll_comp = 0.0f;
|
|
float pll_comp = 0.0f;
|
|
|
if (g_encoder.b_timer_ov) {
|
|
if (g_encoder.b_timer_ov) {
|
|
|
- if(ENC_Direction() == ENC_DIR_DOWN){
|
|
|
|
|
- pll_comp = -((float)g_encoder.cpr);
|
|
|
|
|
- }else {
|
|
|
|
|
- pll_comp = g_encoder.cpr;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ pll_comp = _pll_over_comp();
|
|
|
g_encoder.b_timer_ov = false;
|
|
g_encoder.b_timer_ov = false;
|
|
|
}
|
|
}
|
|
|
encoder_pll_update_gain();
|
|
encoder_pll_update_gain();
|
|
@@ -85,14 +92,22 @@ static __INLINE void encoder_run_pll(float cnt) {
|
|
|
g_encoder.est_angle_counts = g_encoder.est_pll.observer;
|
|
g_encoder.est_angle_counts = g_encoder.est_pll.observer;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+static __INLINE u32 _abi_count(void) {
|
|
|
|
|
+#ifdef ENCODER_CC_INVERT
|
|
|
|
|
+ return (g_encoder.cpr - ENC_COUNT);
|
|
|
|
|
+#else
|
|
|
|
|
+ return ENC_COUNT;
|
|
|
|
|
+#endif
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
float encoder_get_theta(void) {
|
|
float encoder_get_theta(void) {
|
|
|
if (!g_encoder.b_index_found) {
|
|
if (!g_encoder.b_index_found) {
|
|
|
return g_encoder.pwm_angle;
|
|
return g_encoder.pwm_angle;
|
|
|
}
|
|
}
|
|
|
- u32 cnt = ENC_COUNT;
|
|
|
|
|
|
|
+ u32 cnt = _abi_count();
|
|
|
__NOP();__NOP();__NOP();__NOP();
|
|
__NOP();__NOP();__NOP();__NOP();
|
|
|
if (ENC_OverFlow()) {
|
|
if (ENC_OverFlow()) {
|
|
|
- cnt = ENC_COUNT;
|
|
|
|
|
|
|
+ cnt = _abi_count();
|
|
|
g_encoder.b_timer_ov = true;
|
|
g_encoder.b_timer_ov = true;
|
|
|
ENC_ClearUpFlags();
|
|
ENC_ClearUpFlags();
|
|
|
}
|
|
}
|