Changing FOC Switching frequency

Yeah, this is the kind of thing that makes sense for what i’m seeing. I’m going to do some more testing today/tomorrow and see what i can see. I got another current sensor, so i’ll hook that up to one phase wire of the motor and see if there is anything interesting going on. Think i’ll build a variable capacitor filter board too, to try to smooth the current spikes into something more easily visualized.

“sensor resolution” he’s referring to is current sensing per phase as it relates to controlling the sensorless electrical commutation and control. He’s correct in that if the ADC measuring current is tied to switching frequency, we might get some odd results, particularly if it isn’t measuring at a consistent/representative time in the current pulse.

Right, we did actually watch the video i posted. Vedder said, measured and demonstrated that this is an unusually low inductance motor. Just because you use 20khz for your motors doesn’t mean it’s ideal for each one of your motors (or any of mine), and/or doesn’t mean there isn’t a firmware bug that’s forcing 20khz to be “best” by hobbling the other frequencies. Testing will continue on my end until it’s clear if there is a bug, an error in my setup/procedure, or that the seeming 20khz preference is refuted by new data. Nothing absolutely conclusive on my end yet, just stuff that seems to indicate something strange.

It is good news that a new vesc 6(vesc 7?) will have some trickle down tech from the 75/300.

3 Likes

These tests are with a pololu current sensor rated to 120khz, so they should be capturing good data. The sensor centers on 2.5v for 0amps, so consider that the baseline. The graphs are a 3khz low pass filter to smooth the current pulses into an average of the “sine-wave” that the FOC controller is hypothetically delivering to the motor.

It sure looks like the 25khz test results in each commutation phase being more similar to the others (though this could be to do with the increase inductive impedance from faster switching, right?). Remembering that this is only one phase of three, i see much greater similarity one every third cycle. I also see a slight lowering of amplitude as the switching frequency increases. Inductive impedance in the motor preventing these shorter pulses from reaching full voltage/current?

The change in jaggedness clearly shows the effect of the increased switching frequency.

This is with 4.12 hardware, on a flipsky 6374 190kv motor. It’s running sensorless at 30% duty cycle with 30w of total energy consumption.

15khz 15khz-30duty-190kv

20khz 20khz-30duty-190kv

25khz 25khz-30duty-190kv

Thoughts, anyone?

1 Like

30khz 30khz-30duty-190kv

zoomed out in the time domain a bit to make sure we see two of each cycle, otherwise same settings as above. (Gearbox that was acting as a load was cooler, so the amplitude won’t be comparable to the others, since the grease is high viscosity at lower temps.)

1 Like

The higher frequency seems to produce a cleaner wave with the one primary frequency, so do I guess right in that it will be more efficient in the motor and maybe less efficient in the esc at 30k? But even within the samples there’s a lot of variation of then waveform which I’d have thought they’d stay the same. I have a weird motor I’d like to see how it shows if you’re open to others.

You shouldn’t need a low pass to filter the current pulses, the motor inductance does that automatically. The 3khz is adding distortion by taking the energy from any fast spikes and smearing it all over the real signal, and also delaying the signal. If the signal is noisy, power the polulu from a battery and make sure scope ground and polulu ground are right at the vesc -input, like right on the board. Shorter scope grouns are better.

Does your scope have multiple channels? Could you capture phase voltage and phase current at the same time? What does the vesc +input look like with ac coupling and 500mV/div?

1 Like

Without the lowpass, the individual current spikes were visible, and the trend was hard to see. Perhaps not enough motor inductance to smooth the spikes into a sine? If so, this might be an indicator that all else being equal (it isn’t), a switching frequency just high enough to smooth the wave via motor inductance is optimal? 3khz seemed about right to smooth the pulses into a sine wave. It’s not what the motor sees, but it is a lot easier to see and think about. I can post without filter to show you.

I’ve got two scopes now, a 4 channel rigol, and the 2 channel AD2. After i posted these, i did hook voltage up to the second channel of the AD2. I also applied (just by hand) more load, and the spikes in this filtered waveform did get much cleaner sine shaped.

