Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

AN1292 Application Note Microchip

Status
Not open for further replies.

electronicsman

Full Member level 5
Full Member level 5
Joined
May 4, 2012
Messages
291
Helped
11
Reputation
22
Reaction score
12
Trophy points
1,298
Activity points
3,737
I am referring to the AN1292 application note source code. I have few questions in the fuction
Code:
OPENLOOP_RAMPSPEED_INCREASERATE = 10
void CalculateParkAngle(void)
{
     else if (Startup_Ramp < END_SPEED)
			Startup_Ramp+=OPENLOOP_RAMPSPEED_INCREASERATE;

ParkParm.qAngle += (int)(Startup_Ramp >> 10);

}

and the function
Code:
SinCos();
I am bit confused of the above function. I have shown the calculations in the excel file. My main question is the output of the sincos function. Please help.
 

Attachments

  • AN1292_dsPIC33EP256MC506_INTOPAMP_MCHV2_MOTOR_80.zip
    1.6 MB · Views: 155
  • Cal.zip
    88.4 KB · Views: 130

SinCos() is updating ParkParm.qSin and ParkParm.qCos from ParkParm.qAngle. The code is in trig.s
 

Thank you very much for the reply. If you can tell me one conversion it will greatly help. First thing i am not very familiar with assembly language.
As per my calculations
Code:
#define END_SPEED (END_SPEED_RPM * NOPOLESPAIRS * LOOPTIME_SEC * 65536 / 60.0)*1024
END_SPEED_RPM 500
[B]NOPOLESPAIRS  5[/B]
LOOPTIME_SEC  0.00005  (20kHz)

END_SPEED = 139810
I am taking the NOPOLEPAIRS as 5

if Startup_Ramp = 0;
then as per the code
Code:
ParkParm.qAngle += (int)(Startup_Ramp >> 10);
ParkParm.qAngle = 0;
then how to calculate to get the values of sin and cos in parkparm ParkParm.qSin=SincosParm.qSin; ParkParm.qCos=SincosParm.qCos; with example will help me after passing through the function
Code:
sincos();
and when ParkParm.qAngle = 1; how the calculations will look like? So that i can try for all the other values.
 

You don't need to understand the assembler code because you know the result, it's converting angle into sin and cos values. The scaling is specified in trig.s, so you can reproduce operation easily in Excel.
 

I have not understood the concept in the program. I think the program is using a sine look up table size of 128. I am trying in excel file , i am doing in open loop and as of now to understand the system i am not trying in closed loop. So my calculations are some thing like this
cal1.JPG
So if you see the qAngle gets incremented and will go beyond the table index value of 128 or 360degrees. I really do not understand the conversion. Can you help me. So if i get a qangle of 1 does it mean i have to pick the element 1 of the sine table that is 1608.
Code:
SinTable: 
  .word 0,1608,3212,4808,6393,7962,9512,11039
  .word 12540,14010,15446,16846,18205,19520,20787,22005
  .word 23170,24279,25330,26319,27245,28106,28898,29621
  .word 30273,30852,31357,31785,32138,32413,32610,32728
  .word 32767,32728,32610,32413,32138,31785,31357,30852
  .word 30273,29621,28898,28106,27245,26319,25330,24279
  .word 23170,22005,20787,19520,18205,16846,15446,14010
  .word 12540,11039,9512,7962,6393,4808,3212,1608
  .word 0,-1608,-3212,-4808,-6393,-7962,-9512,-11039
  .word -12540,-14010,-15446,-16846,-18205,-19520,-20787,-22005
  .word -23170,-24279,-25330,-26319,-27245,-28106,-28898,-29621
  .word -30273,-30852,-31357,-31785,-32138,-32413,-32610,-32728
  .word -32767,-32728,-32610,-32413,-32138,-31785,-31357,-30852
  .word -30273,-29621,-28898,-28106,-27245,-26319,-25330,-24279
  .word -23170,-22005,-20787,-19520,-18205,-16846,-15446,-14010
  .word -12540,-11039,-9512,-7962,-6393,-4808,-3212,-1608
 

You apparently did not read the range specification. It says qAngle uses full 16 bit range. The size of the sine lookup table isn't related to qAngle range, the table is interpolated.

In Excel, you'll calculate
qSin = 2^15*sin(qAngle*2^-15/(2*pi()))
 
Hi,

I see the valuse of your table are from -32768 ... 0 ...+32768
But a signed _16_bit range is: -32768 ... 0 ... +32767

Thus I recommend: qSin = (2^15 -1) * sin(Angle)

Klaus
 
Hi,

I see the valuse of your table are from -32768 ... 0 ...+32768
Klaus
I do not see +32768. I am doing any mistake? Please correct me.
Code:
SinTable: 
  .word 0,1608,3212,4808,6393,7962,9512,11039
  .word 12540,14010,15446,16846,18205,19520,20787,22005
  .word 23170,24279,25330,26319,27245,28106,28898,29621
  .word 30273,30852,31357,31785,32138,32413,32610,32728
  .word 32767,32728,32610,32413,32138,31785,31357,30852
  .word 30273,29621,28898,28106,27245,26319,25330,24279
  .word 23170,22005,20787,19520,18205,16846,15446,14010
  .word 12540,11039,9512,7962,6393,4808,3212,1608
  .word 0,-1608,-3212,-4808,-6393,-7962,-9512,-11039
  .word -12540,-14010,-15446,-16846,-18205,-19520,-20787,-22005
  .word -23170,-24279,-25330,-26319,-27245,-28106,-28898,-29621
  .word -30273,-30852,-31357,-31785,-32138,-32413,-32610,-32728
  .word -32767,-32728,-32610,-32413,-32138,-31785,-31357,-30852
  .word -30273,-29621,-28898,-28106,-27245,-26319,-25330,-24279
  .word -23170,-22005,-20787,-19520,-18205,-16846,-15446,-14010
  .word -12540,-11039,-9512,-7962,-6393,-4808,-3212,-1608
 

Hi,

Sorry, my mistake, I read the values next to 32767 as 32768, but they are 32728.
So the range seems to be correct.

Klaus
 

Sorry for dragging it but i will explain my understanding as per the code which includes the assembler code, hope you will correct it if any mistake.
As per the code let us say ParkParm.qAngle = 1000. This corresponds to an actual angle of (1000/32767)*PI()= 0.0958; The sine look up table consists of 128 elements so each increment radian is 2*PI()/128 = 0.0490. The index in which the ParkParm.qAngle falls is 0.0958/0.0490 = 1.95 ~ 2. So as per the lookup table it should return 3211. This is what the trig.s should return am i correct? But as per the formula shared in the previous post does not match the calculations

qSin = 2^15*sin(qAngle*2^-15/(2*pi())) the excel returns 159.1494603

Ex:
Step1: ParkParm.qAngle = 1000
Step2: (1000/32767)*PI() = 0.0958 Actual angle in radian
Step3: 2*PI()/128 = 0.0490 Increment angle
Step4: Sine lookup table index = 0.0958/0.0490 ~2;
Step5: Sine value = 3211 .
Code:
SinTable: 
.word 0,1608,3212,4808,6393,7962,9512,11039

Please help.
 

Edit:

qSin(2) = (2^15-1) * sin((2 / 128) * 2 * pi) = 3211.727637 ~ 3212
 
Last edited:

Finally i debugged and the data are matching with qAngle and qSin thank you all for the first step. Long way to go before i run the motor and need your support.Result.JPG
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top