fix setEncoderCount wrong TIM bug

This commit is contained in:
Oskar Weigl
2018-01-26 20:19:32 -08:00
parent 13deca5394
commit 4d7c3b92e3
3 changed files with 15 additions and 12 deletions
+5 -5
View File
@@ -16,16 +16,16 @@
"${workspaceRoot}/Drivers/CMSIS/Include",
"${workspaceRoot}/Inc",
"${workspaceRoot}/MotorControl",
"C:/Program Files (x86)/GNU Tools ARM Embedded/6 2017-q1-update/arm-none-eabi/include",
"C:/Program Files (x86)/GNU Tools ARM Embedded/6 2017-q1-update/arm-none-eabi/include/c++/6.3.1",
"C:/Program Files (x86)/GNU Tools ARM Embedded/6 2017-q1-update/arm-none-eabi/include/c++/6.3.1/arm-none-eabi",
"C:/Program Files (x86)/GNU Tools ARM Embedded/6 2017-q1-update/lib/gcc/arm-none-eabi/6.3.1/include"
"C:/Program Files (x86)/GNU Tools ARM Embedded/6 2017-q1-update/lib/gcc/arm-none-eabi/6.3.1/include",
"C:/Program Files (x86)/GNU Tools ARM Embedded/6 2017-q1-update/arm-none-eabi/include"
],
"defines": [
"_DEBUG",
"UNICODE"
],
"intelliSenseMode": "msvc-x64",
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"${workspaceRoot}",
@@ -69,7 +69,7 @@
"_DEBUG",
"UNICODE"
],
"intelliSenseMode": "msvc-x64",
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"${workspaceRoot}",
@@ -115,7 +115,7 @@
"_DEBUG",
"UNICODE"
],
"intelliSenseMode": "msvc-x64",
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"${workspaceRoot}",
+8 -5
View File
@@ -350,7 +350,9 @@ void init_motor_control() {
// Start Encoders
HAL_TIM_Encoder_Start(&htim3, TIM_CHANNEL_ALL);
HAL_TIM_Encoder_Start(&htim4, TIM_CHANNEL_ALL);
SetupENCIndexGPIO();
if (ENC_USE_INDEX_PIN) {
SetupENCIndexGPIO();
}
// Wait for current sense calibration to converge
// TODO make timing a function of calibration filter tau
@@ -533,9 +535,10 @@ void step_cb(uint16_t GPIO_Pin) {
// Triggered when an encoder passes over the "Index" pin
void enc_index_cb(uint16_t GPIO_Pin, uint8_t motor_index) {
if (!motors[motor_index].encoder.index_found) {
setEncoderCount(&motors[motor_index], 0);
motors[motor_index].encoder.index_found = true;
Motor_t* motor = &motors[motor_index];
if (!motor->encoder.index_found) {
setEncoderCount(motor, 0);
motor->encoder.index_found = true;
}
//TODO: Hardcoded EXTI line not portable. Get mapping out of Cubemx by setting EXTI default
if(GPIO_Pin == M0_ENC_Z_Pin){
@@ -1072,7 +1075,7 @@ void setEncoderCount(Motor_t* motor, uint32_t count) {
uint32_t prim = __get_PRIMASK();
__disable_irq();
motor->encoder.encoder_state = count;
motor->motor_timer->Instance->CNT = count;
motor->encoder.encoder_timer->Instance->CNT = count;
motor->encoder.pll_pos = (float)count;
__set_PRIMASK(prim);
}
+2 -2
View File
@@ -203,7 +203,7 @@ void SetupENCIndexGPIO(){
GPIO_InitStruct.Pin = M0_ENC_Z_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
HAL_GPIO_Init(M0_ENC_Z_GPIO_Port, &GPIO_InitStruct);
//TODO: Hardcoded EXTI line not portable. Get mapping out of Cubemx by setting EXTI default
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0);
@@ -213,7 +213,7 @@ void SetupENCIndexGPIO(){
GPIO_InitStruct.Pin = M1_ENC_Z_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
HAL_GPIO_Init(M1_ENC_Z_GPIO_Port, &GPIO_InitStruct);
//TODO: Hardcoded EXTI line not portable. Get mapping out of Cubemx by setting EXTI default
HAL_NVIC_SetPriority(EXTI3_IRQn, 0, 0);