ΣSigmaStudio Ask AI Русский Log in

If then else algorithm, how to?

SigmaDSP & SigmaStudio leonxp Nov 25, 2012 00:00 2 replies Original on forum ↗
Subscribe
leonxp Question
Nov 25, 2012 00:00

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

KJBob Reply
Nov 26, 2012 00:00

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

1dc0301f86ed90e0a7be807aa18d29ae.jpg
1dc0301f86ed90e0a7be807aa18d29ae.jpg
1dc0301f86ed90e0a7be807aa18d29ae.jpg-450x300.jpg
1dc0301f86ed90e0a7be807aa18d29ae.jpg-450x300.jpg
leonxp Reply
Nov 26, 2012 00:00

tnx Bob!