⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mbc_adcinput.m

📁 simulink real-time workshop for dragon12 development board from
💻 M
字号:
function [channelsStr, firstChannel, numChannels] = mbc_adcinput(bank, channels, use10bits, normalize, sampletime)

% turn 'channels' parameter into 'firstChannel' and 'numberChannels'
channels2 = strrep(channels, '-', ':');
if(~isempty(findstr(channels2, ':')))
	channels3 = eval(channels2);
	firstChannel = channels3(1);
	if(firstChannel > 7)
		disp('ADC: Invalid channel number (0 - 7)')
	end
	numChannels = length(channels3);
	if(firstChannel + numChannels - 1 > 7)
		numChannels = 8 - firstChannel;
		disp(['ADC: Limiting number of channels to ' num2str(numChannels) '.'])
	end
else
	channels2 = strrep(channels, ' ', ',');
    while(~isempty(findstr(channels2, ',,')))
        channels2 = strrep(channels2, ',,', ',');
    end
	if(channels2(1) == ',')
		channels2(1) = [];
	end
	if(channels2(end) == ',')
		channels2(end) = [];
	end
	channels3 = eval(['[' channels2 ']']);
	channels3 = sort(channels3);
	numChannels = channels3(end) - channels3(1) + 1;
	firstChannel = channels3(1);
	if(numChannels > length(channels3))
		disp(['ADC: Increased the requested number of channels (' num2str(length(channels3)) ...
				') to ' num2str(numChannels) ' consecutive channels.'])
	end
	if(firstChannel + numChannels - 1 > 7)
		numChannels = 8 - firstChannel;
		disp(['ADC: Limiting number of channels to ' num2str(numChannels) '.'])
	end
end

if(numChannels > 1)
	channelsStr = ['Channels ' num2str(firstChannel) ' - ' num2str(firstChannel + numChannels - 1)];
else
	channelsStr = ['Channel ' num2str(firstChannel)];
end


% adjust number of block output ports...

% de-activate link to library...
if(~strcmp(get_param(gcb, 'LinkStatus'), 'inactive'))
	set_param(gcb, 'LinkStatus', 'inactive')
end

% Get current number outputs
num_now = length (find_system (gcb, 'LookUnderMasks', 'on', 'BlockType', 'Outport'));
%disp(['num_now = ' num2str(num_now)]);
%disp(['numPins = ' num2str(numPins)]);
if numChannels < num_now
    for k = numChannels+1:num_now
        delete_line (gcb, ['Demux/', num2str(k)], ['Out' num2str(k), '/1'])
        delete_block ([gcb, '/Out', num2str(k)])
    end
    set_param ([gcb, '/Demux'], 'Outputs', num2str(numChannels))
else
    set_param ([gcb, '/Demux'], 'Outputs', num2str(numChannels))
    for i = num_now+1:numChannels
        add_block ('built-in/Outport', [gcb, '/Out', num2str(i)])
        set_param ([gcb, '/Out', num2str(i)], 'Position', get_param ([gcb, '/Out', num2str(i-1)], 'Position') + [0 45 0 45])
        set_param ([gcb, '/Out', num2str(i)], 'FontSize', '12')
        add_line (gcb, ['Demux/', num2str(i)], ['Out', num2str(i), '/1'])
    end
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -