cancel
Showing results for 
Search instead for 
Did you mean: 

software architecture - control motor in interrupt routine

omatza
Associate II
Posted on November 12, 2005 at 11:04

software architecture - control motor in interrupt routine

6 REPLIES 6
omatza
Associate II
Posted on May 17, 2011 at 10:19

Hello

In my application I need to have HW SPI (in/out) communication (sometimes of large blocks), HW SCI (in/out) communication, handling queues of messages in software (put messages in buffer, checksum,...), and the MOST important - control of motor.

The motor control is the main application of the chip.

My question conecrt to interrupt and background design.

Option 1 - everythng is done in main loop:

If I need to poll over the comunication, to get/send data, then my control of the motor may be delayed, so the PI control may not work properly.

option 2: control of the motor in main loop, communication in interrupt:

this is good except the fact that you can't work in SPI in interrupt mode for transmit and receive - see note in ST7 SOFTWARE LIBRARY USER MANUAL, and that handling the queues and checksum,.. in interrupt still may delay the main loop of the motor control.

option 3: put all the motor control (what is now done in regul.c and mtc.c, in the BLDC library) in interrupt of timer, and put all the rest in main loop.

What do you think ?

(I am used to work with pSOS, VxWorks, so it is difficult for me to design without RTOS)

Thanks a lot

Oren

gaetano
Associate II
Posted on May 17, 2011 at 10:19

Hi Oren,

ST7FMC MCU is an atypical 8-bit microntroller, with an embedded dedicated Motor Control Hardware peripheral configurable for driving AC Induction and PMSM motors.

That makes it unique in its genre. Infact, all the tasks strictly related to the motor driving issues (steps sequence, hall sensor input signals, ouput channel and PWM management ) are performed by the MTC peripheral, letting the MCU core to process the user code. The CPU load for such a motor driving, generally never exceeds 20%.

This means, that you have enough time to do a lot of other tasks by using purely CPU resources for computations. One of this is the PI regulation routine. In the library delivered with the ST7FMC Starter Kit package, the PI controller is called every SAMPLING_TIMES ms, into the Main.c module, and this time is got by using the Timer A as time base clock.

By the way, it is convenient to organize your algorithms thinking at an interrupt-driven machine, given that, you have a lot of peripherals (SCI,SPI, MTC, 16-bit Timer) that makes the job autonomously. The completion of an atomic task is then signaled to you through an interrupt. For instance, the edge transitions coming from hall sensors that causes the step commutations are managed directly by the MTC peripheral without any intervention of the CPU.

The AN1904 and 1905 (for AC Induction and BLDC PMSM respectively) show in great details how the firmware is organized and the basic principles on how each motor control dirve tasks are implemented.

Moreover, the modular approach followed in the making of libraries should facilitate their understanding solely by reading the source code written in the C module (starting, of course, with the Main.c).

With my best regards,

Tanio

omatza
Associate II
Posted on May 17, 2011 at 10:19

Hello Tanio

First of all I want to thank you for your help. It is very nice of you.

Second, I have several questions, concerning your replay.

I am not familiar with motor issues at all. I got the bldc library from AN1905, compiled it and load it to the starter kit, as you said. I know that there is an MTC unit in the ST7FMC2, but I didn't read about it yet. (I read the AN1905, and the booklet of the starter kit)

1. I saw in softec site that there is new library, but I don't know where to download it from :(

Can you write the link ?

2. you spoke about the libraries that are wrtitten in the same manner and are self explain.

It is true, but:

a. my version of the st lib2 is old, (got it by mail) and I don't know where to download it from :(

can you help here too ?

b. the sources are mostly in polling way!!!

I read in the PDF user manual, that because there is only one interrupt for SCI, you can't work with interrupts in Tx and Rx, only in one direction and the second should be polling.

c. the main routines in every sample doesn't take into account that there are several messages to send/receive, and that there is motor issues to do. So I should change the drivers also.

3. When I wrote that the application should do motor control, I meant to the PI regulation routine.

In the library the SAMPLING_TIMES is 50ms. In our application it should be 10ms, so the CPU load will increase.

Also, from what I know in control, there shouldn't be jitter in the calling to the PI regulation routine, so it must be called in precise intervals, and SCI SPI shouldn't interfere.

This is why I think (and I ask what do you think) to move the call to Set_Target_Electrical_Frequency (or should it be regul_PI), from main, to timer interrupt.

any thoughts ?

Thanks

Oren

gaetano
Associate II
Posted on May 17, 2011 at 10:19

Hello Oren,

sorry for the late answer, but generally I take care of forum questions when I am in office (it is part of my job).

Moreover, today I was off the office the whole day.

Tomorrow I will dedicate some time to answer to your questions (now I'm at home and my daughters don't allow to work. :-[ ).

With my best regards,

Tanio

gaetano
Associate II
Posted on May 17, 2011 at 10:19

Hello Oren,

at this website address:

http://www.softecmicro.com/download.html?type=browse&title=Software&PHPSESSID=ed1d9414d287e5bd2d193bd3f66de41a

by clicking on ''AK-ST7FMC System Software'' (2nd row) you can download the new ST7FMC Control Panel 2.0 package, with a lot of material, including the references I gave you previously.

With the standard installation you will find the source codes for BLDC motor with Hall sensors in the following directory:

C:\Program Files\SofTec Microsystems\AK-ST7FMC\Library\BLDC_3PH_SR_2.0

Oren, the ST7 lib2 you are referring ARE NOT the same of the ones I suggesting to you; mines are dedicated libraries for this device, developed for motor control-oriented application done by using this micro.

About point 3), given that SCI, SPI peripherals have programmable level of interrupt priority, their interference with other part of code can be prioritized as you like. In the case of PI regulator routine, this has been written in the main.c module (lowest priority), but consider that the jittering for PI regulation is confined at few tens of microseconds that compared to 10ms of regulation period makes it absolutely negligible :p

On the contrary, put that function in the Timer routine, could delay the refreshing of sinusoidal waveform and to create problems with harmonic distorsion of the generated sinusoidal waveform.

By the way, the system (Starter kit and Firmware) is really ready to use, and you can make all the measurements you need to appreciate the degree of accuracy you can get from the actual implementation.

Regards,

Tanio

omatza
Associate II
Posted on May 17, 2011 at 10:19

Hi Tanio

I didn't know it is your job to answer messages.

I thought that people answer it voluntarily.

Still it is nice from you to trry to answer from home 🙂

I also have to daughters, and can't study work or do anything else, beside taking care of them. :-?

Where do you work ? why it is your job ?

Are you ''maser'' of motor control applications and ST7FMC ?

Regarding your answer:

Thanks for the new motor library. I didn't know where to find it.

What I also meant is that I have old ST7 lib2, that contains lots of drivers (SCI,SPI and such) that I thought to use it in my application, in order to write everything from screath. don't you think it is a good idea? do you link to the latest version of it, or to one spacial for the ST7FMC ?

Why you said ''On the contrary, put that function in the Timer routine, could delay the refreshing of sinusoidal waveform and to create problems with harmonic distorsion of the generated sinusoidal waveform.'' ???

Isn't it true that the timer interrupt will be called in exact time intervals ???

When you say that the jitter is negligible, when the PI regulation is in main, you implicitly assume short interrupt handling routines, right ?

Also, I am ashamed to say. but I didn't find material on ''programmble level of interrupt priority''.

Do you reference to this topic as well ?

I am sorry to ask all those questions, and I am very grateful for your help 🙂

Yours

Oren