%% Monitor Resolver Using Serial Communication
% 
% This example operates the resolver sensor to measure the rotor position. The resolver consists of two orthogonally placed stator windings placed around the resolver rotor winding. After you mount the resolver sensor over a PMSM, the resolver rotor winding rotates along with the shaft of the running motor. The controller provides a fixed frequency alternating excitation signal to the resolver rotor winding. When the resolver rotor rotates, the resolver stator windings produce output (secondary sine and cosine) signals that are modulated with the sine and cosine of the shaft angle or position. After receiving the secondary signals, the controller samples and normalizes them.
% 
% <<../mcb_resolver.png>>
% 
% <<../mcb_resolver_plot.png>>
% 

% Copyright 2020 The MathWorks, Inc.

%% Models
% 
% The example includes the model
% <matlab:open_system('mcb_resolver_f28069m') mcb_resolver_f28069m>.
% 
% You can use this model only for code generation. You can also use the open_system command to open the Simulink(R) model. For example, use this command for a F28069M based controller:
%%
open_system('mcb_resolver_f28069m.slx');
%%
% 
%% Required MathWorks(R) Products
% 
% For the model: *mcb_resolver_f28069m*
% 
% * Motor Control Blockset(TM)
% * Embedded Coder(R)
% * Embedded Coder(R) Support Package for Texas Instruments(TM) C2000(TM) Processors
% * Fixed-Point Designer(TM)
% 
%% Prerequisite
% 
% We provide default inverter parameters with the target model. If you want to change the default values, you can update the inverter parameters in the model initialization script
% associated with the Simulink(R) model. For instructions, see
% <docid:mcb_gs#mw_dd32d1fd-68d8-4cfd-8dea-ef7f7ed008c0 Estimate Control Gains from Motor Parameters>.
% 
%% Generate Code and Deploy Model to Target Hardware
% This section instructs you to generate code and run the FOC algorithm on
% the target hardware.
% 
% The example uses a host and a target model. The host model is a user interface to the controller hardware board.  You can run the host model on the host computer. The prerequisite to use the host model is to deploy the target model to the controller hardware board. The controller in the target model uses the Resolver Decoder block to process the sampled and normalized secondary sine and cosine signals to obtain the shaft (or motor) position. The host model uses serial communication to command the target model and obtain the computed shaft angle from the controller. You can observe the computed shaft position in the Time Scope block of the host model.
% 
% *Required Hardware*
%
% The example supports this hardware configuration. You can also use the target model name to open the model for the corresponding hardware configuration, from the MATLAB(R) command prompt.
% 
% * LAUNCHXL-F28069M controller + BOOSTXL-DRV8305 inverter: <matlab:open_system('mcb_resolver_f28069m') mcb_resolver_f28069m>
% 
% For connections related to the preceding hardware configuration, see <docid:mcb_gs#mw_8a869325-5b0d-4631-afd5-05a23622cc5c Hardware Connections for LAUNCHXL board>.
% 
% *Generate Code and Run Model on Target Hardware*
%
% *1.* Complete the hardware connections and open the target model *mcb_resolver_f28069m*.
% 
% *2.* Load a sample program to CPU2 of LAUNCHXL-F28379D, for example, program that operates the CPU2 blue LED by using GPIO31 (c28379D_cpu2_blink.slx), to ensure that CPU2 is not mistakenly configured to use the board peripherals intended for CPU1.
% 
% *3.* Click *Build, Deploy & Start* on the *Hardware* tab to deploy the target model to the hardware.
% 
% *4.* Click the *host model* hyperlink in the target model to open the associated host model. You can also use the open_system command to open the host model. For example, use this command for the F28069M based controller:
%%
open_system('mcb_resolver_host_read.slx');
%%
% For details about the serial communication between the host and target
% models, see <docid:mcb_gs#mw_7d703f4b-0b29-4ec7-a42b-0b300f580ccc Communication between Host and Target>.
% 
% *5.* In the Serial Receive and Serial Configuration block masks of the host model, select a Communication port value.
% 
% *6.* If you want to change the default baud rate (in the host and target models), use the Serial Configuration block mask in the models to select a different Baud rate value.
% 
% *7.* Click *Run* on the *Simulation* tab to run the host model.
% 
% *8.* Open the Time Scope block in the host model.
% 
% *9.* Rotate the resolver shaft and observe the computed shaft position signal in the Time Scope block.
% 