フィルターのクリア

Infinity appears at Constant block in Simulink

6 ビュー (過去 30 日間)
Matthew Tieu
Matthew Tieu 2022 年 11 月 12 日
コメント済み: Matthew Tieu 2022 年 11 月 12 日
Hi,
I am making a Simulink program to measure the analog output of a circuit using an Arduino Uno. Since it is not possible to change the PWM frequency using the provided MATLAB blocks, I have included an S-function builder block to include Arduino code. As seen in the screenshot below, when I run the program (either in external or connected I/O mode), the value at the constant block (duty cycle) is infinity. This gives an incorrect graph at the scope.
I am not sure what I have done wrong since the same code works properly in the Arduino IDE. My includes are:
#ifndef MATLAB_MEX_FILE
#include <math.h>
#include <Arduino.h>
#endif
The start wrapper code is:
#ifndef MATLAB_MEX_FILE
pinMode(6,OUTPUT); // Pin D6 generates the PWM wave
TCCR0B = bit(CS01); // Set PWM frequency as 7812.5 Hz
pinMode(16,INPUT); // Pin A2 measures the output
#endif
The output wrapper code in the S function builder block is:
#ifndef MATLAB_MEX_FILE
int fraction = round(duty[0]*2.55);
analogWrite(6,fraction); // Change PWM duty cycle based on input
a2[0] = analogRead(16); // Output is the value read from pin A2
#endif
I have set the number of discrete states to 1. For extra info, this is not for homework and the same problem occurs in my other Simulink programs that require input(s) to an S-function Builder block. I will appreciate any explanation for the issue that I am experiencing currently. Thanks in advance.

採用された回答

Paul
Paul 2022 年 11 月 12 日
That “inf” is the sample time of the constant block. As is the “D1” on the other blocks. Check the Simulink doc on sample times for more info.
  1 件のコメント
Matthew Tieu
Matthew Tieu 2022 年 11 月 12 日
Ok thanks for the clarification. I thought that was the output value coming out of the block.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeArduino Hardware についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by