owntech-foundation / Core

A comprehensive API for power electronics based on Zephyr RTOS
https://www.owntech.org/
GNU Lesser General Public License v2.1
3 stars 10 forks source link

[Scheduling][HRTIM] Under a certain HRTIM Frequency, control task no longer launches #42

Closed jalinei closed 1 month ago

jalinei commented 5 months ago

Major issue that derives from https://gitlab.laas.fr/owntech/power-api/core/-/issues/57

We should check that pwm engine is correctly running at any frequency if criticalTask source is source_tim6

scheduling_define_uninterruptible_synchronous_task returns -1 for all kind of problems which makes debugging non trivial.

It has to be clearly documented that PWM carrier can not be slower than criticalTask frequency if HRTIM is criticalTask clock source. This issue is also midly linked with #32

jalinei commented 3 months ago

Testing should be done to check if #57 is solving this High priority issue.

luizvilla commented 3 months ago

I have tested the frequency with the Setting multiple PWM code. There is still a behavior that is left:

luizvilla commented 3 months ago

Here's the prescaler information image

luizvilla commented 3 months ago

After some testing, I cannot get the frequency to be lower than 10kHz. If I start at 10kHz, I cannot raise the frequency above 190kHz.

luizvilla commented 3 months ago

At 20kHz I cannot go beyond 383kHz At 50kHz I cannot go beyond 957kHz At 200kHz I cannot go beyond 3831kHz

Experimentally, I find that the maximum frequency is 19.15 times higher than the minimum frequency.

luizvilla commented 3 months ago

At 50kHz I cannot go beyond 957kHz At 200kHz I cannot go beyond 3831kHz

jalinei commented 3 months ago

This behaviour seems normal to me Luiz. We do need to test wether the control task is succesfully launched or nor in the interval specified in initFrequency. [minimal_frequency, maximal_frequency].

What I understand from your comment is that we should clarify the capabily and spread of the upper frequency bound. This can be discussed in a separate issue and IMO without the "high priority" tag.

However here I expect that we conclude wether or not the control task correctly triggers in "reasonable" bounds let say between 20kHz to 200kHz, that for any multiple of the carrier frequency we do enter the critical task.

luizvilla commented 3 months ago

The PWM does not start below 10kHz

luizvilla commented 3 months ago

Initfrequency has no "upper bound". The frequency given to it creates the "lower bound" but that is it.

void PwmHAL::initFrequency(uint32_t init_frequency)
+1 overload

This function initialize the frequency

Parameters:
init_frequency – frequency in Hz

Warning:
this function must be called BEFORE initialiazing any timing unit. the frequency initialized becomes the MINIMUM possible. use it BEFORE initialization of the timing unit.
luizvilla commented 3 months ago

We can add in the documentation that the maximum frequency is 19.15 times the initial frequency.

luizvilla commented 3 months ago

I worked on the test a little further. Instead of using the serial port, I use the LED to test that the critical task is working. I get a blinking led that becomes faster over time and stops after a while. This is due to the fact that when the critical task is initialized, the micro-controller calculates the number of master reset repetition it needs for calling the critical task. Whenever the critical task becomes too fast, this become an issue.

jalinei commented 3 months ago

Initfrequency has no "upper bound". The frequency given to it creates the "lower bound" but that is it.

void PwmHAL::initFrequency(uint32_t init_frequency)
+1 overload

This function initialize the frequency

Parameters:
init_frequency – frequency in Hz

Warning:
this function must be called BEFORE initialiazing any timing unit. the frequency initialized becomes the MINIMUM possible. use it BEFORE initialization of the timing unit.

If you set two arguments in pwm.initFrequency(freq_low, freq), the prescaler is calculated in a way that the range [freq_low, freq] can be obtained. It is true that freq is not really the "real" upper bound, but the pwm should be able to output a signal with a frequency between [freq_low, freq] without any guarantee above that range. I do not see the inconvenient with that approach.

luizvilla commented 1 month ago

I tried again and the init frenquency works down to 650Hz with the critical task working fine.

luizvilla commented 1 month ago

Summary of our discussion on the matter. We currently miss:

We should provide the user with the necessary data in our code and information in our documentation.

luizvilla commented 1 month ago

From the current code we can retrieve most of the information. The only information missing is the resolution.

luizvilla commented 1 month ago

I've updated the hrtim driver and the pwnHAL to retrieve all the data that is listed above. This is treated by commits 57e0b1a , f420184 and 9a7420e