If then else algorithm, how to?
Hi everybody, I'd need to implement a simple logic comparison algorithm like this:
- Input source Vi is a sine with frequecy at 440Hz and Vi_Max = 1V and Vi_min = -1V
- Output Vo must be ever bounded between Vt_Max = 5V and Vt_min =-5V.
if(Vi_Max<=Vt_Max & Vi_min>=Vt_min) // is the same if I use |Vi|<Vt_Max
Vo = Vi;
else
Vo = Vi - (Vi_Max - Vt_Max);
How can I use a '<' or '>' comparator in a block program?
Thanks for your attention,
Regards.
leonxp
Hi leonxp,
The attached diagram uses a AB-CD comparator to implement your conditions. Since the sine wave Vi goes from -1 to +1, it's always less than Vt(max)=5.0. Thus, presently the comparator just lets Vi through. I set the sine wave frequency 100x lower (4.4 Hz) so you can see it on the Real Time Display. If you change Vt(max) for example to 0.5, then the comparator will cut in as expected
If you also need to control the output for negative excursions of Vi, you can add a second comparator.
Hope this helps,
bob
tnx Bob!
Please log in to reply.

