On Dec 29, 2015, at 13:37 PM, ST-Micro Technical Support wrote:
Hi Dale,
I have reviewed your Mihai schematic and consulted with my colleagues regarding this matter and the only advice I can tell you is that while your concept is sound, your choice of pins could have used more research and testing to avoid these types of problems.
The low performance you are experiencing is an OEM (you) design flaw which resulted from the lack of testing/knowledge/experience and while you have acknowledge, your limited knowledge of STM32 line of products seem to be falling into the same performance issue that all other designer are experiencing and this is mostly in part based on IO selection for convenience rather than optimal performance.
LeadShine is a China based company who produces a commercial motor and driver based on the STM32F103C8T6 and the driver has the same low performance issue which they have attempted to overcome by adding encoder hall sensors and index signals and they are still unable to achieve more than 72% field saturation which makes the product acceptable to the low end hobbyist who is unaware of the poor performance of the product which is due to the overall design.
Using the STM32F103C8T6 as a 3-PH ESC driver does not rely on positioning or phasing to manage the motor but instead drives each coil into full saturation regardless of the amount of field angle in respect to the rotor as it's basically driving the rotor by voltage/current in constant velocity and varying the speed by voltage so a small delay in the complimentary outputs has minimal effect and the motor never achieves maximum torque.
A Servo Driver should be configured as a constant torque device and rightly so, the data sheet and application notes don't go into specific details or all possible scenarios of use regarding the STM32F103C8T6 and while using PB13, PB14 and PB15 as the complimentary PWM signals will work it's not the best option for your servo driver application.
Do not mistake the driver driving the motor in constant torque for operating the driver in constant velocity, you can drive the driver in constant velocity to traverse to a specific position but the driver needs to control the motor with maximum torque to prevent stalling under heavy loads which is why they are suitable for CNC machine applications.
Due to layer isolation and separation there is a 163 nsec delay on port pins PB13, PB14 and PB15 opposed to a 28 nsec delay using the alternate complimentary port pins PA7, PB0 and PB1 and using a single current sense channel will not provide the correct current results in respect to the non phasing field current due to the delay and performance will never exceed 75% of it's capabilities provided your code can achieve it which we have estimated with some minor code correction you should be able to achieve greater than 92% by utilizing different pins and streamlining your inputs to ANALOG pins (except the encoder inputs).
Using PB6 as your enable line is a poor choice as your POWER_STAGE is tied to port B and all access to this line generates a maskable interrupt which will cause your application to pause until it receives a STEP or DIR signal from the controlling device based on the software configuration of your POWER_STAGE GPIO's, we recommend switching to a non port B ANALOG line such as PA6 for ENABLE and using PB6 as your encoder B channel signal.
Another issue of concern is the use of a dual channel quadrature encoder (A/B) which has no separate index signal, this requires adjusting the encoder to the rotor to obtain the correct phasing, this can be easily achieved by using a low DC voltage on the A coil to lock the rotor and then adjusting the encoder which does have the index signal on the A channel and can be detected due the the different signal pattern of the index position which requires an oscilloscope to detect and correctly set.
We believe this can be corrected by using a triple channel encoder (A/B/Z) making alignment significantly simple as you only need to detect the index position which is a single signal and also allow you to accurately track the rotor position relative to the encoder signal.
You can continue to use the dual channel quadrature encoder and you should still be able to effectively drive your motor into the 90+ saturation region with reasonable torque but we advise the addition of the index signal to help with field orientation and improve motor performance and response and perhaps you should consider adding F.O.C. capabilities to your driver code as you pretty much have all the hardware to support it.
PB2 is a good choice for the encoder index signal as it uses a maskable interrupt which will allow you to zero the encoder counter in forward or set to max value in reverse regardless of the current status/activity of your application code without causing any delay.
It is our professional conclusion you should be using the following pinout to achieve optimal performance in your drive and these pin changes alone will make your drive reach much more acceptable performance levels.
Optional pins have been noted and it is recommended you consider adding them, the dual channel current sense give you the off field current and using something like 0.01ohms as your shunt resistor is better than the 0.1ohms you are currently using and it is a common mistake to use a target voltage of 1v based on 10A which does not take into account a surge of 20A or 30A at startup and 0.01ohms means you working in 0-0.500mv range and less likely to damage the MCU from over-voltage as most ANALOG lines are not five volt tolerant.
As a side note, you might wish to consider using the STM32F103T8U6, STM32F103TBU6 or STM32F103TBU7 as these specifically target motor and inverter applications and have even less delay allowing you to achieve a 98% PWM frequency efficiency.
Code:
++++++++++++++++++++++++
+ STM32F103CxTn PINOUT +
++++++++++++++++++++++++
FUNC NEW_PINOUT
--------------------------------------------------------------------------------------------------
ENABLE ADC12_IN6/PA6 (tim1 break pin, max 3.3V!!!)
STEP SPI1_MOSI/PB5 (5v tollerant)
DIR SPI1_MISO/PB4 (5v tollerant)
ENCODER_A SDA/PB7 (5v tollerant)
ENCODER_B SCL/PB6 (5v tollerant)
ENCODER_Z BOOT1/PB2 (Optional, 5v tollerant)
B_EMF ADC12_IN1/PA1 (Optional, need C_EMF)
C_EMF ADC12_IN0/PA0 (Optional, need B_EMF)
DC_LINK ADC12_IN2/PA2 (Optional for stabilization)
B_SENSE ADC12_IN3/PA3 (Single current sense)
C_SENSE ADC12_IN4/PA4 (Optional for FOC, need B_SENSE)
TIM1_CH1 TIM1_CH1/PA8
TIM1_CH1N TIM1_CH1N/PA7 (Better choice than PB13 due to minimal delay)
TIM1_CH2 TIM1_CH2/PA9
TIM1_CH2N TIM1_CH2N/PB0 (Better choice than PB14 due to minimal delay)
TIM1_CH3 TIM1_CH3/PA10
TIM1_CH3N TIM1_CH3N/PB1 (Better choice than PB15 due to minimal delay)
STATUS_LED JTDO/PB3 (PC13 should not be used for LED)
ERROR_LED JTDI/PA15 (PC14 should not be used for LED)
USB_DM USB_DM/PA11 (Obvious)
USB_DP USB_DP/PA12 (Obvios)
SW_DIO SWDIO/PA13 (USE SWD WHERE POSSIBLE)
SW_CLK SWCLK/PA14 (USE SWD WHERE POSSIBLE)