I performed a serial communication between dsPIC33F and Simulink. When I send a constant value through serial connection to microcontroller and takes it back to Simulink, the signal comes like a train of pulses with amplitude equals to the value of the one I chose to send. I was thinking of a workaround to put a Digital to Analog converter before I send the value to serial. But I did not find any block in Simulink library that can perform this, only Analog - Digital conversion, that, I guess, will not work. I'm sending the output of signal that I received from serial connection. If anyone has a workaround for me I would appreciate.

 Accepted Answer

Walter Roberson
Walter Roberson on 25 Oct 2013
Analog signals cannot be sent to serial ports.
Serial ports do not send constant values: the protocol is an asynch protocol with a "start bit" and a "stop bit" (one of which breaks the other portions of the protocol), and between 7 and 10 data bits (up to 12 data bits in some variations.)

4 Comments

Danilo NASCIMENTO
Danilo NASCIMENTO on 25 Oct 2013
Edited: Danilo NASCIMENTO on 25 Oct 2013
So what you suppose me to do? I am trying to set a hardware in the loop system,with a buck-converter and a dspic33f to perform the control of this converter. So the voltage of the load should be sent to the serial port and then the microcontroller makes a control of this voltage by a reference voltage and send to serial port the PWM pulses calculated by this control to the IGBT of this buck converter. The logic is very simple, but I don't know whether it can be done this way, since the load voltage will be a DC signal.
PWM cannot be (usefully) sent to a serial port. Only a representation of the pulses an be sent, with the representation interpreted by receiving equipment.
My recollection is that the dspic33f has an analog output line or two. The dspic33f will need to use digital data representation to decide how it wants to do the control, and then it will have to use its built-in D/A convertor to send the actual signal. If it wants to tell Simulink about how it controlled the convertor, then it will need to do the telling in digital form. For example it might send the bits 01101001 to symbolize on for 0110 (decimal 6) units followed by off for 1001 (decimal 9) units, where the unit has been agreed between the two to be (say) 16.66667 nanonseconds.
So the PWM signal will be sent to AN0, for example, but how do I send this to Simulink Model? Wouldn't it be through serial connection?
Walter Roberson
Walter Roberson on 26 Oct 2013
Edited: Walter Roberson on 26 Oct 2013
Are you asking how to return back to Simulink a simulation of you having sent the signal to AN0 ? If so then that is not something I have ever looked at.
I could imagine doing it through serial transmission, by mapping the state at a fixed time step (my "unit" above) to a bit, and transmitting groups of 8 bits, with a serial receive block converting the bits into some form appropriate for the model.
Is the idea to have Simulink plot the pulse-train? If so then that can be done by having the serial receive block pass through a logical demux block (that might be implemented as an arithmetic block or two), and then on to a scope. All done in software with digital signals. You cannot transmit an analog signal directly back into Simulink over a serial port.
Another approach would be to connect the 33f AN0 to an A/D receive block on the Simulink side (i.e., have A/D hardware there), and then connect the A/D receive block to a scope.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!