514,706 active members
2,159 visitors online
Register for free
Login
IndustryArena Forum > OpenSource CNC Design Center > Open Source Controller Boards > DIY BLDC / DC Motor Servo Drive - ARM MCU (STM32F103C8T6)
Page 1 of 24 12311
Results 1 to 20 of 471
  1. #1
    Registered
    Join Date
    May 2006
    Posts
    190

    DIY BLDC / DC Motor Servo Drive - ARM MCU (STM32F103C8T6)

    Hello again dear machinists

    As some of you know I published earlier this year schematic and firmware for a BLDC servo drive. http://www.cnczone.com/forums/open-s...-software.html
    Don't get me wrong, that model is working just fine, but the 8 bit MCU used is somehow limited... So as many other suggested I am migrating now to a STM32 MCU...
    Because the price and the fire power of that little thingy is amazing, I intend to integrate in the schematic a prebuild board: STM32F103C8T6 ARM STM32 Minimum System Development Module Board For New Arduino | eBay

    Basic MCU specifications:

    Model:STM32F103C8T6.
    Core:ARM 32 Cortex-M3 CPU.
    72MHz work frequency.
    64K flash memory, 20K SRAM.
    On-board Mini USB interface, you can give the board power supply and USB communication.
    Size:53.34mm x 22.86mm.

    So... So far I am developing on a STM32F4Discovery board, that has a more powerfull MCU, however I am waiting for the little ebay boards to arrive...

    Things that I tested so far and status:

    1. PWM generation works great, 16 bit timers are used. Also note that the STM32F103 has a 16-bit, motor control PWM timer with deadtime generation and emergency stop. For now I do not know how to configure it, so I am using timers in a classic fashion. (I will have to rewrite the mikropascal PWM library as it does not support motor control PWM)
    2. Communication with the PC will be done using the USB port provided. The board will register as a HID device, no additional driver will be needed. The Servo Tuner program must be rewritten (not such a big deal)
    3. External interupts also tested, very nice as they are plenty and they can be mapped on quite any desired pin.
    4. ADC not tested yet, but I am pretty sure it works just fine...
    5. Flash storing of the configuration parameters. The sample programs from mikroe seem to work just fine... It seems that those MCUs do not have a special EPROM section anymore, but there are instructions capable to write directly to flash part...

    What I need to do for now:

    - Build another 3 phase MosFET power driver. All that I previously built are in my CNC machine
    - Build a dougther board for the STM32F4 discovery board, that will hold very few parts, only the optocouplers for the encoder, step, dir and enable signals, the power regulators and a few connectors.

    I intend to add another parameter in the config and to allow user to select what kind of motor it wants: DC or BLDC. When using DC motors only 2 stages from the 3 phase power stage will be connected.
    Please let me know if you have any other suggestions, requests for features and so on... It's better to think for them from now when there is no board designed, and there are virtually no limitations...

    I will keep you informed on progress

    Mihai

  2. #2
    Registered
    Join Date
    Mar 2005
    Posts
    284

    Re: DIY BLDC / DC Motor Servo Drive - ARM MCU (STM32F103C8T6)

    i suggest use to265 mosfet or 3 phase stage or IPM

  3. #3
    Registered
    Join Date
    May 2006
    Posts
    190

    Re: DIY BLDC / DC Motor Servo Drive - ARM MCU (STM32F103C8T6)

    Quote Originally Posted by tivoidethuong View Post
    i suggest use to265 mosfet or 3 phase stage or IPM
    Do you have some suggestions for some cheap IPM modules or some stuff like that. The IOR IRAMs look interesting but the price is ugly...

    Thanks
    Mihai

  4. #4

  5. #5
    Registered
    Join Date
    May 2006
    Posts
    190

    Re: DIY BLDC / DC Motor Servo Drive - ARM MCU (STM32F103C8T6)

    Thanks for suggestions. I will consider them...
    However they look pretty expensive and way more powerful than our needs... I can build a 3 phase mosfet power stage with 3 irf2101 and 6 mosfets for less than 10 bucks.

    Anyway... Here is the status of the project:

    I am building the firmware and the Servo Tuner Software in parallel, here is a quick snapshot.

    Attachment 294068

    Status:
    1. Communication with MCU over USB (board is registered as USB HID). Fast data transfers are possible, I made the soft to transfer a dummy Response from servo matrix, with 2048 int16 values, and it takes less than 1 second = Done
    2. Storing and reading of servo parameters in flash = Done
    3. 6 channel PWM generation = Done
    4. 3 external interupts (Encoder A, Step / Enable) = Done
    5. ADC = Not Done, Not Tested (but i guess it works...)
    6. PID process is in place but can not be tested without hardware...


    I will start building a power stage for testing this weekend, and an interface board with optocouplers and stuff that I can link with the power stage board and the STM32F4 Discovery board. (I am still waiting for the STM32f108 ebay boards, but I am sure that porting will be easy)

    I am open to suggestions...

    Mihai

  6. #6
    Registered
    Join Date
    Mar 2005
    Posts
    284

    Re: DIY BLDC / DC Motor Servo Drive - ARM MCU (STM32F103C8T6)

    cool, i think 400w good for DIY machine
    waitting you

  7. #7
    Registered
    Join Date
    May 2006
    Posts
    190

    Re: DIY BLDC / DC Motor Servo Drive - ARM MCU (STM32F103C8T6)

    Good news...

    The ARM servo drive project is rolling... Check out the progress so far:

    https://www.youtube.com/watch?v=Xt3-MSbPQvk

    Attachment 294508

    Please note the PID frequency!!! 65 kHz (this is done with a stm32f4 discovery board that has a powerfull mcu (168 MHz) than the stm32f103...
    Also parameters are now checked realtime with this software so you can know all the time what the status is, what is the error and so on...
    Also firmware upgrade is now possible via USB (not with STLink) but directly with the usb cable used for servo tuning...

    Status:
    Encoder AB inputs and processing = done
    PID algorithm in place and working but not optimized yet...
    Current feedback in place and working = done
    Tuning program = done, lots of new features, written in C#.

    I will keep you updated...

  8. #8

    Re: DIY BLDC / DC Motor Servo Drive - ARM MCU (STM32F103C8T6)

    Quote Originally Posted by mcm_xyz View Post
    Good news...

    The ARM servo drive project is rolling... Check out the progress so far:
    ...
    I will keep you updated...
    Hello Mihai!

    I found your threads (this one + AVR based) just a while ago. Very Impressive, thanks for sharing your designs! I've been working with very similar project for a while now. I have STM32F103 as well running on an ebay devboard and IR2101+IRFB3607 driver board. The difference is that I'm using HAL commutation at the moment, but I think I'll implement encoder or resolver interface when I receive some proper AC servo to try with. My initial setup is to have a simple PWM velocity input on my servo drive and have the encoder input + PID loop inside LinuxCNC, but having the full loop inside the microcontroller and having just step/dir or similar input would be more efficient I'm sure. But I'm taking small steps towards that.

    One question raised when reading your threads. You mention at some point in the AVR development that you removed the sinusoid commutation tables and went to square wave (trapezoid) commutation. It was a bit unclear what was the reason behind this. Because when reading any papers about servo control, the sinusoidal commutation is always referred as the best method providing the smoothest torque. Did you see the opposite? Or was it just that the advantage from sinusoid commutation was not noticeable and it certainly is easier to implement the trapezoid commutation with limited resources like AVR.. I have implemented trapezoidal commutation myself as well, but I think I'll try sinusoidal at some point or even go to try some current based vector control. But your servo runs so nicely, so it's difficult to see the benefits of more advanced methods just now. But I'd be happy to hear your comments about this.

    I'm planning to design a better driver PCB and probably a separate control board which sits somehow on top of the driver board. If you are going to share your software at some point, I'm eager to test it and of course if you (or anyone else) want to use my code or the forthcoming PCBs, I'm happy to share.

    Pekka

  9. #9
    Registered
    Join Date
    May 2006
    Posts
    190

    Re: DIY BLDC / DC Motor Servo Drive - ARM MCU (STM32F103C8T6)

    Quote Originally Posted by roivai View Post
    Hello Mihai!

    I found your threads (this one + AVR based) just a while ago. Very Impressive, thanks for sharing your designs! I've been working with very similar project for a while now. I have STM32F103 as well running on an ebay devboard and IR2101+IRFB3607 driver board. The difference is that I'm using HAL commutation at the moment, but I think I'll implement encoder or resolver interface when I receive some proper AC servo to try with. My initial setup is to have a simple PWM velocity input on my servo drive and have the encoder input + PID loop inside LinuxCNC, but having the full loop inside the microcontroller and having just step/dir or similar input would be more efficient I'm sure. But I'm taking small steps towards that.

    One question raised when reading your threads. You mention at some point in the AVR development that you removed the sinusoid commutation tables and went to square wave (trapezoid) commutation. It was a bit unclear what was the reason behind this. Because when reading any papers about servo control, the sinusoidal commutation is always referred as the best method providing the smoothest torque. Did you see the opposite? Or was it just that the advantage from sinusoid commutation was not noticeable and it certainly is easier to implement the trapezoid commutation with limited resources like AVR.. I have implemented trapezoidal commutation myself as well, but I think I'll try sinusoidal at some point or even go to try some current based vector control. But your servo runs so nicely, so it's difficult to see the benefits of more advanced methods just now. But I'd be happy to hear your comments about this.

    I'm planning to design a better driver PCB and probably a separate control board which sits somehow on top of the driver board. If you are going to share your software at some point, I'm eager to test it and of course if you (or anyone else) want to use my code or the forthcoming PCBs, I'm happy to share.

    Pekka
    Hello Pekka

    Very nice to see your appreciation.

    To answer your question quickly... those were old times... I was learning with the AVR Servo project about motors, and how to control them... So basically I started with a code that tried to move the motor freely... when no feedback there is no solution to make the motor spin nicely at lower speeds but to generate somekid of sinous signals, to make the trasition from one pole to another as smooth as possible... However when a PID process is used to control the output power, it will adjust the power very quickly and according to encoder position... Don't really know how to explain better... In fact if you would measure the output of a pid controller when motor is moving at a constant speed you would get a sinus...
    So basically... When PID is in place for controlling movement sine commutation table is not a good idea...

    I will publish soon the schematic and firmware... when I will make some tests with the STM32F103... for now I am testing with STM32F407 that is much faster...
    You mentioned an ebay board with IR2101+IRFB3607... do you have a link? I just built one myself but such prebuilt boards could save time for me in the future...

    Thanks!

    Mihai

  10. #10

    Re: DIY BLDC / DC Motor Servo Drive - ARM MCU (STM32F103C8T6)

    Quote Originally Posted by mcm_xyz View Post
    Hello Pekka

    I will publish soon the schematic and firmware... when I will make some tests with the STM32F103... for now I am testing with STM32F407 that is much faster...
    You mentioned an ebay board with IR2101+IRFB3607... do you have a link? I just built one myself but such prebuilt boards could save time for me in the future...
    Mihai
    Thanks for your reply! Sorry, I wrote a bit misleading sentence. My driver board is home made as well, only the control board is from ebay ( Arm Cortex M3 STM32F103C8T6 STM32 Minimum System Development Board | eBay ). I have a possibility to mill prototype PCBs, so for me making boards myself is the easy part of this hobby. But like I said, I will design a driver PCB and have it manufactured somewhere and if it is something that you can use as well, I can make couple extra ones and send them to you.

    I don't fully understand the drive method you have.. I may have a bit too academic approach because I haven't done that much in practice yet, just reading. But when you publish the software, I'll take a deep look and I'm sure I will learn a lot. Looking forward to that!

    Pekka

  11. #11
    Registered
    Join Date
    Oct 2009
    Posts
    17

    Re: DIY BLDC / DC Motor Servo Drive - ARM MCU (STM32F103C8T6)

    thanks for sharing so much of your development. I was interested in the last one, but the use of daughter board makes this one a no brainer. Two questions:

    1. Did I read right that you're still coding in MicroPascal? Any plan to port to C++?
    2. Is the power stage the same as the last board?

  12. #12
    Registered
    Join Date
    May 2006
    Posts
    190

    Re: DIY BLDC / DC Motor Servo Drive - ARM MCU (STM32F103C8T6)

    Quote Originally Posted by S.A.C. View Post
    thanks for sharing so much of your development. I was interested in the last one, but the use of daughter board makes this one a no brainer. Two questions:

    1. Did I read right that you're still coding in MicroPascal? Any plan to port to C++?
    2. Is the power stage the same as the last board?
    Hi hi hi...

    My thoughts exactly...

    The reason for not publishing till now is because I am moving to GCC ARM!

    It took a long time for me to get familiar with the development environment (eclipse) and debugging and stuff. STM32CubeMX is really a nice tool that helped me a lot in generating the required configuration settings for my project.
    What I can tell you is that so far I have implemented the following:

    1. USB communication. The device is again a HID device, no drivers needed.
    2. PWM generation. I've managed to start the Advanced TIM1 of the STM32F407. You can see in the oscilloscope bitmaps the signals, in perfect complement. Also dead time between HI and LO channels is configurable. (must check the IR2101 half bridge driver pdf for a good value) (see second picture)
    3. EXT interrupts. We will still use EXT interrupts for the encoder, even if the STM32F407 can use it's second advanced timer for quadrature encoder capture. The reason for this is because STM32F103 (that is the final target for this project) has a single advanced timer and that is used for motor. Please somebody with more experience with STM32 check this: Can we use a standard timer for encoder capture?
    4. Flash storage of the servo parameters.

    Things not tested:
    5. ADC conversion... but I am sure I'll do it...

    Power stage remains the same with IR2101 and IRFZ44N mosfets (or what ever you want)...

    So... This is becoming a truly open source project. In order to compile and flash you will need:
    1. Eclipse with GCC ARM toolchain... (plenty of tutorials and things on the internet on how to setup, please do not even dare ask me how to do it... )
    2. VS2015 Express (free) to build and modify Servo Drive Tuner app.
    3. STLink utility and drivers...

    I will keep you posted...

    PS. STM32F407 has the bootloader in ROM. so no need to build and upload one, but STM32F103 does not. A bootloader will have to be compiled and uploaded to the cip if you want to use the firmware upgrade feature from the Servo Drive Tuner. But I think we can do it since the ST Bootloader code is free and can be compiled as it is...

    Mihai

    Attachment 294868

    Attachment 294870

  13. #13

    Re: DIY BLDC / DC Motor Servo Drive - ARM MCU (STM32F103C8T6)

    Quote Originally Posted by mcm_xyz View Post
    Hi hi hi...

    My thoughts exactly...

    3. EXT interrupts. We will still use EXT interrupts for the encoder, even if the STM32F407 can use it's second advanced timer for quadrature encoder capture. The reason for this is because STM32F103 (that is the final target for this project) has a single advanced timer and that is used for motor. Please somebody with more experience with STM32 check this: Can we use a standard timer for encoder capture?
    4. Flash storage of the servo parameters.

    Mihai
    Hello! Thanks for your update!

    Yes, you can use standard timer TIM2-TIM5 (General purpose timer as in datasheet) as well for the quadrature encoder capture. I've done it (with STM32F407, but works the same in STM32F1xx). Check chapter 15.3.12 in STM32F1xx reference manual.

    Pekka

  14. #14
    Registered
    Join Date
    May 2006
    Posts
    190

    Re: DIY BLDC / DC Motor Servo Drive - ARM MCU (STM32F103C8T6)

    Quote Originally Posted by roivai View Post
    Hello! Thanks for your update!

    Yes, you can use standard timer TIM2-TIM5 (General purpose timer as in datasheet) as well for the quadrature encoder capture. I've done it (with STM32F407, but works the same in STM32F1xx). Check chapter 15.3.12 in STM32F1xx reference manual.

    Pekka
    Many many thanks Pekka!!!

    I've just stetted up the encoder counter on TIM2 (on stm32F407), this is a 32 bit timer... I will see if STM32F103 has 32 bit Timers... if no... Have no clue how to do it with timers... 16bit values are too small...

    Mihai

  15. #15

    Re: DIY BLDC / DC Motor Servo Drive - ARM MCU (STM32F103C8T6)

    Actually STM32F1xx has only 16-bit timers. But there is quite easy way to overcome that limitation. I have done it like this:

    void getCount()
    {
    int16_t now = TIM3->CNT;
    int16_t delta = now - oldcount;
    oldcount = now; //oldcount is volatile int16_t global variable
    count += delta; //count is volatile int32_t global variable
    }

    As you can see, here a difference between current value and the previous value is calculated and this is added to the 32-bit count-variable. Now you only have to make sure that the getCount function is called often enough that the actual 16-bit counter doesn't go more than 32k (15bit) steps between calls. So basically you call it in your PID loop and it works fine.

    Pekka

  16. #16
    Registered
    Join Date
    May 2006
    Posts
    190

    Re: DIY BLDC / DC Motor Servo Drive - ARM MCU (STM32F103C8T6)

    Quote Originally Posted by roivai View Post
    Actually STM32F1xx has only 16-bit timers. But there is quite easy way to overcome that limitation. I have done it like this:

    void getCount()
    {
    int16_t now = TIM3->CNT;
    int16_t delta = now - oldcount;
    oldcount = now; //oldcount is volatile int16_t global variable
    count += delta; //count is volatile int32_t global variable
    }

    As you can see, here a difference between current value and the previous value is calculated and this is added to the 32-bit count-variable. Now you only have to make sure that the getCount function is called often enough that the actual 16-bit counter doesn't go more than 32k (15bit) steps between calls. So basically you call it in your PID loop and it works fine.

    Pekka
    Thanks for the suggestion! I think I will do it like this... In my latest tests with mikropascal I obtained with STM32F407 almost 200kHz for PID frequency... so it's damn fast... so I am pretty sure that it can make some additional calculations and still keep up the high frequency... and there is no interupt like this to disturb the mcu. After some tests I intend to move the PID update on a timer so it will execute at constant intervals... I guess 50KHz or even lower is enough...

    Thanks again!

    Mihai

  17. #17
    Registered
    Join Date
    May 2006
    Posts
    190

    Re: DIY BLDC / DC Motor Servo Drive - ARM MCU (STM32F103C8T6)

    Hello guys!

    Good news...

    STM32F103C8T6 is the new core for my Servo drive...

    Code is written in C and compiled with GNU ARM GCC, under eclipse. So far it's not really usable, current feedback is not present, external inputs for STEP / DIR / Enable are also missing. It's in the early stages. What is done so far:

    USB Communication, Storing and Loading servo parameters in flash, PID process, Encoder Input (A and B are linked to TIM2 in encoder mode, Thanks Pekka!!!), PWM outputs are using TIM1 in advanced complementary mode.
    PID Frequency is about 40kHz, with totally messed up code, at 72MHz... I am sure I can improve it in time... Movement is buttery smooth!!!, I presume because of the use of the complementary PWM channels...

    enjoy!

    Mihai!

    Code and schematics really soon... I will not design a PCB because I do not intend to produce this for myself... So... show me your Eagle skills...

    https://www.youtube.com/watch?v=6Pn04kHPXOk

  18. #18
    Registered
    Join Date
    Mar 2005
    Posts
    284

    Re: DIY BLDC / DC Motor Servo Drive - ARM MCU (STM32F103C8T6)

    Quote Originally Posted by mcm_xyz View Post
    Hello guys!

    Good news...

    STM32F103C8T6 is the new core for my Servo drive...

    Code is written in C and compiled with GNU ARM GCC, under eclipse. So far it's not really usable, current feedback is not present, external inputs for STEP / DIR / Enable are also missing. It's in the early stages. What is done so far:

    USB Communication, Storing and Loading servo parameters in flash, PID process, Encoder Input (A and B are linked to TIM2 in encoder mode, Thanks Pekka!!!), PWM outputs are using TIM1 in advanced complementary mode.
    PID Frequency is about 40kHz, with totally messed up code, at 72MHz... I am sure I can improve it in time... Movement is buttery smooth!!!, I presume because of the use of the complementary PWM channels...

    enjoy!

    Mihai!

    Code and schematics really soon... I will not design a PCB because I do not intend to produce this for myself... So... show me your Eagle skills...

    https://www.youtube.com/watch?v=6Pn04kHPXOk
    give schematic, i will layout

  19. #19
    Registered
    Join Date
    May 2006
    Posts
    190

    Re: DIY BLDC / DC Motor Servo Drive - ARM MCU (STM32F103C8T6)

    Hello guys!

    Here is the schematic... I do think there will be no change in the pinouts of the STM32F103C8T6 MCU.

    So far we have:

    PA0, PA1 = Encoder A and B Inputs, used in TIM2 encoder counter

    PA3 = ADC in

    PB4, PB5 = STEP / DIR inputs, used in TIM3 encoder counter
    PB6 = ENABLE input, used as EXTI

    PA8, PA9, PA10, PB13, PB14, PB15 = TIM1 advanced motor timer outputs

    PC13, PC14 = Error and Status Leds and outputs

    THINGS already on the STM32 board, in case somebody decides to make a schematic with the MCU directly... will need to solder usb, oscilator, and JTAG(SWI) interface connector:

    PA11, PA12 = USB
    PD0, PD1 = OSC
    PA13, PA14, PA15, PB3 = JTAG

    Lets make this, guys!

    Mihai

    PS. Please feel free to change the schematics as needed. Like if you want to drop the VRegs... do it, and add connectors for 5 and 12-15V regulated inputs... and so on...

  20. #20

    Re: DIY BLDC / DC Motor Servo Drive - ARM MCU (STM32F103C8T6)

    Quote Originally Posted by mcm_xyz View Post
    Hello guys!

    Here is the schematic... I do think there will be no change in the pinouts of the STM32F103C8T6 MCU.

    Mihai

    PS. Please feel free to change the schematics as needed. Like if you want to drop the VRegs... do it, and add connectors for 5 and 12-15V regulated inputs... and so on...
    Hello Mihai,

    Nice progress again!

    I've been working with my own version of the very same thing. I decided to divide my drive into two boards, driver and the controller. Mostly because I like the modular approach, I probably screw up something, so I do not need complete redesign / rebuild if I change something.

    Anyway, I've started by designing the driver board. It is essentially equal to your schematic. I'm planning to mount my control board above the driver board. The driver board is only 5x10cm, so I think it's quite compact and PCBs with that size are super cheap. I also included some current sense amplifiers, so I can measure small currents and still use small shunt resistors. I included also phase current measurement for two phases if I ever happen to try current based position sensing.. But all those can be left unmounted if not used in the beginning..
    Next I'll design the controller board and I will try to match your pinout so that your software would be directly compatible with my board. The difference will be at least that I'll include also support for HALL sensors as I'm using them for commutation at the moment. I will directly mount the STM32F103 to the controller board, as I own plenty of them already.

    You can check my driver board from:
    http://pekka.eu/cnc/bldc_driver_sch.pdf
    http://pekka.eu/cnc/bldc_driver_layout.png

    Pekka

Page 1 of 24 12311

Similar Threads

  1. Replies: 3
    Last Post: 02-11-2015, 06:07 AM
  2. Replies: 0
    Last Post: 10-21-2014, 09:29 PM
  3. Servo Drive AC + servo motor for car steering wheel simulator
    By yusukeand in forum Servo Motors / Drives
    Replies: 6
    Last Post: 01-10-2014, 09:06 AM
  4. VCE-750 with BLDC Servo - X Axis Servo fault
    By kostner in forum Haas Mills
    Replies: 6
    Last Post: 10-23-2011, 08:09 PM
  5. Sell Servo Motor, Servo Drive by GSKcnc.com from China
    By salecnc@hotmail in forum News Announcements
    Replies: 0
    Last Post: 06-03-2008, 08:55 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •