587,768 active members*
3,273 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)
Results 1 to 20 of 490

Hybrid View

  1. #1

    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

  2. #2
    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

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
  •