• AVR Freaks

AnsweredHot!Running Average in AN1292 application note

Page: 12 > Showing page 1 of 2
Author
microLearner
Senior Member
  • Total Posts : 122
  • Reward points : 0
  • Joined: 2017/02/27 20:26:37
  • Location: 0
  • Status: offline
2019/10/04 23:13:17 (permalink)
0

Running Average in AN1292 application note

I have seen the following statement in the source code of the AN1292 application note
"Running average value of ADC-Ave is maintained and subtracted from ;  ADC value before scaling."
What is the importance of this running average? Can someone please explain me with an example how it will affect? Please advise.
#1
rodims
Super Member
  • Total Posts : 1532
  • Reward points : 0
  • Joined: 2009/02/10 11:08:59
  • Location: 51.9627, 7.6262
  • Status: offline
Re: Running Average in AN1292 application note 2019/10/05 06:34:33 (permalink) ☄ Helpfulby microLearner 2019/10/25 21:07:33
#2
du00000001
Just Some Member
  • Total Posts : 3244
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: online
Re: Running Average in AN1292 application note 2019/10/06 07:19:13 (permalink) ☄ Helpfulby microLearner 2019/10/25 21:07:40
0
I didn't check vs. AN1292, but the rolling/moving/running/sliding average is a means to calculate the (short-term) mean value of some input.
Especially the exponential form can be calculated with little effort as an IIR Filter
O(t) = O(t-1) * (k - 1)/k + I(t) * 1/k        O: output value / buffer; I: input value
Even less effort if k is a power of 2, reducing the divisions to shifting.
 
So, following the calculation of the difference you're scaling the deviation from the mean value.
post edited by du00000001 - 2019/10/06 07:22:13

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#3
NorthGuy
Super Member
  • Total Posts : 5817
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: offline
Re: Running Average in AN1292 application note 2019/10/06 07:36:54 (permalink) ☄ Helpfulby microLearner 2019/10/25 21:07:48
4 (1)
Moving average works as low-pass filter. If you have noisy signal which jumps up and down, you can average several consecutive ADC reading to produce more stable result.
#4
microLearner
Senior Member
  • Total Posts : 122
  • Reward points : 0
  • Joined: 2017/02/27 20:26:37
  • Location: 0
  • Status: offline
Re: Running Average in AN1292 application note 2019/10/25 22:08:49 (permalink)
0
With An2192 i could see the motor running but in open loop. Trying to run in closed loop using the encoder, will come back for clarifications. Thank you for the support. But if i run it for some time the power section ICs are getting heated. Generally to run a motor will there be any timing constraints like i have to run the motor for some time then power off and then re run it?
post edited by microLearner - 2019/10/25 22:13:53
#5
du00000001
Just Some Member
  • Total Posts : 3244
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: online
Re: Running Average in AN1292 application note 2019/10/25 22:26:17 (permalink)
0
It's quite normal for the power section to heat up - - - as there is quite some power dissipated during conduction and switching. I know nothing about your motor,  but multiple amps of current are not uncommon.
BTW: what temperature is "heated" - and at which ambient temperature?

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#6
microLearner
Senior Member
  • Total Posts : 122
  • Reward points : 0
  • Joined: 2017/02/27 20:26:37
  • Location: 0
  • Status: offline
Re: Running Average in AN1292 application note 2019/10/25 23:00:13 (permalink)
0
Thank you for the reply. I have purchased MCLV-2 development board along with the Motor.The motor is 10 pole, 24V Hurst motor
https://www.microchip.com/DevelopmentTools/ProductDetails/PartNO/AC300020
Temperature heated -- I really did not measure it but if i try to touch the Mosfets with hand they are quite hot. The ambient temperature is the room temperature is approx. 30DegreesCentigrade.
 
#7
du00000001
Just Some Member
  • Total Posts : 3244
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: online
Re: Running Average in AN1292 application note 2019/10/26 01:59:16 (permalink) ☄ Helpfulby microLearner 2019/10/26 02:06:50
0
OK, the MCLV is not exactly made for 24/7 operation at high ambient temperatures. But if you can still touch the MOSFETs, they do not exceed 70 °C. Have you noticed the motor's temperature? It's not staying cool as well.
Overall (my own experience with tbis combo): unless operated at currents near or exceeding 2 A, you should be able to operate this setup for hours if necessary.

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#8
microLearner
Senior Member
  • Total Posts : 122
  • Reward points : 0
  • Joined: 2017/02/27 20:26:37
  • Location: 0
  • Status: offline
