0

I intend to generate a square wave which is applied on a DSP.

I have written these codes and put them in an embeded Matlab function.

function y = fcn(u)
    %#eml
t=0:0.001:1

h = sign(sin(125600*t+u));

y= (h+1)/2

where, u is a constant value of 0.582 which is used for shifting the square wave.

The problem is at the output in the simulation, instead of getting a square wave, I see only two straight lines of y=o and y=1.

Please let me know where is the problem that I can not get the square wave?

Note that the frequency of square wave must be 20 kHz. Therefore, I adjust the sampling time as 1e-7 s. And also its amplitude is between 0 and 1 In addition, due to this signal must be transferred to a DSP board, in the "solver option" I chose the type: " Fixed-step" and for the Solver: "Discrete (no continues state)".

Thanks a lot.

am304
  • 13,758
  • 2
  • 22
  • 40

2 Answers2

1

This is wrong on many levels.

First of all, you never define the time vector inside a MATLAB Function, that's what the Simulink engine does. Pass time as an input to your MATLAB Function block and use a Clock block to generate the time input.

Second, the above is fine for simulation, but it sounds like you are generating C code from the Simulink model to run it (in real-time) on your DSP. This is not my area of expertise, but from memory, I think you need to enable "absolute time" or something similar for the above to work with code generation. However, I think this is target-dependent and so I'm not sure whether this will work on your DSP.

am304
  • 13,758
  • 2
  • 22
  • 40
0

In you function type plot(t,y) at the end. You are generating a 20khz square wave (assuming you are sampling at 1e-7). Essentially your generating it is working.

Now, what is the DSP board you are using/any information that is relevant to your problem?

I don't know what you are referring to when you say "Solver" either.

Is the "simulation" an oscilloscope or a program? Either way perhaps it is not triggering correctly? Is there an edge trigger option?

da_steve101
  • 283
  • 4
  • 16
  • The DSP board is F28335 eZdsp. I can convert the Matlab file on this board using compiler. The Solver is in the Matlab Configuration Parameters, where we can adjust the sampling time and the other parts of simulation running. As I mentioned earlier I am using Matlab simulink. I employed an embeded Matlab function in the simulation to write my codes. I can see the output of this block by a scope in Matlab. But the problem is instead of a square wave I see only two straight line, y=0 and y=1. Also when I converte the simulation on DSP, I can not see any output signal on oscilloscope hardware. – user3217738 Jan 21 '14 at 05:58
  • Hmmm ... i don't have enough information to solve this i think. Do you have access to the simulation source? Is the "solver" some commercial program or a classroom tool - either case could be buggy? Have you checked the drivers/that you can communicate with it? – da_steve101 Jan 21 '14 at 06:01