8
955 PERIMETER ROAD • MANCHESTER, NH 03103 • USA
+1-603-626-2300 • FAX: +1-603-641-5336 • ALLEGROMICRO.COM
APPLICATION INFORMATION
AN296260
MCO-0001238
P0168
APPENDIX: FULL MATLAB SOURCE CODE
%% Script to showcase the A31315 DLL communication
% Author: Vijay Peddoju
% Co-Author: Till Ostermann
% Date: 2021-5-14
% Software prerequisites:
% - Matlab (tested with R2020a)
% - requires the Windows Command Library V0.7.1 or higher (download via
% registration.allegromicro.com after registration)
% - ASEK20.dll, ASEKBase.dll and ASEK20_A31315.dll files need to be accessible
% Hardware prerequisites:
% - ASEK20 with a firmware > 163.1.0 (firmware updater download available via
% registration.allegromicro.com after registration)
% - Connected TED-0002820 daughter board
% - Connected A31315 device (using grand daughter board)
% (WKUP set to high or lpm_en_c=0)
% ASEK Initialization: might need to close Matlab and restart in case of a failure
close; clear; clc;
% User selectable parameters
% The user can choose the communication method to the A31315 device. There
% are two ways to communicate with the device:
% Over voltage and over drive
%% ASEK initialization
% Configure ASEK connection
% must explicitly provide full path to DLL on net.addAssembly command
ASEK20 = NET.addAssembly( [which('ASEK20_A31315.dll')] );
A31315 = ASEK20.AssemblyHandle.CreateInstance( 'Allegro.ASEK.ASEK20_A31315' );
% seriallist function shows a list with available COM-Ports
ASEK_com = 'COMxx';
A31315.SetCommunicationPort(ASEK_com); % Set Port where ASEK is connected
% Setup the device with the proper protocol for communication
% Configure Manchester communication between ASEK-20 and A31312 device
% In case of long wire harnesses or a large capacitance on Vout, it can be
% beneficial to reduce the Manchester communication speed. The minimum
% available is 4000 (bit/s).
A31315.IsAnalogOutput = true;
A31315.SetNumberOfDie(1);
A31315.InitializeDeviceManchester();
A31315.CommunicationEnableMethod = 3; % 0 = overvoltage, 3 = overdrive
A31315.CommunicationEnableVoltage = 10.300;
A31315.SetManchesterHighVoltage(4);
A31315.SetManchesterLowVoltage(0.3);
A31315.ASEK20InternalCapacitor =1;
A31315.SetManchesterInputSamplingThreshold(1.5);
A31315.SetManchesterCommunicationSpeed(4000);
% Unlock and give message for successful unlock
% Set voltage and send unlock code
A31315.SetVcc(5.0, hex2dec('86'), hex2dec('8298A6B6'));
disp( ['Init TED-0002820 and A31315 successful. Connected on connected via ' ASEK_com '.']);
%% Measure section
% Read temperature form sensor
temp = (double(A31315.ReadPartialRegister(Allegro.ASEK.MemoryAccessType.primary,...
hex2dec('A7'), 31, 16)) / 128) + 25;
% read digital angle output
angle_dig =
double(A31315.ReadPartialRegister(Allegro.ASEK.MemoryAccessType.primary, ...
hex2dec('A7'), 15, 0));
angle_dig_0_360 = angle_dig * 360.0 / (2^16);