Re: Running Average in AN1292 application note 2019/10/28 08:10:54 (permalink)
0
Bit confused now, the AC300020 motor is not encoder based but it is hall sensor. The part number AC300022 is  encoder based. Most of the microchip application notes are sensorless. I want to try sensored then go for sensorless control. Please advise me on how to proceed further?
#9
microLearner
Senior Member
  • Total Posts : 122
  • Reward points : 0
  • Joined: 2017/02/27 20:26:37
  • Location: 0
  • Status: offline
Re: Running Average in AN1292 application note 2019/10/28 08:20:57 (permalink)
0
I want to add Sensored FOC and Sensorless FOC.
#10
du00000001
Just Some Member
  • Total Posts : 3244
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: online
Re: Running Average in AN1292 application note 2019/10/28 08:38:41 (permalink)
0
Hi,
while both motors are basically useable for sensorless control (see the product page - they explicitly state that), AC300022 is the more versatile solution as it sports both, Hall AND Encoder, position sensing systems. (That's the one I possess.)
And during the transitional phase you can use the sensor to check/validate your sensorless position calulations...
 

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#11
microLearner
Senior Member
  • Total Posts : 122
  • Reward points : 0
  • Joined: 2017/02/27 20:26:37
  • Location: 0
  • Status: offline
Re: Running Average in AN1292 application note 2019/10/29 02:19:28 (permalink)
0
I am checking the hall signals on the scope i could only see the Hall C signal on the test points. The resistors of Hall A and Hall B R72, R75 seem to be opened.I can see the hall waveform before the resistor but not after the resistors R72 and R75, but I can see on R78 resistor. Can this happen I don't visibly see any damage on the board. How to proceed further? The schematic is available in the following location http://ww1.microchip.com/downloads/en/devicedoc/ds-52080a.pdf
 
I am checking the hall signals on the scope i could only see the Hall C signal on the test points. The resistors of Hall A and Hall B R72, R75 seem to be opened.I can see the hall waveform before the resistor but not after the resistors R72 and R75, but I can see on R78 resistor. Can this happen I don't visibly see any damage on the board. How to proceed further?

Attached Image(s)

#12
du00000001
Just Some Member
  • Total Posts : 3244
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: online
Re: Running Average in AN1292 application note 2019/10/29 02:27:50 (permalink) ☼ Best Answerby microLearner 2019/10/29 05:19:13
5 (1)
I'd suggest to remove the PIM and check again.
(A wrongly configured microcontroller could pull the inputs down or up - making them to appear defective. Given the resistors' values it's not very likely that they could become damaged.)

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#13
microLearner
Senior Member
  • Total Posts : 122
  • Reward points : 0
  • Joined: 2017/02/27 20:26:37
  • Location: 0
  • Status: offline
Re: Running Average in AN1292 application note 2019/10/29 05:19:02 (permalink)
0
You are absolutely correct. Wrong port configuration, corrected it could see all the Hall signals. Thank you for the support.  Proceeding to calculate the rotor position using the Hall signals.      
#14
microLearner
Senior Member
  • Total Posts : 122
  • Reward points : 0
  • Joined: 2017/02/27 20:26:37
  • Location: 0
  • Status: offline
Re: Running Average in AN1292 application note 2019/10/30 02:17:38 (permalink)
0
Could you please review this logic?  The logic for calculating the rotor angle every pwm cycle and passing as input to the FOC logic.
Let Fhall be the frequency of the hall signal and Thall the hall sensor time
Thall = 1/Fhall   --->1
To cover PI/3 radians it will take Thall time.  (1 Hall pulse will be 60degrees)
Let the time of pwm frequency is Tpwm. (Currently working with 20KHz or 50uS)
In Tpwm time it will cover an angle of (PI/3 * Tpwm /Thall)= Electrical Angle
The mechanical angle increment is (PI/3)*(Tpwm)/(Thall*Noofpolepairs)
If HallA=1,HallB=0, Hallc=0, Rotor position is 0degrees. if rotor position is greater than 2*PI then reset to 0.
#15
du00000001
Just Some Member
  • Total Posts : 3244
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: online
Re: Running Average in AN1292 application note 2019/10/30 08:21:34 (permalink)
0
The formulas are looking good so far.
 
To simplify:
mechanical angle = electrical angle / No of pole pairs
 
Minor corrections:
  • if rotor position > 2*PI, rotor position = rotor position - 2 * PI
    (Otherwise you might "loose" some angle - 'til the next round.)
  • HallA == 1, HalLB == HallC == 0 is valid for an angular range of 60 ° (PI/3).
    So you'd better define some Hall sensor transition (e.g. HallA 0 -> 1) as the 0 ° reference position.

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#16
microLearner
Senior Member
  • Total Posts : 122
  • Reward points : 0
  • Joined: 2017/02/27 20:26:37
  • Location: 0
  • Status: offline
Re: Running Average in AN1292 application note 2019/11/03 08:32:47 (permalink)
0
I had to change the logic as the application project included the sine look up table implementation in assembly code. I incremented the counter to calculate the Hall Time Thall = counter++;
For sine look up table implementation i changed the PI radians with 32767, so the formula looked as
(PI/3)*(Tpwm)/(Thall*Noofpolepairs) = (32767 * Tpwm )/(3*counter*Tpwm*Noofpolepairs)
Canceling the Tpwm the equation is
32767/(3*counter* Noofpolepairs) = 2184/counter;
To avoid floating calculations i used the following code from the compiler user guide

l_fre_u16 = __builtin_divud(2184,gs_final_fre_u16);
g_rotorangle_u16 += l_fre_u16;
SincosParm.qAngle = (int)g_rotorangle_u16;
SinCos();
ParkParm.qSin=SincosParm.qSin;
ParkParm.qCos=SincosParm.qCos;

Is the above logic is ok? Could you please review? One other confusion is shifting from open to closed loop.
#17
du00000001
Just Some Member
  • Total Posts : 3244
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: online
Re: Running Average in AN1292 application note 2019/11/04 07:23:42 (permalink)
0
  1. Aquiring the transition of the hall sensors per input capture would be superior to some counter incrementing.
    Although the latter isn't unusable. Especially at higher activation frequencies of the control loop (somewhere >= 20 kHz).
  2. If at all, I'set the PI radian to equate 32678, not 32767. But this is just a minor issue.
  3. Re your calculations: not sure about that. What does g_rotorangle_u16 really count? angles up to 2 * PI ?

Re confusion about shifting from open to closed loop:
The closed loop is just the open loop - PLUS a correction of the rotor position that stems from the feedback.
  • The open loop can only be based on the THall (period of the last 2 hall sensor transitions). This is ok when the speed is constant, but has errors during acceleration/deceleration.
  • The closed loop's position feedback tends to be "nearer" to the real rotor position, although some delay will always exist (independent from the means of position sensing).
  • So closed loop is an improvement vs. the open loop control, although not perfect.
    Adding some predictive correction to the position sensed might further improve the position feedback. But this is a somewhat different story for freaks.

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#18
microLearner
Senior Member
  • Total Posts : 122
  • Reward points : 0
  • Joined: 2017/02/27 20:26:37
  • Location: 0
  • Status: offline
Re: Running Average in AN1292 application note 2019/11/04 10:31:49 (permalink)
0
du00000001
 
Aquiring the transition of the hall sensors per input capture would be superior to some counter incrementing.
Although the latter isn't unusable. Especially at higher activation frequencies of the control loop (somewhere >= 20 kHz).   

      I plan to do this probably once i am somewhat confident of the existing method using counter.
 
du00000001
If at all, I'set the PI radian to equate 32678, not 32767. But this is just a minor issue.

  I have changed it.
du00000001
Re your calculations: not sure about that. What does g_rotorangle_u16 really count? angles up to 2 * PI ?

Yes there are big mistakes i found after your comments.  g_rotorangle_u16 is used to count angles upto 2 * Pi, I have used unsigned int, but i have to change it to signed int. The logic is increment the angle l_fre_u16 and assign it to g_rotorangle_u16.




#19
du00000001
Just Some Member
  • Total Posts : 3244
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: online
Re: Running Average in AN1292 application note 2019/11/04 10:44:06 (permalink)
0

g_rotorangle_u16 is used to count angles upto 2 * Pi, I have used unsigned int, but i have to change it to signed int.

 
Basically it doesn't matter whether g_rotorangle_u16 is used unsigned (counting 0..2*PI) or signed (counting -PI..PI). This only depends on how the variable is used in the further processing. But no objection if -PI..PI fits your calculations. (Which might be the case when using usual sin/cos prebuilt function implementations.)
 
It was only important that PI equals 32768, providing a continuous angular system without some "hole".
(With this specification, 2 PI would equal 65536 - in effect 0. Which fits the fact that 2 PI and 0 represent the same angle.)
 
 

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#20
Page: 12 > Showing page 1 of 2
Jump to:
© 2019 APG vNext Commercial Version 4.5