2025-11-09 8:51 AM
Hi;
I recently started playing with CubeMonitor - it's fantastic. I am using it to troubleshoot/fine tune a motor control project I'm working on - specifically, I am graphing the values I'm calculating for Space Vector Modulation to make sure things are working as I expect.
Something odd I notice are these strange "glitches" in my waveforms:
There is nothing obvious I can find in my algorithm that might cause these - I am wondering instead if they might be coming either from 1) some nuance in C I might not be aware of, or 2) something I don't have configured properly in CubeMonitor.
To check the former: in my SVM algorithm, I do something like:
typedef struct {
float theta_rad;
float u, v, w;
float alpha, beta;
float d, q;
} FOC_HandleTypeDef;
void calculate_svm(FOC_HandleTypeDef *foc)
{
// ... some stuff happens before this,
// but at one point I use some members of
// FOC as 'inputs'
float uvw_min = fminf(foc->u, fminf(foc->v, foc->w));
float uvw_max = fmaxf(foc->u, fmaxf(foc->v, foc->w));
float wave = (uvw_min + uvw_max);
// .. then write back out to them as 'outputs'
foc->u += wave;
foc->v += wave;
foc->w += wave;
}I notice that if I restructure my code to look more like this:
typedef struct {
float theta_rad;
float in_u, in_v, in_w;
float out_u, out_v, out_w;
float alpha, beta;
float d, q;
} FOC_HandleTypeDef;
void calculate_svm(FOC_HandleTypeDef *foc)
{
// let's separate the 'input' members from
// the "output" members, and be more
// explicit about things.
float out_u, out_v, out_w;
float uvw_min = fminf(foc->in_u, fminf(foc->in_v, foc->in_w));
float uvw_max = fmaxf(foc->in_u, fmaxf(foc->in_v, foc->in_w));
float wave = (uvw_min + uvw_max);
out_u = foc->in_u + wave;
out_v = foc->in_v + wave;
out_u = foc->in_w + wave;
foc->out_u = out_u;
foc->out_v = out_v;
foc->out_w = out_w;
}So here I am not reading from and writing to the same member variables in my input struct. When I do this, I notice the "glitches" go away in cubeMonitor:
I'd like to understand why this might be? I am doing all of this work in a simple while loop at the moment while I test my code - there are no interrupts or any apparent contention for the variables I'm working with:
FOC_HandleTypeDef foc;
foc.theta_rad = 0.0f;
foc.d = 0;
foc.q = 1;
while(1) {
calculate_svm(&foc);
foc.theta_rad += 0.001f;
osDelay(pdMS_TO_TICKS(1));
}Thank you! And apologies if it turns out this is more a C question than a cubeMonitor question...were it not for cubeMonitor I'm not sure I would have uncovered this.