具有ASEK DLL谐波线性化的高级编程
具有ASEK DLL谐波线性化的高级编程
由K. Robert Bate,
雷竞技竞猜下载Allegro MicroSystems,LLC
Introduction
从工业自动化和机器雷竞技最新网址人跨越的行业中的许多应用,以电子动力转向和电机位置感测需要监测旋转轴的角度在轴上或轴外布置。
在设计中使用磁铁时,磁性输入很可能在整个旋转范围内均匀 - 它将具有固有的误差。这些磁输入误差会导致系统中的测量误差。线性化可以减少这些输入错误。
One form of linearization available on theA1332andA1335那harmonic linearizationapplies linearization in the form of up to 15 correction harmonics whose phase and amplitude are determined by means of an FFT (fast Fourier transform) performed on the data collected from one rotation of the magnet around the angle sensor IC. This technique can be readily implemented using Allegro-provided software to calculate coefficients and program on-chip EEPROM. This application note describes the functions and the process flow the customer can use if the Allegro-provided software is not flexible enough or if custom software is to be used.
Programming Requirements
所有软件都在Microsoft Visual Studio 2010上使用.NET 4.0开发。下载您要使用的设备的命令库(C#/。NET)并将其添加到其中包含的三个DLL的项目引用。
Collecting the Data
首先,关闭所有线性化算法处理;这包括零Offset,线性化旋转(RO),短行程反转(IV)和旋转芯片比特(RD)。可以留下预析化调整,例如或替换设置,IIR过滤器(FI)和预析化旋转(LR)。
在增加角度位置的方向上移动编码器。如果角度传感器IC输出也没有增加,则将LR位设置为反转角度传感器IC输出的方向或在相反的方向上旋转编码器,在这种情况下,线性化旋转位(RO)可能需要设置。有关更多详细信息,请参阅A1332 / A1335编程参考。
最佳收集方法是以等间隔的步骤旋转目标,使得所得到的数据点的数量是2.通常,32或64个均匀间隔的数据点足够。如果无法完成此操作,则收集点,并且如下一部分中所讨论的,必须预处理数据。
收集所需数据点的另一种技术是多次旋转目标,以预定义的间隔收集数据。一旦收集足够的点以覆盖目标的整个旋转,那么它们必须按照下一节中讨论的那样预处理。
Preprocessing the Data
如果收集的数据点的数量不是两个的功率,或者收集的数据不等等地间隔,则必须调整点阵列和/或使得恰好间隔。要对数据执行此操作,请调用例程resizepointarray。
x参数是编码器值阵列,y参数是在该编码器值收集的设备读数。参数Newsize是调整大小阵列的所需大小。如果x参数设置为null,则假定y值以0开始于0开始,并在360处结束。如果x参数未为空,则在执行调整大小之前将排序输入阵列。
Double [] ResizePointarray(Double [] x,Double [] Y,Int Newsize)
该例程将在输入阵列上执行立方样条插值,以产生具有所需点数的相等间隔的阵列。
初始处理
一旦收集数据并将其成阵列为2的长度,那么就可以计算谐波系数。要计算系数,请呼叫例程计算哈马克乐谱。
HarmonicCoefficients[] CalculateHarmonicLinearCoefficients (double[] points, out bool pointError)
Its input is the array of angles that has been collected. The routine performs an FFT and will return the array of coefficients and a warning flag. The point error warning flag is set when one or more of the input angles is greater than 20 degrees different from what the routine calculates it should be.
例如,对于8个条目阵列,例程计算角度应为[0,45,90,135,180,225,270,315]。如果输入阵列是[0,45,90,135,180,204,270,315],则例程将设置指针,因为第六阵列条目具有大于20度的误差。
选择谐波
一旦计算了所有谐波系数,必须选择所需的谐波。通常,计算例程生成的谐波数将超过设备可以支持的谐波数量,因此必须选择一些选择相关谐波的算法。
The number of harmonics used is also dependent on which device and which features are used. For the A1332, the maximum number of harmonics is 15, but if the maximum is used, a number of programmable features will use the defaults, such as short-stroke configurations and specific I2C and SPI settings. The maximum number of harmonics without using the defaults for those programmable features is 9. For the A1335, the maximum number of harmonics is 11, but to get this number, a number of programmable features will use the defaults, such as the short-stroke settings. The maximum number of harmonics without using the defaults for those programmable features is 8.
The simplest algorithm to use is to select the first harmonic through to the desired number of harmonics. While easy, it will select harmonics that will not significantly influence the output.
The current algorithm that is used in the Allegro A1335 Samples Programmer is to select the harmonic where the amplitude is greater than 0.3. One limitation in the current hardware to note is that only 4 harmonics can be skipped between selected harmonics. If there is a jump greater than 4, then as many harmonics as needed between the last harmonic selected and the desired harmonic also need to be selected.
编程设备
Once the harmonics have been selected, then the values to be written into the device can be generated by calling the routine GenerateHarmonicLinearizationDeviceValues.
HarmonicDeviceValues []生成哈卡卡猴弹性DeviceValues(HasbonicCoefients []系数)
谐波系数被传递到该例程中,并且它返回编程设备所需的值的数组。此例程将抛出的唯一例外情况是在所选系数之间跳过超过4个谐波系数的情况。
To program the device for harmonic linearization, the HL flag must be set, the HAR_MAX field must be set to the number of coefficients to be used, and the HARMONIC_PHASE_n, ADV_n, and HARMONIC_AMPLITUDE_n fields must be written.
Example Code
using System;
using Allegro.ASEK;
命名空间handoniclinearizationexample.
{
公共类HasmonicLizationExample.
{
公共HandonicLizationExample()
{
}
公共void程序armonearization(String Filepath,Asek Asekprogrammer)
{
try
{
HarmonicCoefficients[] hc;
bool pointError = false;
double []点= null;
string fieldBuffer = File.ReadAllText(filePath);
弦线;
List
List
// 1.1收集数据
// Read in the angles from a text file. Blank lines or lines starting with a # are ignored.
if (!string.IsNullOrEmpty(fieldBuffer))
{
使用(stringReader SR = New StringReader(FieldBuffer))
{
而((line = sr.readline())!= null)
{
line = line.trim();
if (string.IsNullOrEmpty(line) || line.StartsWith("#"))
{
continue;
}
// Each line can be in 1 of 2 forms.
// The first contains an encoder angle then the angle from the device separated by a comma (22.125,23.543)
//或只是从设备的角度。(23.543)
//如果角度不等于间隔,则需要两个值。
string[] values = line.Split(‘,’);
if(值.Length> 1)
{
double encoder = convert.todouble(值[0]);
while (encoder >= 360.0)
{
编码器 - = 360.0;
}
while (encoder < 0.0)
{
编码器+ = 360.0;
}
encoderReadings.Add(encoder);
devicereadings.add(convert.todouble(值[1]));
}
其他
{
devicereadings.add(convert.todouble(值[0]));
}
}
}
// 1.2预处理数据
if(!Poweroftwo(devicereadings.count()))
{
//如果点数为OFF,则只需删除最后一个,
if(poweroftwo(devicereadings.count.count() - 1))
{
devicereadings.removeat(devicereadings.count() - 1);
points = deviceReadings.ToArray();
}
其他
{
// otherwise calculate the number of desired samples.
// If the number of samples is less then 64 then round
// up to the nearest power of two, otherwise round down.
int desiredSamples = 8;
虽然(所探伤的
desiredSamples *= 2;
}
if(devicereadings.count()> 64)
{
desiredSamples /= 2;
}
// If there are no encoder readings, assume the devices readings are equally spaced.
if(encoderreadings.count()!= devicereadings.count())
{
//将角度列表转换为数组and then resize it.
points = ((IHarmonicLinearization)asekProgrammer).ResizePointArray(null, deviceReadings.ToArray(), desiredSamples);
}
其他
{
//将角度列表转换为数组and then resize it.
点=((iharmoniclinearization)asekprogrammer).resizepointarray(Encoderreadings.toArray(),devicereadings.toarray(),jusiningsamples);
}
}
}
其他
{
//将角度列表转换为数组
points = deviceReadings.ToArray();
}
// 1.3初始处理
//计算来自点数组的系数。
HC =((IharmoniclineArization)Asekprogrammer).CalculateHarmonicLineAlcoefiers(点,out PointRor);
// A point error is what happens when one or more of the angles is more then 20 degrees different then what the routine thinks it should be.
// For example if an array of 8 values is to be used [0, 45, 90, 135, 180, 204, 270, 315] the calculate would flag a warning for the 6th
/ /入口array because it should be closer to 225 than it is.
if(pointerror)
{
MessageBox.show(“其中一个角度从所需的内容越多20度。”);
}
// 1.4 Selection of Harmonics
// Once the array of harmonic coefficients has been calculated, the coefficients need to be selected. The number of coefficients that
// the calculate routine returns will generally exceed the number of coefficients the devices can support so some method of limiting the number
//需要系数。可以挑选前8或可以使用另一种方法。
int numberofharmoniccomponents = hc.length;
int numberOfSelectedHarmonicComponents = 0;
int lastHarmonicComponentSelected = 0;
int maxHarmonicComponentsSelected = 8; // maximum number of harmonics that can be used before impacting other features on the device
//对于此示例,选择幅度超过0.3的前8个谐波。
for(int index = 0; index
if((hc [index] .amplitude> 0.3)&&(numberofselectedharmoniccomponents
//如果要选择的谐波之间的谐波数量
// and the last harmonic selected is greater then 4 then some of the
// harmonics between then need to be selected.
int skip = index - lastHarmonicComponentSelected;
如果(跳过> 4)
{
// Make sure that the number of harmonics that will need to be selected
//不超过所需的数字。
int numberNeeded = skip / 4;
if((numberneededed + numberofselectedharmoniccomponents)<= maxharmoniccomponentsselect)
{
for(int jndex = 1; jndex <= number4eded; ++ jndex)
{
hc [jndex] .select = true;
++ numberofselectedharmoniccomponents;
}
hc [index] .select = true;
++ numberofselectedharmoniccomponents;
}
其他
{
//代码无法在不超过的情况下选择所需的谐波
// the maximum number of coefficients selected so it will stop selecting.
打破;
}
}
其他
{
hc [index] .select = true;
++ numberofselectedharmoniccomponents;
}
LastharmonicComponentselect =指数;
}
}
/ /如果没有谐波选中,然后选择the first 8.
if(numberofselectedharmoniccomponents == 0)
{
for(int i = 0;(i
hc[i].select = true;
++ numberofselectedharmoniccomponents;
}
}
// 1.5编程设备
// Generate the values needed to be written into the eeprom.
HarmonicDeviceValues [] EEPROMVALUES =((IHARMONICLINARIZEARIZE)ASEKPROGGRAMMAMER).generateHarmonicLIZAZEVICEVALUES(HC);
//确保设备上的电源
asekprogrammer.setvcc(5.0);
//使写入设备的EEPROM,这需要使SRAM写入并停止处理器
((isramwriteacessmode)asekprogrammer).setsramwriteaccessmode();
((iProcessorMode)ASekprogrammer).setprocessoridle();
//在EEPROM中打开谐波线性化
((iRegisterAccess)ASekprogrammer).writepartialRegister(MeminityAccessType.extended,0x306,15,15);// hl = 1
//设置要使用的谐波数量
((iRegisterAccess)ASekprogrammer).writepartialRegister(MemineScessType.extended,0x309,EEPROMVALUES.LENGTH,19,16);// har_max =谐波的数量
//为谐波
for (uint index = 0; index < eepromValues.Length; ++index)
{
uint registerValue = (uint)(((eepromValues[index].phase << 12) & 0x0FFF000) +
((EEPROMVALUES [INDEX] .Advance << 10)&0x0C00)+
(eepromValues[index].amplitude & 0x03FF));
((IRegisterAccess)asekProgrammer).WriteRegister(MemoryAccessType.extended, 0x30C + index, registerValue); // HARMONIC_PHASE, ADV and HARMONIC_AMPLITUDE
}
//关闭电源然后重新打开以确保设备使用新的线性化值。
asekprogrammer.setvccoff();
asekprogrammer.setvcc(5.0);
}
}
catch (Exception ex)
{
MessageBox.show(ex.message);
}
}
私人BOOL Poweroftwo(INT值)
{
int log2npoints = 0;
int j = value;
虽然((j> 0)&&((j&1)== 0))//计算的输入值
{
log2npoints ++;
j >> = 1;
}
if((值<2)||(值!=(1 << log2npoints)))
{
返回false;
}
返回true;
}
}
}
角度输入文件格式
This file contains a list of angle values. If there are two values separated by a comma, then the first value is the encoder angle and the second value is the device angle. Lines can be blank, or if they start with #, then they are considered comments.
Example of Angles Input file:
329.59
354.81
6.832
13.566
17.592
20.228
22.638
24.638
25.956.
27.454
28.77
30.054
30.966
有两列:
0,123
22.5,145.5.
45,168
67.5,190.5
90,213
112.5,235.5
135,258
157.5,280.5.
180,303
202.5,325.5.
225,348
247.5,10.5
270,33
292.5,55.5
315,78.
337.5,100.5.