How can write a pulse generator block with coding?
12 次查看(过去 30 天)
显示 更早的评论
Hi,
I have to write a pulse generator block via coding in a "Matlab embeded function" I want to control the phase shift of the generated square wave signal continuously. It is not possible with the pulse generator block of Matlab simulatiom due to this block does not have external phase shift input signal. Therefore, I thought I could generate square wave via coding in a Matlab embeded function block. In the other word I wanted to create a pulse generator block which is able to control the phase externally. At the end I wanted to compile the simulation on a DSP board (F28335).
I used these codes to generate square wave signal in Matlab embeded function:
function y = fcn(t)
%#eml
h = sign(sin(125600*t));
y= (h+1)/2
Note that I connected the function block to a digital clock to provide t. I connected the digital clock to the pulse generator block as well. And also connected both output signals to "Digital Output" block which is considered by Texas Instrument Co. in Matlab.
Using two methods, (Pulse generator block and the embeded Matlab function block) I could generate two identical square waves in the simulation in terms of amplitude and frequency. But when I compile the simulation and transfer them to the DSP, only the square wave which has been generated by Pulse generator block was appeared on Oscilloscope. It means that the above codes do not do the same job the pulse generator block does.
Please let me know where the problem is that the embeded function operates exactly the same as pulse generator block in simulation but on hardware they have different behaviors? Whether the above codes are not complete or any thing else? If the first one is true, what codes I do have to add to create a pulse generator block manually,
Regards
Foad
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 C2000 Microcontroller Blockset 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!