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.
0 个评论
采纳的回答
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Arduino Hardware 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!