RP2040 No low-side current support


We just made a motor controller with the DRV8323HRTAR and RP2040, and wanted to use SimpleFOC for current sensing on low-side. I noticed that SimpleFOC says it doesn’t support it though. Is there a reason for this?

Hi @Electrium_Mobility,

yes, the first was that, even though in theory there should be a DREQ to trigger DMA from the PWM, I could not get it to work. I am not sure if this is a silicon problem, a problem of my code, or the fact that the RP2040 Arduino core is on a fairly old SDK version. I could not get it to work, but I didn’t try with the earlehillpower core.

The DREQ is also at the wrong time in the PWM IIRC, and would involve inverting the PWM logic in some way to get the DREQ during the low-side on-time.

But the main reason is that it is unlikely to work well even if the chain of DMA requests were working. This is because the Pico’s ADC, in addition to its other faults, is very slow, and can only convert one channel at a time. So in response to a DMA trigger from PWM, it would have to convert at least 2 channels in succession, and this would not happen in time on low duty cycles, as the on-time of the PWM is too short.

Hmm, that makes sense.

In theory everything should be put together, but it seems that there are some intrinsic bugs on the RP2040 that doesn’t allow it to fully operate for the MCU.

We will try to see if we can get results with the earlehillpower core, and see if that makes any difference.


1 Like

Hai! @Electrium_Mobility

Could you try to run this loop on the RP2040, I’m curious to see how it performs without FPU?

long start_ticks = 0;
long stop_ticks = 0;
float elapsed_ticks = 0.0f;
float angle = 0.0f;
int count = 0;

start_ticks = micros();
for (angle = -pi; angle <= pi; angle += 0.001, count++) {

float angle2 = angle;
angle2 = _normalizeAngle(angle2);
float _ca = _cos(angle2);
float _sa = _sin(angle2);


stop_ticks = micros();

elapsed_ticks = stop_ticks-start_ticks;

Serial.print("Iterations: ");
Serial.print("elapsed_ticks: ");
Serial.println(elapsed_ticks, 4);
Serial.print("time per iterasion: ");
Serial.println(elapsed_ticks / count, 4);




Sorry about that, just got our PCB shipped recently.
These are the results with your script running that code in the loop. I let it loop 20 times in order to get these results.

Iterations: 1
elapsed_ticks: 4999980.0000
time per iterasion: 4999980.0000
Iterations: 2
elapsed_ticks: 10005816.0000
time per iterasion: 5002908.0000
Iterations: 3
elapsed_ticks: 15007795.0000
time per iterasion: 5002598.5000
Iterations: 4
elapsed_ticks: 20009784.0000
time per iterasion: 5002446.0000
Iterations: 5
elapsed_ticks: 25011784.0000
Iterations: 6
elapsed_ticks: 30012784.0000
time per iterasion: 5002130.5000
Iterations: 7
elapsed_ticks: 35014784.0000
time per iterasion: 5002112.0000
Iterations: 8
elapsed_ticks: 40016784.0000
time per iterasion: 5002098.0000
Iterations: 9
elapsed_ticks: 45018784.0000
time per iterasion: 5002087.0000
Iterations: 10
elapsed_ticks: 50020784.0000
time per iterasion: 5002078.5000
Iterations: 11
elapsed_ticks: 55023788.0000
time per iterasion: 5002162.5000
Iterations: 12
elapsed_ticks: 60025784.0000
time per iterasion: 5002148.5000
Iterations: 13
elapsed_ticks: 65027784.0000
time per iterasion: 5002137.0000
Iterations: 14
elapsed_ticks: 70029784.0000
time per iterasion: 5002127.5000
Iterations: 15
elapsed_ticks: 75031784.0000
time per iterasion: 5002119.0000
Iterations: 16
elapsed_ticks: 80033784.0000
time per iterasion: 5002111.5000
Iterations: 17
elapsed_ticks: 85035792.0000
time per iterasion: 5002105.5000
Iterations: 18
elapsed_ticks: 90037784.0000
time per iterasion: 5002099.0000
Iterations: 19
elapsed_ticks: 95039784.0000
time per iterasion: 5002094.0000
Iterations: 20
elapsed_ticks: 100041784.0000
time per iterasion: 5002089.0000


Wow, something went wrong with the test.

the idea is to let it run through -pi to +pi.

for (angle = -pi; angle <= pi; angle += 0.001, count++) {

float angle2 = angle;
angle2 = _normalizeAngle(angle2);
float _ca = _cos(angle2);
float _sa = _sin(angle2);


And then time it…

Hi, re-ran it with for loop again.

Iterations: 1
elapsed_ticks: 122751.0000
time per iterasion: 19.5339
Iterations: 2
elapsed_ticks: 122441.0000
time per iterasion: 19.4846
Iterations: 3
elapsed_ticks: 122364.0000
time per iterasion: 19.4723
Iterations: 4
elapsed_ticks: 122374.0000
time per iterasion: 19.4739
Iterations: 5
elapsed_ticks: 122354.0000
time per iterasion: 19.4707

Thanks again,
Sherwin Chiu

Ok, then you should be avle to speed thinges up by looking at this →

It is 20micro seconds for each for loop. Is that not good enough?

Sure, but if you need faster calculations then apparently it can be optimized.

It all depends on your use case and how your trials go.

Looking forward to see your progress!