Flow sensor FOR-NEXT?

Jacobsen

New Member
I have acquired a Flow sensor, that reads "READADC 3,w3"

Grundfos Direct Sensors Web-link:

<A href='http://net.grundfos.com/doc/webnet/directsensors/images/pressurelow.pdf ' Target=_Blank>External Web Link</a>

And these values from the flow sensor I would like to output on my LCD-display

The lines below (like these &quot;if w3 &lt;= 26 then V050&quot;) I have to type 256 times,
There must be an easier way to do this? If you have a suggestion I would really like

a code example.

The codes for calculation of the values are made in a spread-sheet:
From steps to Flow-speed
= (A17*( 5/256)-0,5)*10/1,5

I thought of something like this myself, but not quite sure how to do it?

<code><pre><font size=2>
FOR-NEXT

For w3=1 to 256 STEP 1

(w3*(0.0195)-0,5)*10/1,5

Next w3


Code:
DisplayLine4:	
			READADC 3,w3
			byte = $D4; Start Line 4
			GOSUB SendCmdByte
			
			EEPROM 56,(&quot;Flow:    &quot;) ;56..64
			FOR get = 56 TO 64
			READ get,byte
			GOSUB SendDataByte
			NEXT
		
			if w3 &lt;= 26  then V050
			if w3 &lt;= 27  then V052
			if w3 &lt;= 28  then V054
			if w3 &lt;= 29  then V056
			if w3 &lt;= 30  then V058
			if w3 &lt;= 31  then V060
			if w3 &lt;= 32  then V062
			if w3 &lt;= 33  then V064
			if w3 &lt;= 34  then V066
			if w3 &lt;= 35  then V068

V050:
let w3 = 000
goto Disp1000Linie4:

V052:
let w3 = 001
goto Disp1000Linie4:

V054:
let w3 = 003
goto Disp1000Linie4:

V056:
let w3 = 004
goto Disp1000Linie4:

V058:
let w3 = 005
goto Disp1000Linie4:

V060:
let w3 = 007
goto Disp1000Linie4:

V062:
let w3 = 008
goto Disp1000Linie4:

V064:
let w3 = 009
goto Disp1000Linie4:

V066:
let w3 = 011
goto Disp1000Linie4:

V068:
let w3 = 012
goto Disp1000Linie4:

Disp1000Linie4:
		SERTXD(&quot;Flow: &quot;,#w3,&quot; l/time&quot;,&quot;  &quot;,CR,LF)

		byte = w3 / 10000 | &quot;0&quot;
		IF w3 &gt;= 10000 THEN Disp1000Digit4
		byte = &quot; &quot;
		Disp1000Digit4: 
		GOSUB SendDataByte
Disp100Linie4:
		byte = w3 / 1000 // 10 | &quot;0&quot;
		IF w3 &gt;= 1000 THEN Disp100Digit4
		byte = &quot; &quot;
		Disp100Digit4: 
		GOSUB SendDataByte
Disp10Linie4:
		byte = w3 / 100 // 10 | &quot;0&quot;
		IF w3 &gt;= 100 THEN Disp10Digit4
		byte = &quot; &quot;
		Disp10Digit4:
		GOSUB SendDataByte

DispUnits4:
		byte = w3 / 10 // 10 | &quot;0&quot;
		GOSUB SendDataByte
		DispDecimalPoint4:
		byte = &quot;.&quot;
		GOSUB SendDataByte
DispDecimal4:
		byte = w3 // 10 | &quot;0&quot;
		GOSUB SendDataByte

			byte = &quot; &quot;
			GOSUB SendDataByte
			byte = &quot;l&quot;
			GOSUB SendDataByte
			byte = &quot;/&quot;
			GOSUB SendDataByte 
			byte = &quot;m&quot;
			GOSUB SendDataByte
			'byte = &quot;i&quot;
			'GOSUB SendDataByte
			'byte = &quot;n&quot;
			'GOSUB SendDataByte

		goto DisplayLine1
 

<b>   
Bestregards
Monie
   </b>   


Edited by - Monie on 2/8/2006 2:11:44 PM    &lt;/font&gt;&lt;/pre&gt;&lt;/code&gt;

Edited by - Monie on 2/8/2006 2:14:20 PM    </font></pre></code>
 

Dippy

Moderator
Oh dear.
I hope Hippys got a few minutes to spare. He'll want to get his teeth into this!
I think it all starts to go wrong when you typed a decimal point and loads of brackets.
And can't you work out a simple algorithm rather than all those IF..Thens?
With all the diplomacy I can muster, can I suggest you start in the 'variable types' section of the PICAXE manual? (Integers etc.)Then move onto syntax etc.
If I had the time....
 

hippy

Technical Support
Staff member
<i>I hope Hippys got a few minutes to spare </i>

Incredibly busy at the moment which is why no one's heard from me over the past few days, and just time for short comments ...

X * 0.19 is the same as X * 19 with the decimal point printed with two digits following it, if that's any help. Doing non-integer maths is really a case of multiplying up so it become an integer ( watching out for overflow ) and then adjusting down later, either by dividing or by printing decimal points in the right place.

Also LOOKUP/LOOKDOWN might prove useful, if it's a 256 byte lookup, it could be put in EEPROM and READ used.

Edited by - hippy on 2/9/2006 2:41:23 AM
 

Jacobsen

New Member
<b>Hello hippy </b>

I do hope yoy can assist with my problem
Im have trying many time.
Hippy, I would be happy to if you send a example. ;-)

