Borrar filtros
Borrar filtros

Infinity appears at Constant block in Simulink

2 visualizaciones (últimos 30 días)
Matthew Tieu
Matthew Tieu el 12 de Nov. de 2022
Comentada: Matthew Tieu el 12 de Nov. de 2022
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.

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Arduino Hardware en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by