Infinity appears at Constant block in Simulink

2 views (last 30 days)
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.

Accepted Answer

Paul
Paul on 12 Nov 2022
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 Comment
Matthew Tieu
Matthew Tieu on 12 Nov 2022
Ok thanks for the clarification. I thought that was the output value coming out of the block.

Sign in to comment.

More Answers (0)

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by