Page 1 of 1

Adjustable Threshold Level

Posted: Mon Jul 07, 2014 9:13 pm
by JDR04
Hello folks, attached is my flow chart of a automatic light switch. The current knob represents the light level detected by a LDR. Once the set threshold is reached, the led turn on.

Could somebody show me please how to adjust the threshold level before the LED turns on.

Thanks very much everyone............John

Re: Adjustable Threshold Level

Posted: Mon Jul 07, 2014 11:12 pm
by medelec35
Hi John,
You have got:

Code: Select all

if lightlevel < 150 then LED = On
So what about using another ADC and setting it to ReadAsByte.
The ADC read variable you can name Threshold for example.
Then change your flowchart to:

Code: Select all

if lightlevel < Threshold then LED = On
You can also add hysteresis
e.g

Code: Select all

if lightlevel > Threshold+5  then LED = Off
Martin

Re: Adjustable Threshold Level

Posted: Mon Jul 07, 2014 11:46 pm
by JDR04
Hello Martin, I got close to it (attached)

Would you be kind enough to explain to me what Readbyte Uint etc means.

How do I actually add the hysterisis, do I need to include another calculation symbol or can it be included in one of the calculation symbols I already have??

Many thanks again......John

Re: Adjustable Threshold Level

Posted: Tue Jul 08, 2014 12:14 am
by medelec35
Hi john.
Its just the resolution or sensitivity.
E.g if you ReadAsByte then the full range from 0V to 5V will be 0 to 255 (256 steps).
Resolution (minimum voltage change to cause change of 1) = 5/256 = 19.5mV
So the type of variable should be byte to save ROM space. You can use UInt or Int but maimum will be 255.

ReadAsInt then the full range from 0V to 5V will be 0 to 1023 (1024 steps)
Resolution = 5/1024 = 4.88mv

The Hysteresis is just a set difference between of and on.
if on = 100 and off = 99 then there is no hysteresis.
So what I have done is modified flowchart so on = threshold +5
Off must be less or equal to threshold.
There for there has to be a change of 5 or greater between on and off = hysteresis.
So see the rage of different variable types when you go to add variable you will get to see all the ranges.

Martin

Re: Adjustable Threshold Level

Posted: Tue Jul 08, 2014 7:39 pm
by JDR04
Many thanks, will check it all out.

Take care.........John