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