add sincos encoder input (hacky)

This commit is contained in:
Oskar Weigl
2019-01-29 23:17:27 -08:00
parent 3eea1b2a90
commit a169dd33f0
2 changed files with 16 additions and 1 deletions
+14
View File
@@ -277,6 +277,20 @@ bool Encoder::update() {
}
}
} break;
case MODE_SINCOS: {
float c = get_adc_voltage(GPIO_3_GPIO_Port, GPIO_3_Pin) / 3.3f;
float s = get_adc_voltage(GPIO_4_GPIO_Port, GPIO_4_Pin) / 3.3f;
float phase = fast_atan2(s, c);
int fake_count = (int)(1000.0f * phase);
//CPR = 6283 = 2pi * 1k
delta_enc = fake_count - count_in_cpr_;
delta_enc = mod(delta_enc, 6283);
if (delta_enc > 6283/2)
delta_enc -= 6283;
} break;
default: {
set_error(ERROR_UNSUPPORTED_ENCODER_MODE);
+2 -1
View File
@@ -19,7 +19,8 @@ public:
enum Mode_t {
MODE_INCREMENTAL,
MODE_HALL
MODE_HALL,
MODE_SINCOS
};
struct Config_t {