My flipsky 6.6 is acting up (no USB detect anymore), so i can’t run a motor-vs-motor dyno test to look at waveforms under higher torque loads right now. I’ll probably modify my program to send PPM test motor signals rather than VESC UART to make the dyno more universal. I do have other controllers i’d like to test. After finals week though, which is this week.

1 Like

Ok, finally gotten around to making the latest batch of changes. This graph is sorta tangentially related to the VESC.

Testing procedure changed just a little. Now the power limiting (that i need to simulate my power limited situation) is external to the VESC. The code is now lowering commanded duty cycle when the power exceeds the setpoint. The dyno is now agnostic to the tested esc and motor, but still uses a vesc as the adjustable regenerative brake.

vdyno_esc_agnostic

Anyhow, the results from three green runs (where i don’t have any options to play with, so they’re all the same) show them ahead of the vesc by ~4%. Also this other esc runs at a switching frequency of 30khz (apparently, maybe i’ll put a scope on it to see if it’s real). This seems to further demonstrate there there is something problematic with the VESC’s switching frequency algorithm, if this esc really is running at 30khz.

All data was collected externally to the VESC, so the inaccurate current sensing in the vesc isn’t a cause of the discrepancy.

3 Likes

All energy measurements are using external sensing?

Now that my board is working I will see if I can do the real life tests before the new year

What frequency’s should I test? Was thinking is just 20 and 30 KHz, and if I have patience do a full discharge test for both and see how far can I go, this way we eliminate errors in the vesc energy measurements

1 Like

Yep, all energy sensing external. I’m measuring voltage and current into the esc, rpm, and force. All external sensors, and the conversion constants don’t change between runs.

IMG_20181224_185818 It’s a nutty rig, honestly.

3 Likes

what esc is the green? And the brown, blue and red are the Vesc I guess. But such low efficiency shown on the side of the graph it seems unbelievable. Peak efficiency for the Vesc at 80%. Maybe there’s some other Vesc variable that u could adjust for better results like boost or timing or something. Maybe ur particular Vesc is the issue. What version and model is it. I’ve heard ones with three shunts are more efficient

Agnostic?

Agnostic?

meaning before it needed a vesc to control the duty cycle, report rpm, current and voltage. That meant i couldn’t compare escs to each other.

Green dots are the Hobbywing hv foc esc. All others are vesc at different frequencies. Same rig, same mounting, same sensors, same calibration. These were all with a flipsky vesc 6.6 with three shunts.

It’s a little surprising to me too. The hobbywing esc is actually “designed” to go with that motor, so that’s one thing. I’m sure i could have fiddled with every button in VESCTOOL and run the tests again. Not sure if i’d have found anything different in the data. What options other than switching frequency would affect performance? I expected the VESC to be significantly better, just because of how many people are using it, and how the source is open so bugs might get caught.

My flipsky 6.6 is fucked, and i’ve finally convinced them to take it back to look at. USB on the fritz from day one, and now it just won’t detect at all. Wish me luck with that. That means that until i can get another vesc, it’ll be hard to test any other motors on the vesc. I’ve got another one coming (one of the crazy cheap 50a 4.12 hardware based ones). The one going back is the only one i own with three shunts.

Any rich folks wanna ship me a nice vesc six to test with? Or even better some vesc spinoff custom hardware? ESCape? :slight_smile:

1 Like

Pedro, i’m worried your data won’t be very conclusive, unless the road conditions and your application of throttle is just identical. However, if you wanted to try something, i’d go for 10khz, 20khz, 30khz. You might not even get any motor stability at the 10khz frequency, but if you can, run it and see!

Another thought is that you might be able to reduce battery factors somewhat by logging the power used over time “Wh Draw” in vesc tool. That way you know how much power total got used, and how far you went on that much power. It’ll also factor in voltage sag, though the motor won’t necessarily behave the same when voltage sags.

2 Likes

Yeah, I will keep the road the same and only do it with no wind, the route I use to test I can keep full throttle all the time apart from turning back, should be consistent enough

1 Like

