Infinity appears at Constant block in Simulink

6 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Arduino Hardware 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by