From: tom00 on 13 Nov 2009 07:18 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 From: Christen Fihl on 13 Nov 2009 07:26 Table lookup like State = Array [0..1] [0..15] of 0..1 State = '0000000000011111' State = '0000011111111111' Y := State[Y] [X] X limited between 0..15, else bigger table Christen Fihl From: Vladimir Vassilevsky on 13 Nov 2009 13:29 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