stancecoke wrote: ↑Apr 23, 2018 2:41 am

casainho wrote: ↑Apr 19, 2018 2:38 am

If we push the first magnet to right to move the second one, max torque will be at 90 degrees and after being moving, to brake, max torque will be at -90 degrees (now on the left side).

Have you ever tried to shift the correction angle by 127 (=180°) for doing regen? In the german forum there was

a similar suggestion.

Yes, that is one idea but I prefer to keep looking at the same place and consider the signal is now inverted and so invert the logic for increase/decrease the ui8_angle_correction. That's because of possible errors on current implementation, due to overflow of the 8bits variables like this ui8_motor_rotor_angle >= FOC_READ_ID_CURRENT_ANGLE_ADJUST.

Anyway, I also need to see because just recently I started to look for the first time to phase current to understand if the system is doing regen:

Code: Select all

```
// make sure we just execute one time per ERPS, so use the flag ui8_flag_foc_read_id_current
if ((ui8_motor_rotor_angle >= ((uint8_t) FOC_READ_ID_CURRENT_ANGLE_ADJUST)) && (ui8_flag_foc_read_id_current))
{
ui8_flag_foc_read_id_current = 0;
// minimum speed to do FOC
if (ui16_motor_speed_erps > MOTOR_ROTOR_ERPS_START_INTERPOLATION_60_DEGREES)
{
// read here the phase B current: FOC Id current
ui8_adc_id_current = UI8_ADC_MOTOR_PHASE_B_CURRENT;
if (ui8_adc_id_current > ADC_PHASE_B_CURRENT_ZERO_AMPS_FOC_MAX)
{
// limit max ui8_angle_correction value (127 + 15)
if ((ui8_angle_correction+1) < 143) { ui8_angle_correction++; }
}
else if (ui8_adc_id_current < ADC_PHASE_B_CURRENT_ZERO_AMPS_FOC_MIN)
{
// limit min ui8_angle_correction value (127 - 15)
if ((ui8_angle_correction-1) > 112)
{
// decrease only when not regen!! other way ui8_angle_correction will always decrease... CAN WE IMPROVE THIS??
if (UI8_ADC_BATTERY_CURRENT > (ui8_adc_battery_current_offset+2)) { ui8_angle_correction--; }
}
}
}
}
```

I can look at 2 different values to understand if regen is happening: shunt value or hall phase current sensor. Unfortunately I can't put my ebike with direct drive motor on the bike training roller because the motor bolts are to large to fix the training roller and so it is hard to me to make regen happen and observe in real time with oscilloscope. Sure there are other ways, but they take much time that I don't have currently.

But one way or the other, I think I have now more knowledge that will permit to solve the problem. I think I really need to phase current in real time and see to where it should be adjusted.... and I think:

is the vector I*w*L that gives the direction for phase voltage V, since for regen I will change in direction, will be -I*w*L (maybe the vectors will now be placed on -Q axis of that graph and V should be adjusted now on the inverse direction, because we want to go to the other side/direction of the magnet (D axis, phi magnetic flux).

When regen, I think the V vector will also be negative because now the voltage differential on the coils also invert directional so both I and V will be placed on -Q axis.

So, to resume, I think we should keep the same reference rotor position (D axis, max phi magnetic flux/BEMF) + 90 degrees and looking to battery current (or phase B current??) to understand if regen is happening and if so, adjust increase/decrease phase B voltage angle (ui8_angle_correction) on the inverse direction. (or at the same reference rotor position (D axis, max phi magnetic flux/BEMF) - 90 degrees and keep the same logic for ui8_angle_correction increase/decrease) and you suggest).