Adjustable Threshold Level

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
JDR04
Posts: 264
Joined: Tue Mar 05, 2013 10:49 pm
Contact:

Adjustable Threshold Level

Post 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
Attachments
Auto Light.fcf
(12.5 KiB) Downloaded 127 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8894
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Contact:

Re: Adjustable Threshold Level

Post 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
Martin

JDR04
Posts: 264
Joined: Tue Mar 05, 2013 10:49 pm
Contact:

Re: Adjustable Threshold Level

Post 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
Attachments
Auto Light.fcf
(9 KiB) Downloaded 115 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8894
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Contact:

Re: Adjustable Threshold Level

Post 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
Attachments
Auto Light 1.1.fcf
(9.5 KiB) Downloaded 149 times
Martin

JDR04
Posts: 264
Joined: Tue Mar 05, 2013 10:49 pm
Contact:

Re: Adjustable Threshold Level

Post by JDR04 »

Many thanks, will check it all out.

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

Post Reply