<code><pre><font size=2>
DisplayLine4:
READADC 3,w3
byte = $D4; Start Line 4
GOSUB SendCmdByte

EEPROM 56,(&quot;Flow: &quot;) ;56..64
FOR get = 56 TO 64
READ get,byte
GOSUB SendDataByte
NEXT
for w4=0 to 255 STEP 1
<b>'w3*(0.0195)-0,5)*10/1,5 The codes for calculation of the values are made in a spread-sheet: </b>
let w3 = 1
let w3 = w3 * 195
let w3 = w3 / 100
let w3 = w3 / 100
let w3 = w3 - 0.5 '<b>Subtract ???? </b>
let w3 = w3 * 10
let w3 = w3 * 15 / 10

lookup w4,(w3),w6

if w4 &lt; 256 then Disp1000Linie4

next w4

Disp1000Linie4:
byte = w6 / 10000 | &quot;0&quot;
IF w6 &gt;= 10000 THEN Disp1000Digit4
byte = &quot; &quot;
Disp1000Digit4:
GOSUB SendDataByte
Disp100Linie4:
byte = w6 / 1000 // 10 | &quot;0&quot;
IF w3 &gt;= 1000 THEN Disp100Digit4
byte = &quot; &quot;
Disp100Digit4:
GOSUB SendDataByte
Disp10Linie4:
byte = w6 / 100 // 10 | &quot;0&quot;
IF w6 &gt;= 100 THEN Disp10Digit4
byte = &quot; &quot;
Disp10Digit4:
GOSUB SendDataByte

DispUnits4:
byte = w6 / 10 // 10 | &quot;0&quot;
GOSUB SendDataByte
DispDecimalPoint4:
byte = &quot;.&quot;
GOSUB SendDataByte
DispDecimal4:
byte = w6 // 10 | &quot;0&quot;
GOSUB SendDataByte

byte = &quot; &quot;
GOSUB SendDataByte
byte = &quot;l&quot;
GOSUB SendDataByte
byte = &quot;/&quot;
GOSUB SendDataByte
byte = &quot;m&quot;
GOSUB SendDataByte
byte = &quot;i&quot;
GOSUB SendDataByte
byte = &quot;n&quot;
GOSUB SendDataByte

goto DisplayLine4
</font></pre></code>

PS. I would be very pleased if you would help me to solve the problem.
Which i se as a great obstacle on my way forward.

<b>
Bestregards
Monie
</b>
 

Dippy

Moderator
I think Hippy would need to know what actual signal is coming from the sensor before he can suggest code. Is the flow sensor a VOLTAGE proportional to &quot;flow rate&quot; output (as you have used READADC)?
Bit confusing as in your first post you say &quot;From steps to flow speed&quot; implying the sensor is giving pulses proportional to flow speed.
So, from the spreadsheet, is &quot;A17&quot; an analogue voltage or pulses/time unit?

