UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Adventurer
Adventurer
325 Views
Registered: ‎06-04-2019

MCode Data Type Mismatch

Hello,

I designed a simple FSM using MCode. The FSM is used to increment a config variable. The code is as below,

 

function [configValid,configFsel] = coefficientSwitch(tready)
    % switches between the coefficient sets to configure the config channel
    %#codegen
       
    nCoeSets        = 2;
    bCoeID          = xl_nbits(nCoeSets-1); % =1

    
    % State definitions
    START      = 0;
    SWITCHING  = 1;  
    bState     = xl_nbits(2); % Number of bits to represent a state

    
    % Assign registers for all output and intermediate variables  
    persistent configValidReg, configValidReg = xl_state(false,{xlBoolean});
    persistent configFselReg, configFselReg = xl_state(0,{xlUnsigned,bCoeID,0}); 
    persistent stateReg, stateReg = xl_state(START,{xlUnsigned,bState,0});
    
    
    %% Switching
    
    if(tready) % data reception starts
        
        switch double(stateReg)
            
            case START        
                % Assert the Valid flag
                configValidReg = true;
                configFselReg = xfix({xlUnsigned,bCoeID,0},0); % First coe set
                stateReg = SWITCHING;
                
            case SWITCHING
                % Switching to the next coefficient set
                if(configFselReg == nCoeSets-1)
                    configFselReg = xfix({xlUnsigned,bCoeID,0},0); % reset when reached max count                                       
                else
                    configFselReg = xfix({xlUnsigned,bCoeID,0},configFselReg + 1);
                end
                
            otherwise
                configValidReg = false;
                configFselReg = xfix({xlUnsigned,bCoeID,0},0);
        end
    else
        configValidReg = false;
        configFselReg = xfix({xlUnsigned,bCoeID,0},0);
    end
   
    % Assign outputs
    configValid = configValidReg;
    configFsel = configFselReg;
    
end 

I expect the output configFsel to be 1 bit (because the number of coefficients is 2, one bit is enough to represent it). I have assigned only one bit for it throughout the code,

persistent configFselReg, configFselReg = xl_state(0,{xlUnsigned,bCoeID,0}); 

bCoeID = 1;

However at the output, it is assigned with 4 bits after compilation. I have no idea why? Any help would be appreciated!

DataTypeError.PNG

Thanks,
Bhavanithya Thiraviaraja
0 Kudos
3 Replies
Moderator
Moderator
189 Views
Registered: ‎08-01-2007

回复: MCode Data Type Mismatch

What's value of bCoeID?

 

0 Kudos
Adventurer
Adventurer
163 Views
Registered: ‎06-04-2019

回复: MCode Data Type Mismatch

bCoeID = 1
Thanks,
Bhavanithya Thiraviaraja
0 Kudos
Moderator
Moderator
124 Views
Registered: ‎08-01-2007

回复: MCode Data Type Mismatch

It might be due to following syntax.

                if(configFselReg == nCoeSets-1)
                    configFselReg = xfix({xlUnsigned,bCoeID,0},0); % reset when reached max count                                       
                else
                    configFselReg = xfix({xlUnsigned,bCoeID,0},configFselReg + 1);
0 Kudos