Hi everyone,
I have to control a sinusoidal BLDC through a PWM and an H-bridge, following a profile written in a table.
I have encoders reading as feedback but I have not quite well understood how to measure the difference between the position table and the encoders reading.
In general if the encoder reading is in the same turn as the table than everything is fine:
p = 78 deg (position) m = 75 deg (measure)
e = p - m = 3 deg
But when I cross the 0 deg (360 deg) I have some stupid issues with signs:
p = 359 deg m = 1 deg
e = p - m = 358 deg
while I would like to get -2 deg! Even with modulo function I'd not be better off:
e = mod(p - m, 360) = 358 deg!
Should it be dependent on the quadrant I'm in?
I'm missing some basics here. And yes, a pointer to elementary school math is definitely appreciated!
Al