Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[General] STMicroelectronics 8 bit MCUs for BLDC Motor Control

Status
Not open for further replies.

DebD21

Newbie level 3
Newbie level 3
Joined
Aug 25, 2019
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
59
Hi there... my first post on this forum! Coming to the point right-away, I'm working on a 48V 1kW sensored BLDC Motor control project for EV application. I'm using the STM8S series MCUs for this purpose (STM8S Discovery Board, based on STM8S105C6T6 48 pin MCU)
I'm planning to feed the hall sensor outputs from the motor into the 3 channels of Timer 2 of my MCU and I want the Timer 2 to issue an interrupt every time a hall sensor makes transition either from 0 to1 or from 1 to 0, so that Timer 1 channel outputs can be configured accordingly, to switch on and off the correct pair of switches (6 step commutation strategy)
Could someone give me a rough idea of how to configure the Timer 2 for this purpose i.e. which registers/bits do I need to modify so that Timer 2 channels are able to capture every hall transition (both 1 to 0 and 0 to 1) and subsequently generate an interrupt event on Timer 1.
P.S. I've gone through a sample program released by STMicroelectronics to generate 6 step PWM using software generated interrupts by configuring Timers 1 and 4. I just need to know which registers do I need to modify so that I can generate interrupts using hardware i.e. Hall Sensors instead of software.
 

Hi,

I'm completely clueless what you want to do with the timers.

Pin transitions can be detected without timer... and the BLDC signals can be controlled without timers, too.
Then you talk about PWM .... what do you do with PWM and why?

Klaus
 

I'm following a reference design given by ti (URL attached at the end of the message) They've used the advanced timer available in their MCU to generate PWM signals for the inverter running the motor and another general purpose timer to capture the hall signals. I plan to do the same on my STM8S MCU.
As far as why use PWM is concerned, I'd request you to go through page 4 of the PDF (url given)

https://www.google.com/url?sa=t&sou...FjABegQIBRAB&usg=AOvVaw0qpNVF0mEnJQbq5448o54g
 

Hi,

A simple BLDC controller uses the hall sensors for commutation control. It does not use PWM.

Now I guess you want to build a regulation loop, maybe for speed control, maybe for torque control, maybe for position control.
But you did not mention any of the three.

Please tell a little more about your ideas.

Klaus
 

Yes speed control is going to be my primary objective. Sorry for being a little less elaborate!
So now could you tell me how to configure the Timer 2 for the purpose I outlined? Or for that matter is there a simpler way to read pin transitions and generate commutation events other than using timers?
Sorry I'm quite new to microcontroller coding and nobody to guide me properly in this regard!
 

Hi,

Ok, then timer2 is for measuring RPM? .. please confirm this.

If so, then on every pin change you need to:
* calculate new commutation state
* calculate RPM

For RPM:
Now you first need to decide at which range of RPM you are interested. You can't go down to 0 RPM, because this means infinite time.
Infinite is not possible.
Decide the timer frequency. It must be low enough for the counter not to overrun from one hall transition to the next transition at your lowest RPM ...
I'm not experienced with STM8, but it will be similar to every microcontroller. The datasheet should tell you which registers to set with what values.
Then you need to set up the timer for the capture feature. I'm not sure wheter it's possible to use three inputs on one timer and each using the capture feature.

If you can't use the capture periferal, then it's no problem to do this within the ISR by software. Just let the conter run freely and read the counter value at the beginning of the ISR.

Independet of hardware capture of software capture:
* you need to store the captured value in a variable, because you need it at the next run of the ISR.
* at every ISR run calculate: diff_time = current_capture_value - previously_stored_caoture_value.

1/diff_time is proportional to RPM.

Mind:
* There are discussions where hall transitions are not clean and giving multiple transitions where there should be only one. Be sure to take care of that. I recommend to use proper hardware filtering, or do validation within the software.
* That at low RPM you have a low regulation reaction speed. This may make the regulation loop unstable.
* That the angular precision of the hall signal is not perfect, thus you get jittery timing...resulting in jittery regulation.
* You need to take special care (special software) for RPM below your RPM range.

Klaus
 

Hi,

Ok, then timer2 is for measuring RPM? .. please confirm this.

If so, then on every pin change you need to:
* calculate new commutation state
* calculate RPM

For RPM:
Now you first need to decide at which range of RPM you are interested. You can't go down to 0 RPM, because this means infinite time.
Infinite is not possible.
Decide the timer frequency. It must be low enough for the counter not to overrun from one hall transition to the next transition at your lowest RPM ...
I'm not experienced with STM8, but it will be similar to every microcontroller. The datasheet should tell you which registers to set with what values.
Then you need to set up the timer for the capture feature. I'm not sure wheter it's possible to use three inputs on one timer and each using the capture feature.

If you can't use the capture periferal, then it's no problem to do this within the ISR by software. Just let the conter run freely and read the counter value at the beginning of the ISR.

Independet of hardware capture of software capture:
* you need to store the captured value in a variable, because you need it at the next run of the ISR.
* at every ISR run calculate: diff_time = current_capture_value - previously_stored_caoture_value.

1/diff_time is proportional to RPM.

Mind:
* There are discussions where hall transitions are not clean and giving multiple transitions where there should be only one. Be sure to take care of that. I recommend to use proper hardware filtering, or do validation within the software.
* That at low RPM you have a low regulation reaction speed. This may make the regulation loop unstable.
* That the angular precision of the hall signal is not perfect, thus you get jittery timing...resulting in jittery regulation.
* You need to take special care (special software) for RPM below your RPM range.

Klaus

Yes Timer 2 is to be used for RPM and on every pin change I need to compute new commutation state and calc. RPM
-Timer 2 is driven by the internal fMASTER clock with a prescaler ranging from 1 to 32768 in powers of 2. Max frq of internal clock is 16MHz.
-Timer 2 has three input channels and each has input capture feature.
- I have understood the RPM calculation part. I've gone through examples where input capture feature is set to detect rising edge or falling edge of a PWM input signal. But as far as hall transition is concerned, it can be either rising edge (from 0 to 1) or falling edge (from 1 to 0) so I'm asking for a way to sort out this issue i.e. how can I set my Timer 2 to detect either a rising edge or a falling edge? One idea I could think of by reading ti's program is: Suppose my current hall state is H3H2H1 = 001 then I'm aware that the next transition which the H3 and H2 pins will be making is from low to high i.e. rising edge, so I can set the register bits corresponding to H3 and H2 to capture a rising edge next time while for H1 it should capture a falling edge next time. As soon as the next hall transition occurs i.e. H3H2H1 = 011, H2 captures a rising edge and by reading the new H3H2H1 values, I can write the necessary switching code.
- What I need to understand therefore is how do I come to know if a hall transition has occurred i.e. how do I extract the information from the Timer 2 that one of H3, H2 or H1 has made a state change.
 

Hi,

* the capture feature just freezes the timestamp
* the interrupt on pinchange feature just raises an interrupt.

But you need to write software on your own to read the hall states.

Now you need to decide at which hall state you need to output which BLDC state..


But isn't all this written in the application notes?

Klaus
 

A simple BLDC controller uses the hall sensors for commutation control. It does not use PWM.

True, but he's using PWM to generate the three phase outputs to the motor. According to his original post he's using different timers to generate the PWM outputs than the one(s) he's using to capture timings on the Hall sensor inputs.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top