Thanks for sharing, this really will help me. I’ve got my head full of ‘can bus’ at the moment but will return to looking at current in a few weeks.
Any reason you are talking directly to registers and not using HAL libs? The HALs give a bit more cross board compatibility. Might not matter for vesc as all the boards I’ve seen are for stm32f405
@Owen_Williams,
You are right about the Hals for a best compatibility, but sometimes that permits to know better the mcu target, as I don’t know well yet the STM32 peripheral.
Here is the synchronize between TIM1 & TIM8 for the TRGO :
Hi @Owen_Williams,
I think I found an issue, in fact the core is running only 48MHz (?), because my loop takes 138us (it is a lot!) to execute the FOC.
I found this with a scope with a pin toggle for the scope, and this bit of program:
It was therefore the loop time too long and the core frequency that was wrong.
For your information @Owen_Williams, the SystemClock_Config(void) from vesc_4_12.h doesn’t work with me, I have had to use the configuration as shown below:
Hi @Antun_Skuric,
Yes, I implemented the current mode low side shunts (2 here) with the Clarke/Park transforms using 3 currents.
c = ADC1->DR;
a = ADC2->DR;
c -= offset_1;
a -= offset_2;
b = -(a+c);
ia *= I_SCALE;
ib *= I_SCALE;
ic *= I_SCALE;
Then I use the transform with these 3 currents, and so on.
So that I keep the “mode regular” for the ADCs, I synchronized these ones with TIM8 TRGO (TIM1 TRGO synchronized with TIM8 TRGO too, as shown here above).
@Owen_Williams, @Antun_Skuric,
I think to have found another issue about Hall sensors this time. The original “sensor.getVelocity()” sometimes returns 0, even at high velocity. I modified like this to fix it:
/*
Shaft velocity calculation
function using mixed time and frequency measurement technique
*/
float HallSensor::getVelocity(){
if (pulse_diff <= 0 || pulse_diff > 130000){
return 0;
} else {
float Ts = pulse_diff * 1e-6;
return direction * (_2PI / cpr) / Ts;
}
}
130000 corresponds to around 10 rpm, which is more than enough for hall effect sensors.
I can see the problem, but I’m not happy with that fix as the replaced code does fix the slow speed case.
At slow speed the last velocity might be say 0.1 rad/s, it then stops. There are no more interrupts, therefore pulse_timestamp and pulse_diff do not change. The velocity would continue to report 0.1 rad/s for ever.
Do you think pulse_diff > 130000 is needed? Are you seeing the occasional freakish high readings?
From my point of view (but it is my point of view ), yes, it is needed, like for “pulse_diff <= 0” is needed instead of “pulse_diff == 0” from original code. I would avoid to use pulse_diff with timeout_factor.
The compromise is to create a variable :
int32_t timeout_velocity = 1000000 / ((RPM / 60) * 2 * POLE_PAIRS * 6); // minimum velocity of Hall sensors,
I tried something similar initially. I set timeout velocity to 1s.
…but when velocity is 0 in reality but sensor is reporting old velocity because timeout hasn’t happened yet, the velocity loop becomes unstable/unhappy as it overcompensates.
The current approach, whilst a bit wrong is reasonably stable at slow speeds.
The intuition is that if your last pulse diff is 500ms then you can expect no info (new pulse) for about 500ms. If it is late then perhaps it has stopped. In reality, particularly at high speed, it is probably slowing down. I think the algorithm needs some sort of velocity half-life when a pulse is ‘late’ but at slow speed this is latency (which could cause instability).
Hi @Owen_Williams,
You are quite right for the reasoning whether for high speed or low speed, because it is the case here, and the behavior we are facing. The calculation time also is important at high velocity.
Anyway, below 50 rpm with hall sensors and 8 pôles or 14 pôles motor, it becomes difficult to get a stable velocity due to the resolution per turn (24 or 42 counts per turn i.e.).
Once that we told this, I think it would be interesting to improve this important function…to think about.
Hi,
I am new to SimpleFOC. And I have a Flysky 4.20
I have managed to move the motor in open loop.
But the driver(drv8302) doesn’t work with the latest version of the SimpleFoc(2.2). It only works with 2.0.2 version. Any Idea how to update to the latest version?
I see the open loop draws much current. But I couldn’t move the motor in closed-loop. The motor vibrate a lot. Any idea?
May I ask which sensor you are using? Can you print the angle values from the sensor when turning the motor just by hand? Does it look plausible?
The drv8302 should be supported in SimpleFOC 2.2, and if it is working in open loop, but not in closed loop, then probably the issue is not with the driver, but with the sensor…