bgkatz / motorcontrol

motor controller firmware
MIT License
239 stars 102 forks source link

hw_config incompatible with old mbed code #8

Closed MaximilianKoestler closed 2 years ago

MaximilianKoestler commented 2 years ago

Hi,

I have started comparing the code in this repository with the old mbed code, specifically with this revision: https://os.mbed.com/users/benkatz/code/Hobbyking_Cheetah_Compact_DRV8323/

This is part of an effort to port an existing modified variant over the version in this repository.

Before testing anything, I have spotted several changes to the pinout of the STM32 that left me puzzled:

Different Timer Connections

This is how the timers are currently set up in hw_config.h:

#define TIM_CH_U        TIM_CHANNEL_1       // Terminal U timer channel
#define TIM_CH_V        TIM_CHANNEL_2       // Terminal V timer channel
#define TIM_CH_W        TIM_CHANNEL_3       // Terminal W timer channel
Looking at the .ioc, I get this mapping: Channel Pin
TIM1_CH1 PA8
TIM1_CH2 PA9
TIM1_CH3 PA10

The Config/hw_config.h from the old mbed version defines this mapping:

#define PIN_U PA_10
#define PIN_V PA_9
#define PIN_W PA_8
Which means we end up with swapped pins for U and W: Channel Old Pin New Pin
U PA10 PA8
V PA9 PA9
W PA8 PA10

Different ADC Channel use

Similarly, the ADC channels have been swapped as far as I can tell.

This is how the ADC channels are currently set up in hw_config.h:

#define ADC_CH_MAIN     hadc1               // ADC channel handle which drives simultaneous mode
#define ADC_CH_IA       hadc1               // Phase A current sense ADC channel handle.  0 = unused
#define ADC_CH_IB       hadc2               // Phase B current sense ADC channel handle.  0 = unused
#define ADC_CH_IC       0               // Phase C current sense ADC channel handle.  0 = unused
#define ADC_CH_VBUS     hadc3               // Bus voltage ADC channel handle.  0 = unused
Looking at the .ioc, I get this mapping: Channel Pin
ADC1_IN10 PC0
ADC2_IN11 PC1
ADC3_IN0 PA0

The hw_setup.cpp from the old mbed version defines this mapping through register configuration:

     ADC1->SQR3 = 0x000000A;                                    // use PC_0 as input- ADC1_IN0
     ...
     ADC2->SQR3 = 0x0000000B;                                   // use PC_1 as input - ADC2_IN11
     ...
     ADC3->SQR3 = 0x00000000;                                   // use PA_0, - ADC3_IN0

So far, so good, the name/pin mappings are identical. However, the code in Calibration/calibration.cpp shows an interpretation of the ADC channels that is different from the one in the new repository:

    controller->i_b = I_SCALE*(float)(controller->adc2_raw - controller->adc2_offset);    //Calculate phase currents from ADC readings
    controller->i_c = I_SCALE*(float)(controller->adc1_raw - controller->adc1_offset);
    controller->i_a = -controller->i_b - controller->i_c;
So we have the following mismatch ADC Old Meaning New Meaning
1 I_C I_A
2 I_B I_B
3 V_BUS V_BUS

Questions

Sorry for the long post btw, I wanted to properly show where in the code my confusion comes from ;-)

hfzhang1223 commented 2 years ago

Hello, I would like to ask by the way, the new version I used has changed some parameters, but the motor does not run, and the calibration cannot be carried out. Did your transplanted program start running?

MaximilianKoestler commented 2 years ago

Did your transplanted program start running?

I am still preparing for the first tests, verifying as much as possible before even starting to adapt the new version of the firmware for my needs. I will post an update here if and when I get it working.

hfzhang1223 commented 2 years ago

ok,Thanks

------------------ 原始邮件 ------------------ 发件人: "bgkatz/motorcontrol" @.>; 发送时间: 2022年7月14日(星期四) 晚上8:06 @.>; @.**@.>; 主题: Re: [bgkatz/motorcontrol] hw_config incompatible with old mbed code (Issue #8)

Did your transplanted program start running?

I am still preparing for the first tests, verifying as much as possible before even starting to adapt the new version of the firmware for my needs. I will post an update here if and when I get it working.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

bgkatz commented 2 years ago

The naming convention in the original firmware didn't match the solder mask labels on the PCB. The new firmware was corrected to match the PCB. Both work fine on the original hardware.

MaximilianKoestler commented 2 years ago

The naming convention in the original firmware didn't match the solder mask labels on the PCB. The new firmware was corrected to match the PCB. Both work fine on the original hardware.

Thank you for confirming again that porting the new firmware to the old boards is essentially safe and possible. I think this Issue can then be closed, I will go ahead with my plan.

Since I have now realized that the board I have to target is actually using DRV8323RH (so not the SPI variant), there are a few things I need to adapt in any case.

MaximilianKoestler commented 2 years ago

Hello, I would like to ask by the way, the new version I used has changed some parameters, but the motor does not run, and the calibration cannot be carried out. Did your transplanted program start running?

@Erick-Zhf After making the required adaptions tor my driver PCB (notably for the DRV8323RH), the calibration worked pretty much instantly. I needed to reduce KI_D and KI_P in the firmware a bit (and of cause update the number of pole pairs and the gear reduction ratio), otherwise most things just worked from the start.

I guess if you are still having trouble, that discussion should move to a new issue.

hfzhang1223 commented 2 years ago

OK,I have almost the same problem as you, the calibration has always been a problem, I am now starting to debug the old version

------------------ 原始邮件 ------------------ 发件人: "bgkatz/motorcontrol" @.>; 发送时间: 2022年7月25日(星期一) 下午5:11 @.>; @.**@.>; 主题: Re: [bgkatz/motorcontrol] hw_config incompatible with old mbed code (Issue #8)

Hello, I would like to ask by the way, the new version I used has changed some parameters, but the motor does not run, and the calibration cannot be carried out. Did your transplanted program start running?

@Erick-Zhf After making the required adaptions tor my driver PCB (notably for the DRV8323RH), the calibration worked pretty much instantly. I needed to reduce KI_D and KI_P in the firmware a bit (and of cause update the number of pole pairs and the gear reduction ratio), otherwise most things just worked from the start.

I guess if you are still having trouble, that discussion should move to a new issue.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>