Embedded matlab function for trigger generation

4 visualizaciones (últimos 30 días)
Owen
Owen el 10 de Oct. de 2012
Hi,
I want to write an Embedded Matlab function with 2 inputs and 1 output.
Input1: an integer Input2: a trigger Output1: a triggered rectangular impulse, the number of its waveforms is determined by input1.
I need this to generate some trigger signals with a determined number.
For example, if input1 = 10 then the output shall generate 10 triggers. These 10 triggers will be used to trigger the Queue block so that I can control how many elements can be accepted by the Queue block.
The code is following:
function y = fcn(u1, u2)
y = 0;
if u2 == 1
for i = 1:u1
if y == 0
y = 1;
else
y = 0;
end;
end;
end;
But it outputs only 0. Must I insert some delays?
Thanks Senmeis

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 10 de Oct. de 2012
Editada: Azzi Abdelmalek el 10 de Oct. de 2012
the loop in your matlab function will only generate the last value of y.
try this
with matlab function
function [y,compt] = fcn(yp,u1,u2,comptp)
%#codegen
compt=(comptp+1)*u2
if yp==0 & compt<=u1
y=1
else
y=0
end

Más respuestas (1)

Owen
Owen el 11 de Oct. de 2012
Thank you.
It works but now I want to trigger the generation with a rising edge, so the code
compt=(comptp+1)*u2
shall be changed.
Is there standard function for detection of rising edge?
Thanks Senmeis
  1 comentario
Azzi Abdelmalek
Azzi Abdelmalek el 11 de Oct. de 2012
I suggest that you accept the answer if it answers your first question, then repost another question

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB Coder en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by