0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

二部探索アルゴリズムでADしてDAするSimulinkシミュレーション 

Posted at

image.png

% 電源電圧ありの2部探索アルゴリズムのAD変換器
function [Vout, D] = binary_search_adc_with_vdd(Vin, VDD, bit_generation_clock)
    % 入力:
    %   Vin  - 入力電圧
    %   VDD  - 電源電圧
    %   bit_generation_clock    - ビット生成用のクロック (0 または 1)
    % 出力:
    %   Vout - 残差電圧
    %   D    - ビット出力 (0 または 1)
    
    % 基準電圧 VREF = VDD / 2
    VREF = VDD / 2;
    
    % クロックが0のとき出力はすべて0
    if bit_generation_clock == 0
        Vout = 0;
        D = 0;
        return; % クロックが0の場合、出力は更新されず終了
    end
    
    % クロックが1のとき、入力電圧に応じて計算
    if Vin > VREF
        Vout = 2 * (Vin - VREF); % VinがVREFより大きい場合
        D = 1;                   % ビット出力は1
    else
        Vout = 2 * Vin;          % VinがVREFより小さい場合
        D = 0;                   % ビット出力は0
    end
end

% クロックが0から1になると値を更新する関数
function y = fcn(u, VDD, bit_generation_clock)
    % fcn - クロックが0から1になるときに出力を更新する
    % 入力:
    %   u   - 入力電圧
    %   VDD - 電源電圧
    %   bit_generation_clock   - ビット生成用クロック信号 (0 または 1)
    % 出力:
    %   y   - 出力電圧 (Voutとビット出力)

    % 初期出力は全て0に設定
    persistent Vout D
    if isempty(Vout)
        Vout = 0;
        D = 0;
    end
    
    % クロックが0から1に変わったときのみ値を更新
    if bit_generation_clock == 1
        [Vout, D] = binary_search_adc_with_vdd(u, VDD, bit_generation_clock);
    end
    
    % 結果を出力
    y = [Vout, D];
end

function DA_output = DAC_output(VIN, Din, clk)
    % 初期化
    persistent DA_value;
    if isempty(DA_value)
        DA_value = 0;  % 初期値はすべて0
    end
    
    % ビット生成クロックが0の時はすべて0を出力
    if clk == 0
        DA_output = 0;
    else
        % ビット生成クロックが1の時は
        if Din == 1
            DA_output = VIN;  % D1が1の時にVINを出力
        else
            DA_output = -0;  % D1が0の時に 0 を出力
        end
    end
    
    % 値が変更されたらDA値を更新する
    DA_value = DA_output;
end


image.png

image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?