Re: Schmitt trigger in software
tom00 wrote:
> Hello all!
>
> I have to implement a Schmitt trigger in software on a DSP. I was thinking
> a while about a good implantation, but I just came to the simple solution
> with has nested if conditions (See Pseudo code below). Does anyone has a
> faster code??
>
>
> -Thomas
>
>
>
> for n = 1:length(x)
> if flag
> if x(n) > th
> do something
> flag = 0;
> end
> else
> if x(n) < -th
> do soming else
> flag = 1;
> end
> end
> end
^^^^^^^^^^^^^^^^^^^^^^^^^
Fie, stupident solution.
Here we go:
const s16 fubar[] = { nonsense, -nonsense };
const s16 void (*do_something[])() = { something_ , else_ };
s16 *x = blablabla;
s16 th = 0;
while(length--)
{
th = fubar[u16 state = ((u16)(*x++ +th)) >> 15];
do_something[state];
}
VLV
|