I have a couple different escs u could try. 4.12 w updated hardware and you could use a flipsky six I have. Have some focboxes that one might work and two coming in the mail

I don’t know the variable you can adjust but have heard the timing is one. I don’t know where that is though. Have you posted this in the old or new vedder forum? Bet you’d get a lot of info there

If ur going full throttle and at top speed wouldn’t that amount to the full battery voltage directly being put to the motor as there’d be no pwm needed to reduce voltage and the back voltage would need to be overcome? If you set an erpm limit then went full throttle it would be reducing the speed and therefore need Pwm, no?

Sorry, forgot to say that, full throttle but erpm limited so the speed is constant across all battery voltage

2 Likes

Hummie, I’m not sure where the old/new forums are. I added some detail to the thread over here https://vesc-project.com/comment/2821#comment-2821

I also realised that there are a couple gaps to think about.

  1. The above graph isn’t quite apples to apples, since the vesc tests were with internal vesc power limiting, and the hobbywing tests were with external limiting. Since the internal limits are based on shoddy current measurements, they could be off and change the power range i’m examining, and thus the results could be offset. Need another vesc to see how true that is.

  2. Max efficiency on my curves are power limited to 450w. If the motor/esc max efficiency peaks at 800w, then i’ll never see that in my graphs. It’s unimportant for my testing, since my application will never see 800w, and only ever 200-450w. However, the numbers might be hampered slightly by this, and absolute max efficiency is likely higher that ~80%.

  3. I haven’t been keeping track of whether motors are tested CW or CCW (edit: though the tests in the graph above were definitely the same direction, previously in this thread i’m not sure about). I don’t understand why but i know that many motor manufacturers that do provide power/efficiency curves will have curves for both directions, and i’ve seen differences upto around 5% with only the spin direction changed. I’ll need to move back to a push/pull load cell to make that happen. I’ll also need a good way to make sure the push and pull are calibrated the same, which i can’t think of yet.

Lastly, i’d love to borrow an ESC to keep the testing going. Whatever vesc you wanna lend me, i’d be happy to test with. What is the custom hardware 4.12 you mentioned? What’s different about it? I’d be interested to try a focbox too. Those are modified 4.12 hardware, right? Hit me up via email and we’ll sort out something.

1 Like

EDIT: Nevermind, the motor sees an effective frequency of twice the pwm frequency, so the main point of this post is irrelevant.

@Petertaylor Hey guys, not sure how helpful this is, but I just took a quick look at the VESC firmware and saw this CenterAligned

Now, if I understand STM32’s advanced control timers correctly, in center aligned mode, the actual PWM frequency is Input Clock / (Period x 2). I discovered this when I read debug information from the VESC terminal, it said TIM1 and TIM8 TOP was ~6000, which did not sound right at all for center-aligned PWM. Looks like the actual switching frequency is HALF of what it is when set in VESC tool. (This would explain the high pitched ringing on my Hoverboard Motors at “35khz and up”, because it was actually 17.5khz). This also explains why “30khz” doesn’t give you DRV GVDD undervoltage faults galore.

Theoretically, on 4.12 hardware, using typical gate charge values, any real switching frequency above 22khz would overload the GVDD charge pump.

This is how sampling is determined: Timer 8 is synchronized to Timer 1, and set in up-counting mode. Capture compare channel 1 triggers ADC conversion sequence. Compare value is set to some small value (looks like 2 from what I can see), so that the start of conversion occurs close to (but not exactly, very shortly after) Timer 1 underflow and overflow (center of low and high pulse). One sample will occur when all phases are low, the other when all phases are high. If you don’t have phase shunts, the second sample (when all phases are high) is thrown out.

The way PWM is updated, the applied PWM lags behind by half a PWM period, not sure what kind of effect this has on the FOC algorithm as a whole. One way to get around this is to estimate the current at the next timer update event by extrapolation and use those values for your SMO and current control loops.

TL:DR There might be (or very likely? if I am looking at this code correctly) a firmware bug making the real switching frequency be half of the switching frequency specified in VESC tool.

Current control loop lags behind by one PWM cycle and does not compensate accordingly.

3 Likes