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

JDR04
Posts: 264
Joined: Tue Mar 05, 2013 10:49 pm
Has thanked: 111 times
Been thanked: 13 times
Contact:

Adjustable Threshold Level

Postby JDR04 » Mon Jul 07, 2014 9:13 pm

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 101 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8440
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2412 times
Been thanked: 3451 times
Contact:

Re: Adjustable Threshold Level

Postby medelec35 » Mon Jul 07, 2014 11:12 pm

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
These users thanked the author medelec35 for the post:
JDR04 (Tue Jul 08, 2014 12:08 am)
Rating: 5.26%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

JDR04
Posts: 264
Joined: Tue Mar 05, 2013 10:49 pm
Has thanked: 111 times
Been thanked: 13 times
Contact:

Re: Adjustable Threshold Level

Postby JDR04 » Mon Jul 07, 2014 11:46 pm

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 93 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8440
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2412 times
Been thanked: 3451 times
Contact:

Re: Adjustable Threshold Level

Postby medelec35 » Tue Jul 08, 2014 12:14 am

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 127 times
These users thanked the author medelec35 for the post:
JDR04 (Tue Jul 08, 2014 7:39 pm)
Rating: 5.26%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

JDR04
Posts: 264
Joined: Tue Mar 05, 2013 10:49 pm
Has thanked: 111 times
Been thanked: 13 times
Contact:

Re: Adjustable Threshold Level

Postby JDR04 » Tue Jul 08, 2014 7:39 pm

Many thanks, will check it all out.

Take care.........John
These users thanked the author JDR04 for the post:
medelec35 (Thu Jul 10, 2014 8:20 am)
Rating: 5.26%