C2000WARE-MOTORCONTROL-SDK: F28379D

Part Number: C2000WARE-MOTORCONTROL-SDK

Tool/software:

Hi everyone,

I need deep orientation to make calculation of speed and Angle for the absolute encoder RM22SC with signal (data+, Data-, Clock +, Clock -) using Launchpad F28379D and Simulink.

I did interface the absolute encoder with IC DS26LS32CN and I did get signal Data and Clock. I did use the GPIO20 for Data and GPIO21 for Clock and connect both to the Matlab Function block to get as output the position. See the code on attached.  The output of the Matlab function times 2*pi/8192 to get the angle. However, I don't get anything as value. 

 

function position = decodeSSI(data, clock)
    %#codegen
    
    persistent bitCounter shiftRegister prevClock
    
    if isempty(bitCounter)
        bitCounter = uint32(0);
        shiftRegister = uint32(0);
        prevClock = uint32(0);
    end
    
    % Parameters
    numBits = 13; % Number of bits in the SSI word
    
    % Rising edge detection for clock
    clock = uint32(clock);  % Ensure clock is of type integer
    clockRisingEdge = (clock == 1) && (prevClock == 0);
    prevClock = clock;
    
    if clockRisingEdge
        bitCounter = bitCounter + 1;
        
        % Shift in the data bit
        shiftRegister = bitor(bitshift(shiftRegister, 1), uint32(data));
        
        % Check if we have received the full word
        if bitCounter == numBits
            position = shiftRegister;
            
            % Reset for the next word
            bitCounter = uint32(0);
            shiftRegister = uint32(0);
        else
            position = uint32(0); % or NaN to indicate incomplete data
        end
    else
        position = uint32(0); % or retain the last valid position
    end
end