Decision based on Voltage 'Window'

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

daveb0360
Posts: 139
Joined: Mon Sep 21, 2009 10:17 am
Location: Leicester
Has thanked: 35 times
Been thanked: 12 times
Contact:

Decision based on Voltage 'Window'

Postby daveb0360 » Fri Aug 05, 2011 2:50 pm

Hi,
Can somebody help with a problem I have.
I need to measure the voltage on ADC1 and create a decision based on the voltage being outside a central window. For example. I want my code to wait for a voltage that is either below 1.5 V or above 3.5V and then trigger external port.
In other words, a voltage that is between 1.5 and 3.5, keeps the program in a wait state.

I can't seem to get this to work and it is not due to the setting of the ADC (i.e. readasbyte, readasvoltage etc) this is irrelevant.
I can get the program to respond to either a voltage below 1 or above 3 independantly but I can't seem to get the maths (if voltage <1.5>3.5 then....) I get a syntax error when simulating, telling me that > is not acceptable.

Please assist, I'm sure it's something simple I'm overlooking .......hopefully I've made this clear.

Dave

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 381 times
Been thanked: 715 times
Contact:

Re: Decision based on Voltage 'Window'

Postby JohnCrow » Fri Aug 05, 2011 3:08 pm

Hi Dave

If you are using floats , you cannot use the

if V < 3.5 type statements. There are a set of commands to do greater than, less than , equal to etc.

Have a look in the flowcode help file on floats it shows how to do it.
Sorry I'm at work so not able to access my system to give a more concise answer, but hope this helps you get stated
1 in 10 people understand binary, the other one doesn't !

daveb0360
Posts: 139
Joined: Mon Sep 21, 2009 10:17 am
Location: Leicester
Has thanked: 35 times
Been thanked: 12 times
Contact:

Re: Decision based on Voltage 'Window'

Postby daveb0360 » Fri Aug 05, 2011 3:30 pm

Hi John and thanks for the reply. I appreciate you are at work so don't get too involved in this.....would hate to see you get pulled for wasting time.

I think I misrepresented what I was trying to acheive. I gave the 1.5V / 3.5V as an example. The precise voltages are not critical. I was approximating a 0 - 5V range divided by 3 with the centre mathematical 'window' being measured and ignored by the program. The program only responding with a logical decision if a voltage was detected outside the central 'window'.
I could approximate within a byte range of 0 - 255 instead of 0 - 5V range if it makes it easier. I am trying to approximate/replicate a hardware 'window comparator' function.
i.e. I could base the logical decision on an ignore window of 85 - 170 for example. Give a signal on any measured byte value below 85 or above 170.

Is this clearer? and would this be simpler to implement and code?

Regards
dave

User avatar
Benj
Matrix Staff
Posts: 14371
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4447 times
Been thanked: 4145 times
Contact:

Re: Decision based on Voltage 'Window'

Postby Benj » Fri Aug 05, 2011 4:59 pm

Hi Dave,

If you want to detect if a value is within a range then this is one way to do it.

Component Macro: sample = ADC Read As Byte

Decision: (sample > 50) && (sample < 100)

yes: Component Macro: Print String "In Range"

no: Component Macro: Print String "Out Of Range"
These users thanked the author Benj for the post:
mauro (Thu May 10, 2012 7:28 pm)
Rating: 5.26%
 

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: Decision based on Voltage 'Window'

Postby medelec35 » Fri Aug 05, 2011 5:45 pm

Hi Dave,

I have shown this as an alternate way to Ben's.
His would be the best if only one function if out of range. E.g only portA1 is activated if out of range
You could use my version if an o/p is required ,if Voltage too high, or a different o/p is required if voltage is too low
Win Comp.jpg
Win Comp.jpg (130.75 KiB) Viewed 5179 times

Martin
Attachments
Window comparator.fcf
(7 KiB) Downloaded 253 times
These users thanked the author medelec35 for the post (total 3):
daveb0360 (Fri Aug 05, 2011 10:39 pm) • Werner (Sat Dec 03, 2011 8:30 pm) • mauro (Thu May 10, 2012 7:28 pm)
Rating: 15.79%
 
Martin

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

daveb0360
Posts: 139
Joined: Mon Sep 21, 2009 10:17 am
Location: Leicester
Has thanked: 35 times
Been thanked: 12 times
Contact:

Re: Decision based on Voltage 'Window'

Postby daveb0360 » Fri Aug 05, 2011 10:37 pm

Genius !!! Thanks Ben,
This works fine. Brings to mind though, the need to explain correct syntaxfor all these commands and functions.
Not meaning to be critical because I love the program but since it is intended for engineers that have little or no knowledge of programming languages, it follows that many would not know correct syntax and need a reference document.

Dave

daveb0360
Posts: 139
Joined: Mon Sep 21, 2009 10:17 am
Location: Leicester
Has thanked: 35 times
Been thanked: 12 times
Contact:

Re: Decision based on Voltage 'Window'

Postby daveb0360 » Fri Aug 05, 2011 10:47 pm

medelec35 wrote:Hi Dave,

I have shown this as an alternate way to Ben's.
His would be the best if only one function if out of range. E.g only portA1 is activated if out of range
You could use my version if an o/p is required ,if Voltage too high, or a different o/p is required if voltage is too low
Win Comp.jpg

Martin



Thanks Martin,
My project is in early stages and depending on how I advance this and expand functionality, I may use this also. I actually only need a single port to go high(low) if input goes outside the central window. The central point determined by a simple resistor divider from VDD. I have actually decided to print a string with the command to LCD also.

The purpose of the circuit is to take a trigger from an external source that can be a voltage (scaled by R network) or from volt free relay. I already designed and built the circuit in analogue which worked fine but since there was spare capacity in the micro, I decided it would be good to combine all functionality in a single device.

Thanks again, I am sure I will have many other questions before I am done with this.

Dave

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: Decision based on Voltage 'Window'

Postby medelec35 » Fri Aug 05, 2011 11:04 pm

No problem
One thing about my flowchart, is you can use the formula in association with Ben's method
So you know the result is 35, then ADC is measuring 3.5V since result = V ADC x 10.

Martin
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: Decision based on Voltage 'Window'

Postby JDR04 » Fri Mar 15, 2013 2:22 pm

Thanks Martin, I'll go through this later.

I have however got a strange one for you. When I opened you attachment this morning and ran the circuit all went 100% OK.

However, when I open the attachment now the two LED's are missing?? I've tried opening the attachment a few times with the same result. I also noticed with the file I saved the two LED's were also missing??? Ghost busters???