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
Decision based on Voltage 'Window'
Moderator: Benj
- JohnCrow
- Valued Contributor
- Posts: 1367
- Joined: Wed Sep 19, 2007 1:21 pm
- Location: Lincolnshire
- Has thanked: 364 times
- Been thanked: 716 times
- Contact:
Re: Decision based on Voltage 'Window'
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
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 !
-
- 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'
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
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
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Decision based on Voltage 'Window'
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"
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"
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Decision based on Voltage 'Window'
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 Martin
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 Martin
- Attachments
-
- Window comparator.fcf
- (7 KiB) Downloaded 459 times
Martin
-
- 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'
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
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
-
- 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'
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 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
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Decision based on Voltage 'Window'
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
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
-
- Posts: 271
- Joined: Tue Mar 05, 2013 10:49 pm
- Has thanked: 111 times
- Been thanked: 13 times
- Contact:
Re: Decision based on Voltage 'Window'
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???
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???