As I hinted and Hippy said you'll have to do your 'decimal' calcs in integers (with his word of caution re: overflow).
Then 'convert'them at the end.

And note some unnecessary commands in your code.

In your calculation you can't have 0.5 so assuming initial val w3&lt;330 you could try:
(I have merely suggested a symbol 'Flow' as a word only for clarity.)
Flow=w3*195
Flow=Flow-5000 ' all scaled by 10000
flow=flow/1500 ' forget the *10, adjust scale to 1000

This works but resolution won't be very good. But then I don't how big your likely READADC value of &quot;w3&quot; is likely to be. You could modify the factors above if you didn't mind a little offset creeping in - and adjust your LCD output to suit.

Anyway, food for thought until the big guy wades in.
Your LCD output needs modding but I'll leave you in Hippy's capable hands. I'm sure he's looking forward to it!!
Is this your school project? You should be doing it yourself!

 

BarryP

Senior Member
Hi
Seems Hippy is a bit Busy.
To Add to some of Dippy's Comments...

Although I Haven't looked into exactly what you are doing there are a few routines you might look at.
Using Peek/Poke , saving variables etc

This May Give you some extra Ideas

Symbol mGenVarsBase = $D0
Symbol mAdcReffCount = mGenVarsBase
Symbol mBCD10000 = mGenVarsBase + 1
Symbol mBCD1000 = mGenVarsBase + 2
Symbol mBCD100 = mGenVarsBase + 3
Symbol mBCD10 = mGenVarsBase + 4
Symbol mBCD1 = mGenVarsBase + 5

Symbol WordVar3 = W3
Symbol X = B2
Symbol Y = B3
Symbol LCD_Data = B4

;*************
WordVar3BCD:
;*************
X = WordVar3/10000
Poke mBCD10000,X
X = WordVar3//10000/1000
Poke mBCD1000,X
WordVar3 = WordVar3//10000//1000
X = WordVar3/100
Poke mBCD100,X
X = WordVar3//100/10
Poke mBCD10,X
X = WordVar3//100//10
Poke mBCD1,X
Return
;****************
DisplayA_String:
;****************
X = 0
DisplayA_String_1:
Lookup X,(&quot;Any Old String&quot;,0),LCD_Data
if LCD_Data = 0 then DisplayA_String_Leave
gosub LCDsendchar
X = X + 1
goto DisplayA_String_1
DisplayA_String_Leave:
Return

;***********
BCD2Serial:
;***********
For X = mBCD10000 to mBCD1
Peek X,Y
Y = Y + &quot;0&quot;
SerTxd (Y)
Next
Sertxd (13,10)
Return


Hope It Helps

... Off to bed



Edited by - barryp on 2/9/2006 9:39:11 AM
 

cpedw

Senior Member
Now that BarryP has shown how to display the digits of the result, I feel able to offer a line or two to convert the READADC value into a result which you call Flow (though I am intrigued at the linear connection between a pressure measurement and flow - it's usually a squared relation).
Also, READADC returns a byte so it's not necessary to use a word variable for it, but it won't prevent it working.
We need to prevent the calculation overflowing during the arithmetic. To do that, we must mak sure the calculation never reaches 65536 or 256 squared.
The READADC can return values between 25 and 179 if the picaxe is using 5v supply since its output varies between 0.5V and 3.5V. First step in keeing the numbers low is to subtract 25 from the measurementso it varies between 0 and 154 (179-25). Then multiply by 5 so the range is 0 to 770 then multiply by 10, 0 to 7700. We can't divide by a non-integer so to divide by 1.5, we multiply by 2 then divide by 3. Finally divide by 256. To keep it simple, these calculations can be bundeled together to a large extent so:
subtract 25
Multiply by 100 (5.10.2)
Divide by 768 (3.256)
SO we can write

WordVar3 = WordVar3 - 25 * 100 / 768

then use BarryP's routines to display the result.
Picaxe basic doesn't have brackets; calculations are strictly left to right so the above would be written in algebra:
(WordVar3-25)*100/768

Hope that helps,
Derek.
 
Top