MATLAB Answers


How to monitor an analog signal real-time in Simulink?

Asked by Canberk Suat Gurel on 24 Mar 2018
Latest activity Edited by Canberk Suat Gurel on 2 Apr 2018
I am using Simulink (Embedded Coder) to program my LAUNCHXL-F28379D TI C2000 microcontroller.
I have created a model to detect the frequency of a signal and I want to use this model to detect the frequency of the encoder signal (in order to estimate the angular velocity of the motor). The model seems to be successfully identifying frequencies of different signals in the simulation environment.
Now, I want to test this model with the actual encoder signal. I have digital output GPIO pins (that can only output 0V and 3.3V.) Is there a way to monitor this signal real-time?
Note: I am using MATLAB 2017b and I have an oscilloscope.


Sign in to comment.

2 Answers

Answer by Mark McBroom on 24 Mar 2018

The F28379D device has input capture pins that can be used to measure the frequency of an input signal.


Show 1 older comment
I am assuming what you want to do is run code from your Simulink model on the F28379D device, but monintor signals in scope/display blocks in Simulink? You can accomplish this with External Mode. In External Mode, Simulink will generate code from your Simulink model and download the code to the device. If you have scopes or displays in your Simulink model, then when you hit the run button, Simulink will read the values for those signals from your F28379D device and display them on the scope or display in the Simulink model. The F28379D device will be running in real-time. The data displayed in the scopes/displays in the Simulink diagram will be psuedo real-time.
Thank you for your answer. This sounds like exactly what I need. I will use the dedicated pins for determining the frequency and I will run it in the External Mode to monitor some of the other signals, e.g. speaker, microphone. I will try this tomorrow and report back.

Mark, I am having a small problem with the sampling of the analog signal. The signal that is displayed on the scope is shown below:

It was supposed to be a sine wave and as it can only display it using Markers (not Line) it doesn't appear to be a sine wave. Is there a way to sample more frequently or are we limited with the baud rate of the serial communication?

Sign in to comment.

Answer by Mark McBroom on 1 Apr 2018

You are limited by the speed of the communication channel. What is the frequency of the signal you are measuring? Why are you using an analog channel? If you only need to measure frequency, you should use an input capture pin. This is a better use of CPU resources than trying to sample a high frequency signal using an A/D.

  1 Comment

Okay, let me give some insight about what I am doing. I am working on an acoustic sensor that is mounted on a differential drive mobile robot. The sensor consists of a speaker and a microphone, the speaker emits a 25kHz sine wave and when the microphone receives the echo, it converts acoustical energy (sound waves) into electrical energy (the audio signal). I can monitor this signal by my oscilloscope. The same signal is fed to the ADC, which samples the signal at 250kHz. Then, the max amplitude is stored for further processing. Although, I can monitor the microphone signal by my oscillosope, I cannot monitor what ADC reads and hence I am not sure that it works as I am expecting it to be. This is why I need to run the Simulation in External mode and attach a Scope to monitor what ADC is outputting, in real-time. However, as you can see from the Figure, the SCI is not fast enough to monitor the ADC. Is altering the baud rate going to allow me have a line plot (instead of markers)?

Sign in to comment.