Waterflow metering

Puuhaaja

Senior Member
Hi again! I'm using waterflow meter like: http://www.ebay.com/itm/261152910400?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649
I have made a code for that and I can measure water consumption. When testing 1,5 l amount of water the lcd shows exatly 1.5l.
Problem is that when passing water fast through watermeter Picaxe cannot register hall sensor's click enough accurately. So amount of 1.5l consumpted water can be in lcd 0,7l. That's not good.
I have tested that hall sensor and it give voltage values 0,02V(because of leakage current?) and 2,68V. Because of that I ended up to use readadc10 command.

EDIT:
Idea of measuring: 0,02V get adc value 6 and 2,68V get adc value 530.
Every time adc value is >300 and b2 = 2 then it increases b3. When it have done that 40 times it means 1 desilitre is passed.
every time adc value is < 100 b2 is setted to number 1. That method prevents that b3 is not increasing more than 1 click

QUESTION?
So...Do you have any idea how I could improve my code so that it could measure consumpted water faster?




Code:
readadc10 c.0, w0

if w0 > 300 and b2 = 1 then inc b3 ' If voltage 2,7V and b2 = 1 -> let's increase 1 click
else if w0 > 300 and b2 = 1 then let b2 = 2 ' Let's set b2 back to value 2
end if

if w0 > 300 then let b2 = 2 ' if voltage 2,7V, sp b2=2
end if

if w0 < 100 then let b2 = 1 ' if voltage 0,02V, so b2=1
end if
if b3 > 40 then goto increasing

goto main

increasing:
if b3 > 39 then inc b4 ' 40 click = 1 dl
end if
if b3 > 39 then let b3 = 0
end if

if b4 > 9 then inc b5 ' 10 dl = litre
end if
if b4 > 9 then let b4 = 0
end if

if b5 > 9 then inc b6 ' tens litres
end if
if b5 > 9 then let b5 = 0 
end if

if b6 > 9 then let b4 = 0 '
end if
if b6 > 9 then let b5 = 0 
end if
if b6 > 9 then let b6 = 0 
end if

serout b.0, n2400, (254, 128)      
serout b.0, n2400, (#b3) 

serout b.0, n2400, (254, 192) ' Show tens litres
serout b.0, n2400, (#b6)
serout b.0, n2400, (254, 193) ' Show litres
serout b.0, n2400, (#b5)
serout b.0, n2400, (254, 194) ' Show comma 
serout b.0, n2400, (",")
serout b.0, n2400, (254, 195) ' Show desilitres
serout b.0, n2400, (#b4)
serout b.0, n2400, (254, 197) ' 
serout b.0, n2400, ("Litres")

goto main
 
Last edited:

craigcurtin

Senior Member
WHat picaxe are you using as this will make a difference

Hi again! I'm using waterflow meter like: http://www.ebay.com/itm/261152910400?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649
I have made a code for that and I can measure water consumption. When testing 1,5 l amount of water the lcd shows exatly 1.5l.
Problem is that when passing water fast through watermeter Picaxe cannot register hall sensor's click enough accurately. So amount of 1.5l consumpted water can be in lcd 0,7l. That's not good.
I have tested that hall sensor and it give voltage values 0,02V(because of leakage current?) and 2,68V. Because of that I ended up to use readadc10 command.

QUESTION?
So...Do you have any idea how I could improve my code so that it could measure consumpted water faster?




Code:
readadc10 c.0, w0

if w0 > 300 and b2 = 1 then inc b3 ' If voltage 2,7V and b2 = 1 -> let's increase 1 click
else if w0 > 300 and b2 = 1 then let b2 = 2 ' Let's set b2 back to value 2
end if

if w0 > 300 then let b2 = 2 ' if voltage 2,7V, sp b2=2
end if

if w0 < 100 then let b2 = 1 ' if voltage 0,02V, so b2=1
end if
if b3 > 40 then goto increasing

goto main

increasing:
if b3 > 39 then inc b4 ' 40 click = 1 dl
end if
if b3 > 39 then let b3 = 0
end if

if b4 > 9 then inc b5 ' 10 dl = litre
end if
if b4 > 9 then let b4 = 0
end if

if b5 > 9 then inc b6 ' tens litres
end if
if b5 > 9 then let b5 = 0 
end if

if b6 > 9 then let b4 = 0 '
end if
if b6 > 9 then let b5 = 0 
end if
if b6 > 9 then let b6 = 0 
end if

serout b.0, n2400, (254, 128)      
serout b.0, n2400, (#b3) 

serout b.0, n2400, (254, 192) ' Show tens litres
serout b.0, n2400, (#b6)
serout b.0, n2400, (254, 193) ' Show litres
serout b.0, n2400, (#b5)
serout b.0, n2400, (254, 194) ' Show comma 
serout b.0, n2400, (",")
serout b.0, n2400, (254, 195) ' Show desilitres
serout b.0, n2400, (#b4)
serout b.0, n2400, (254, 197) ' 
serout b.0, n2400, ("Litres")

goto main
Your first two lines of code also look wrong depending on what you are trying to achieve ?

Craig
 

Puuhaaja

Senior Member
Craig:
Code is workin and measuring water amount accurately when waterflow is slow. Problem is that when waterflow is fast Picaxe cannot register hall sensor's pulses accurately. That means 1,5l water is measured 0,7l which I can see on Lcd.
 

Hooter

Senior Member
Shouldn't you be counting the pulses from the flow meter instead of ReadADC.
As the water flow increases and decreases so does the pulse count output.
Perhaps Pulsin would achieve what you want.
Hooter
 

craigcurtin

Senior Member
Well i do not see how you will ever satisfy the condiition to get to line 2

Craig:
Code is workin and measuring water amount accurately when waterflow is slow. Problem is that when waterflow is fast Picaxe cannot register hall sensor's pulses accurately. That means 1,5l water is measured 0,7l which I can see on Lcd.
Again though - which Picaxe are you running ?

Craig
 

Puuhaaja

Senior Member
Hooter:

If Readadc10 value > 300 then it's one pulse. 40 pulse = 1 dl, 400 pulse= 1 litre etc...

main: pulsin C.3,1,w1 ; record the length of a pulse on C.3 into w1
debug ; report the result
goto main ; and repeat
If I supposed right command above measure for example how many milliseconds pulse last. If it's that it means that command would be perfect for measuring how many litres/min water are running through meter.
 

nick12ab

Senior Member
I'm usin 18m2 I have also one 18m2+ chip.
Brilliant! Ditch the serial LCD idea, change to a parallel LCD (by removing the display from the serial backpack) and drive it directly from the PICAXE. The serout command takes up a lot of time compared to parallel LCD interfacing so if your code is missing some pulses because of these serout commands use of a parallel LCD (preferably 8-bit) will fix this. If necessary, change to a bigger PICAXE.

If you really have to use a serial display, you don't need to have all these separate serout commands:
Code:
serout b.0, n2400, (254, 128)      
serout b.0, n2400, (#b3) 

serout b.0, n2400, (254, 192) ' Show tens litres
serout b.0, n2400, (#b6)
serout b.0, n2400, (254, 193) ' Show litres
serout b.0, n2400, (#b5)
serout b.0, n2400, (254, 194) ' Show comma 
serout b.0, n2400, (",")
serout b.0, n2400, (254, 195) ' Show desilitres
serout b.0, n2400, (#b4)
serout b.0, n2400, (254, 197) ' 
serout b.0, n2400, ("Litres")
Instead use this:
Code:
serout B.0,N2400,(254,192,#b6,254,193,#b5,254,194,",",254,195,#b4,254,197,"Litres")
Or even better: (because you don't have to reposition the cursor after each byte)
Code:
serout B.0,N2400,(254,192,#b6,#b5,",",#b4," Litres")
Or better still write the "litres" text in the correct position at the very beginning of the code and only write the changing numbers in the loop.
 

techElder

Well-known member
You are using an analog measuring technique on a digital output.

Your sensor is already providing you digital output equivalent to flow rate.

The "specs" provided define the "frequency" of that output equivalent to flow rate ("pulse frequency (Hz) = [8.1Q -3 ± 10% (proficiency test) (Q is the flow L / min.)").

You measure that, calibrate those measurements and put it on your display.

Your analog method is way to slow to keep up with the "specified" 30L / min output pulse train.

[HR][/HR]

Here's the "specs" from the eBay item:

Description: water flow sensor

The water flow sensor by the plastic body, the flow rotor components and the Hall sensor.
It installed in water heaters, water-side, used to detect water flow, when the water through the water rotor components,
Magnetic rotor rotation speed change with the flow changes, the Hall sensor output corresponding pulse
Signal feedback to the controller, the controller to determine the size of the water flow regulation

Technical parameters

Scope of application: Applicable to automatic gas/ water heater

1. lowest rated voltage: DC4.5 5V-24V

2. maximum working current: 15 mA (DC 5V)

3. voltage range: DC 5 ~ 18 V

4. load ability: &#8804; 10 mA (DC 5V)

5. use temperature range: &#8804; 80 °C

6. use humidity range: 35% ~ 90% RH (No frost status)

7. allows pressure: Water pressure 1.75 Mpa belowv

8. storage temperature: -25 ~ +80 °C

9. Storage Humidity: 25% ~ 95% RH


Output waveforms: square wave

1. output pulse high level: > DC 4.5 V (input voltage DC 5 V)

2. output pulse low level: < DC 0.5 V (input voltage DC 5 V)

3. accuracy (flow rate - pulse output): 1 ~ 30 L / min, ± 1% or less

4. output pulse duty cycle: 50 ± 10%

5. output rise time: 0.04&#956;S

6. output fall time: 0.18&#956;S

7. flow rate - pulse characteristics: Level test pulse frequency (Hz) = [8.1Q -3 ± 10% (proficiency test) (Q is the flow L / min.)

8. impact resistance: From 50cm height of the X, Y, and Z-direction of free fall to the concrete surface, without exception,
Precision changes in less than 10%.

9. insulation resistance: Insulation resistance 100M&#937; or more between the Hall sensor with copper body. (DC 500V)

10. heat resistance: In 80 + 3 °C environment for 48 h, return to room temperature 1-2 h no abnormalities, and parts no crack, relaxation, inflation, and deformation phenomenon, precision change within 10%

11. cold resistance: 20 ± 3 °C in-in the environment for 48 h, return to room temperature 1-2 h no abnormalities, and parts no crack, relaxation, inflation, and deformation phenomenon, precision change within 10%.

12. moisture resistance: In the 40 ± 2°C, relative humidity 90% ~ 95% RH environment placed 72 h after out insulation resistance, 1 M &#937; above.

13. drawing strength: 1 minutes 10N pulling force imposed on the pin-out, no loose, pull-off phenomenon, and the performance did not change.

14. durability: At normal temperature, from the 0.1 MPa pressure into the inlet, to turn on 1 S, disconnect 0.5 S for a cycle, Test 300000 times no abnormalities.
 

Puuhaaja

Senior Member
WoW! Thanks Nick12ab. 12 lines of code are now pressed to one line. Maybe one of the best codepressing result in this forum. I didn't know that lcds can be controlled this way. Maybe I should press submit tutorial button in basic code example area.

Texaslodhopper:

You are using an analog measuring technique on a digital output.
Yes. I don't know yet how to measure it digitally. pulsin C.3,1,w1 is measuring it during 1 second time perioid(I suppose) and I want that its measuring it all the time so that 400 pulses = 1 litre etc...
That's important because the long code I pasted here is only one part of whole program.
 

nick12ab

Senior Member
I didn't know that lcds can be controlled this way. Maybe I should press submit tutorial button in basic code example area.
I don't blame you - the Rev-Ed example uses separate serout commands for repositioning the cursor and displaying data - I was wondering why recently quite a few people had been doing this!

I would suggest you leave a comment. Log in on the PICAXE.com website with your PICAXE Forum credentials and you can then leave a comment on the Serial LCD page.

Yes. I don't know yet how to measure it digitally. pulsin C.3,1,w1 is measuring it during 1 second time perioid(I suppose) and I want that its measuring it all the time so that 400 pulses = 1 litre etc...
That's important because the long code I pasted here is only one part of whole program.
Instead of 'if w0 > 300' use 'if pinC.0 = 1' and instead of 'if w0 < 100' use 'if pinC.0 = 0'.
 
Last edited:

lbenson

Senior Member
This should count the number of pulses in a minute.
Code:
#picaxe 08m2

main:
  do
    gosub countPulses
    sertxd(#w6," pulses in one minute",cr,lf)
  loop

countPulses:
  time = 0  ' M2 seconds counter word variable
  w6 = 0
  bit0 = 0
  do while time < 60
    if pin1 <> bit0 then ' change of state [whichever pin is used]
      if bit0 = 0 then   ' previous state was off
        inc w6           ' new "on" state--increment count
      endif
      toggle bit0
    endif
  loop
  return
It wasn't clear to me from the instructions what the exact relationship was between pulses and litres per second/minute.
 

hippy

Technical Support
Staff member
I didn't know that lcds can be controlled this way. Maybe I should press submit tutorial button in basic code example area.
I don't blame you - the Rev-Ed example uses separate serout commands for repositioning the cursor and displaying data - I was wandering why recently quite a few people had been doing this!
The example had the positioning commands separate so the comments could make it clear what each SEROUT command did, and it was useful to have shorter commands to fit the comments alongside those.

An Example 2 has been added to clarify that multiple SEROUT commands can be combined.
 

Puuhaaja

Senior Member
I don't blame you
You don't but I admit my guilty. In my vindication I invoke my language which isn't english.
Anyways...I have read those link earlier but I didn't understood that enough well.
So I got an idea:

Let's exept that temperature is 101 Celsius

Sub1: serout b.2, n2400, ( 254, $80 )
serout b.2, n2400, ( "Temperature" )
serout b.2, n2400, ( 254, $C0 )
serout b.2, n2400, ( b1, b2, b3, "C" ) ' Lcd shows now: "Temperature 101C" in two lines
return


Sub2: serout b.2, n2400, ( 254, $80, "Temperature", 254, $C0, b1, b2, b3, "C" ) ' Lcd shows now: "Temperature 101C" in two lines
return

That would help noobie people like me to undertand what those commands actually means.
What do you think about that?
 
Last edited:

westaust55

Moderator
Let's except that temperature is 101 Celsius

Code:
Sub1:	serout b.2, n2400, ( 254, $80 )
	serout b.2, n2400, ( "Temperature" )
	serout b.2, n2400, ( 254, $C0 )
	serout b.2, n2400, ( b1, b2, b3, "C" )      '[COLOR="#FF0000"] Lcd shows now: "Temperature 101C" in two lines [/COLOR]
	return
:
:

That would help noobie people like me to understand what those commands actually means.
What do you think about that?
The control codes such as 253, 254, $80, $C0 are not specific to the PICAXE chips but are control codes for the LCD or OLED displays.
While the majority of character based LCD and OLED displays use a chip that is Hitachi controller compatible there are those use different controllers and then there are graphic LCD and OLED displays that have completely different control and command sequences.

So where would Rev Ed stop ???

It is necessary for the user of any particular display module to read the datasheet for the controller on that display module and learn about the allowable control codes.

For example, the Rev Ed character displays do provide control codes in their datasheets:
AXE033 display: http://www.picaxe.com/docs/axe033.pdf (See pages 7, 8 and 9)
AXE133 display: http://www.picaxe.com/docs/axe133.pdf (See page 3)

If you read the Hitachi HD44780 datasheet (the chip used for many character type/based displays) you will also find out more about the control code. See:
http://www.sparkfun.com/datasheets/LCD/HD44780.pdf
In particular in the linked example see pages 24 and 25.
 

Puuhaaja

Senior Member
So where would Rev Ed stop ???
I think that right person to answer for that question is a beginner who is doing process for the first time in his life.
But...learning to do somethin is never automatical process that you just watch and read how to do different kind of things. There's always much effort that has to be done.
Anyways I give full points for Rev ed because they have done really and straightly sais amazing much when they have been writing tutorials.

For example, the Rev Ed character displays do provide control codes in their datasheets:
That's true. I started with those leaflets and checked: www.picaxe.com/docs/led008.pdf
Finally I ended up to manual 3 and there was amazing much information how to do things with Lcd. That really helped me much.

At the end I would say that important question when talking about code examples is: Ask for the beginner. The more expert you are the more blind you are for your point of views(likely). Beginner's eyes are open.
 

Puuhaaja

Senior Member
I think I have now solved problem. I ended up to use following code:

setfreq m32

main:
if pinc.0 = 1 and b2 = 1 then inc b3
end if

if pinc.0 = 1 then let b2 = 2
end if

if pinc.0 = 0 then let b2 = 1
end if
if b3 > 40 then goto inc
goto main
With 32 Mhz it's workin well and counting hits enoug well. Not perfect however. With slow water speed and 32 Mhz it's showing less litres than when using 4mhz and slow waterspeed. I will try to chech what diode could do because it will not pass pulses under 0,6V trough it.

I have also planned that I could try to test decade counter for that(2 of them). 40 hits would give one pulse for Picaxe -> 1dl. That would enables Picaxe to do some other tasks during countig process. Would that be possible at all? I just found decade counter from techsupplies and checked what kind of gadget it is and supposed that it would works on my project. Any ideas or any other ics?
 

hippy

Technical Support
Staff member
I think I have now solved problem. I ended up to use following code:

setfreq m32

main:
if pinc.0 = 1 and b2 = 1 then inc b3
end if

if pinc.0 = 1 then let b2 = 2
end if

if pinc.0 = 0 then let b2 = 1
end if
if b3 > 40 then goto inc
goto main
With 32 Mhz it's workin well and counting hits enoug well. Not perfect however. With slow water speed and 32 Mhz it's showing less litres than when using 4mhz and slow waterspeed.
It seems then that the problem is not actually solved by the code given or there are other issues elsewhere.

I don't really follow the logic of the code. Your 'b3>40' should likely be b3>=40' and, if so, you have a 2.5% loss error there. I would also say you are making it far more complicated than it needs to be -

Code:
Main:
  SetFreq M32
  Do
    Do : Loop Until pinC.0 = 0
    Do : Loop Until pinC.0 = 1
    Inc b3
    If b3 >= 40 Then
      Gosub Increment
    End If
  Loop
The real limitation in the code though is the serial update of the LCD. At 2400 baud that is going to take at least 20ms to update the display. That means the flow meter will never be entirely accurate when receiving more than 50 pulses per second, or a flow rate greater than around 0.1 litre per second.

The error is less than it could be because you only update the display every 40 pulses, not every pulse. The error rate changes depending on flow rate and increases with flow rate. At 1 litre per second that is 400 pulses per second, 2.5ms between pulses, updating the display every 40 pulses means 10 updates of 20ms each and 200ms lost to display updates in that second. During that time some 80 pulses will have been missed. During a second you will have counted 320 pulses rather than 400 so the determined flow rate will be 20% below what it should be.

There should be less error as the flow rate reduces, none as said at around 0.1 litre per second. If the error is worse at lower flow rates this suggests a code problem, either the way pulses are being detected and counted or elsewhere in the code. It would be worth posting the actual code.

So how to measure higher flow rates ?

Increasing clock frequency speeds will not help greatly as it is the baud rate that is the problem; that LCD update takes 20ms or more no matter how fast the chip runs.

One option is to have two PICAXE chips. The first simply generates a pulse out every 40 flow pulses seen; a glorified decade counter. That adds an extra PICAXE though.

A second option is to use multi-tasking and output only one byte to the LCD at a time. After each byte sent the code will go check the input pins for a pulse again so some five times faster than sending all bytes together. Untested ...

Code:
Start0:
  Do
    Do : Loop Until pinC.0 = 0
    Do : Loop Until pinC.0 = 1
    w0 = w0 + 1
  Loop

Start1:
  Pause 1000
  SerOut LCD, N2400, ( 254,$80, "   0.0 Litres" )
  Do
    Do : Loop Until w0 >= 40
    Do
      w0 = w0 - 40
      w1 = w1 + 1
    Loop While w0 >= 40
    BinToAscii w1, b11,b12,b13,b14,b15
    SerOut LCD, N2400, ( 254 )
    SerOut LCD, N2400, ( $80 )
    SerOut LCD, N2400, ( b11 )
    SerOut LCD, N2400, ( b12 )
    SerOut LCD, N2400, ( b13 )
    SerOut LCD, N2400, ( b14 )
    SerOut LCD, N2400, ( "." )
    SerOut LCD, N2400, ( b15 )
  Loop
If that works, then it can be improved further by using HSEROUT to communicate with LCD, again untested ...

Code:
Start0:
  Do
    Do : Loop Until pinC.0 = 0
    Do : Loop Until pinC.0 = 1
    w0 = w0 + 1
  Loop

Start1:
  HserSetup B2400_16, %110
  Pause 1000
  HSerOut 0, ( 254, $80, "   0.0 Litres" )
  Do
    Do : Loop Until w0 >= 40
    Do
      w0 = w0 - 40
      w1 = w1 + 1
    Loop While w0 >= 40
    BinToAscii w1, b11,b12,b13,b14,b15
    HSerOut 0, ( 254 ) : Pause 20
    HSerOut 0, ( $80 ) : Pause 20
    HSerOut 0, ( b11 ) : Pause 20
    HSerOut 0, ( b12 ) : Pause 20
    HSerOut 0, ( b13 ) : Pause 20
    HSerOut 0, ( b14 ) : Pause 20
    HSerOut 0, ( "." ) : Pause 20
    HSerOut 0, ( b15 ) : Pause 20
  Loop
The reason for using 'w0' to count pulses in the 'Start0:' loop rather than a byte variable, 'b0'; is it allows us to spend however long in the 'Start1:' routine that we need. If 'Start1:' is running slower per loop than the rate 'w0' is updating we won't lose counted pulses, and we can bring our 'w1' count in 'Start1:' up to date when we need to.
 
Last edited:

MartinM57

Moderator
Not really tracking this thread, but why are you/the forumites trying to count pulses by software polling instead of using an interrupt routine to count them and a main loop updating the display?
...and are you really sure that 40 pulses = 1dl at any flow rate? To what accuracy?
 

hippy

Technical Support
Staff member
Not really tracking this thread, but why are you/the forumites trying to count pulses by software polling instead of using an interrupt routine to count them and a main loop updating the display?
Good point! And that's the advantage of a forum with a variety of viewpoints, alternatives and different approaches to skinning the proverbial cat ...

Code:
Symbol INTERRUPT_MASK = %00000001

Main:
  Gosub Interrupt_Enable
  Pause 1000
  SerOut LCD, N2400, ( 254,$80, "0000.0 Litres" )
  Do
    Do : Loop Until w0 >= 40
    Do
      w0 = w0 - 40
      w1 = w1 + 1
    Loop While w0 >= 40
    BinToAscii w1, b11,b12,b13,b14,b15
    SerOut LCD, N2400, ( 254 )
    SerOut LCD, N2400, ( $80 )
    SerOut LCD, N2400, ( b11 )
    SerOut LCD, N2400, ( b12 )
    SerOut LCD, N2400, ( b13 )
    SerOut LCD, N2400, ( b14 )
    SerOut LCD, N2400, ( "." )
    SerOut LCD, N2400, ( b15 )
  Loop

Interrupt:
  If b10 = 0 Then
    w0 = w0 + 1
  End If

Interrupt_Enable:
  b10 = b10 ^ INTERRUPT_MASK
  SetInt b10, INTERRUPT_MASK
  Return
 
Last edited:

techElder

Well-known member
In other words, the real problem is that you are trying to update the display at the same time as you are trying to count pulses from the flow meter.

Well, don't do that!

Save the count that you want for the time period that you want, then go do the display thing as slow as you want.

There's no mention by the original poster (OP) of any time crunch involved, and that wouldn't take much time to do anyway.

I see that's what Hippy is trying to do in his suggestion and MartinM57 suggests about the same thing using interrupts.
 

Puuhaaja

Senior Member
Thousands of thanks! This thread has has given much information me about programming Picaxe. Do:loop, multitasking and interrupt. All of them were new things for me. At the moment I have tested only do Do: loop code but later I will check also multitaskin and interrupts. Do: loop code seemed to react faster than my original code with 32mhz. I tested it by blowing air.

Thanks Hippy for your long explanation. Later I will check those codes with measuring cup and report about results. I will test those codes with slow and fast water speed.
 

Puuhaaja

Senior Member
I encountered few problems with those codes.

When using multitasking and hserout commandline.
HserSetup B2400_16, %110
causes following message in Linaxepad:
Syntax check for Picaxe-18m2 failed
Hsersetup B2400_16, %110
Error: Invert hserin pin (bit2 = 1) not supportedby this chip
And when using interrupts following command line:
SerOut b.0, N2400_32, ( 254,$80, "0000.0 Litres" )
causes following message:
Syntax check for Picaxe-18M2 Failed
Serout b.0, n2400_32, ( 254,$80, "0000.0Litres" )
Error: Unknown symbol - N2400_32
Any ideas how to continue?
 

westaust55

Moderator
In earlier posts to this thread there was reference to 32 MHz in SETFREQ commands.
Your SEROUT above has "_32" but the HSEROUT has "_16"

Are you changing PiCAXE clock speeds?
 

westaust55

Moderator
Craig:

I'm usin 18m2 I have also one 18m2+ chip.
The default speed for an 18M2 (or any M2 and X1 chips) is 4 MHz. By comparison the default speed for an X2 part is 8 MHz

In the post by hippy (page 2) there is the command:
Main:
SetFreq M32

therefore the clock speed is increased from the default 4 MHz to 32 MHz.

For serial communications at other than the default clock speed, the baudrate parameter requires the suffix "_xx" where xx matches the clock speed.

It would be worth you posting your entire code in full rather than just the segment/line of concern so that folks here can appreciate the entire program and interactions.
 

roscos

New Member
Hi all, I may have missed something but why wouldn't you use the COUNT command to register the number of revs of the paddle, then it does not matter about the volume as long
as the chamber was full.
roscos.
 

Puuhaaja

Senior Member
Simply remove the _32 and it should work.
That's true. I got it working.

Code:
Start0:
  Do
    Do : Loop Until pinC.0 = 0
    Do : Loop Until pinC.0 = 1
    w0 = w0 + 1
  Loop

Start1:
  HserSetup B2400_16, %110
  Pause 1000
  HSerOut 0, ( 254, $80, "   0.0 Litres" )
  Do
    Do : Loop Until w0 >= 40
    Do
      w0 = w0 - 40
      w1 = w1 + 1
    Loop While w0 >= 40
    BinToAscii w1, b11,b12,b13,b14,b15
    HSerOut 0, ( 254 ) : Pause 20
    HSerOut 0, ( $80 ) : Pause 20
    HSerOut 0, ( b11 ) : Pause 20
    HSerOut 0, ( b12 ) : Pause 20
    HSerOut 0, ( b13 ) : Pause 20
    HSerOut 0, ( b14 ) : Pause 20
    HSerOut 0, ( "." ) : Pause 20
    HSerOut 0, ( b15 ) : Pause 20
  Loop
There's a line:
Hsersetup B2400_16, %110
And that line causes following message in 18m2
Syntax check for Picaxe-18m2 failed
Hsersetup B2400_16, %110
Error: Invert hserin pin (bit2 = 1) not supportedby this chip
I tried to change some parameters but didn't get it working.
 
Last edited by a moderator:

Puuhaaja

Senior Member
why wouldn't you use the COUNT command to register the number of revs of the paddle
Problem is that you need count pulses all the time when the whole program is running and in count command you need to specify time when picaxe is counting pulses. But...If I'd set counting time perioid enough long it would work. At the moment I think that interrupts and multitasking are best opportunies. Anyways...next week I will check those programs with measurecup using slow and fast waterspeed and I will report about results here.
 

hippy

Technical Support
Staff member
Syntax check for Picaxe-18m2 failed
Hsersetup B2400_16, %110
Error: Invert hserin pin (bit2 = 1) not supportedby this chip
You have to use 'Hsersetup B2400_16, %000' or 'Hsersetup B2400_16, %010' with an 18M2. As you are not using 'hserin' whichever is used should not matter.
 

westaust55

Moderator
@Puuhaaja,

not getting angry, but for future reference, when posting program code of more than a few lines, rather than using quote tags, you should use [code] and [/code] tags.

These can be easily access in a few ways:
1. type them in

2. When using cut and past from the program editor use the sequence:
.. (a) Edit/Select All - if appropriate otherwise select the part you want to post
.. (b) Edit/Copy for Forum - this then includes the [code] and [/code] tags.
.. (c) past into the forum post window

3. if already in a post window,
.. (a) select the Go Advanced button at the bottom right of the post window
.. (b) select the code as already exists within your post window
.. (c) click on the hash icon (#) to the right side in the midle row of the post window toolbar

hope that information helps you.
 
Last edited:

Puuhaaja

Senior Member
I'm back again with some test results! I made some test with slow and fast waterspeed using 1,5 litre measuring cup which I filled 3 times = 4,5 litres/test.

Do loop code using 32 Mhz

Code:
low b.0
pause 1000
serout b.0, n2400, (254, 1)
pause 600
setfreq m32

Starting:
goto increment


main:
  SetFreq M32
  Do
    Do : Loop Until pinC.0 = 0
    Do : Loop Until pinC.0 = 1
    Inc b3
    If b3 >= 40 Then
      Gosub increment
    End If
  Loop
if b3 > 40 then goto increment

 goto main

increment:
if b3 > 2 then inc b4 
end if
if b3 > 2 then let b3 = 0
end if

if b5 > 9 then inc b6 
end if
if b5 > 9 then let b5 = 0 
end if

if b6 > 9 then let b4 = 0 '
end if
if b6 > 9 then let b5 = 0 
end if
if b6 > 9 then let b6 = 0 
end if

setfreq m4
serout B.0,N2400,(254,192,#b6,#b5,",",#b4," Litres")
setfreq m32

goto main

l
Testing results:
fast speed 4,6 litres
slow speed 4,7litres.
0,1l error between results can be easily measuring mistake

Paraller tasking

Code:
 Start0:
  Do
    Do : Loop Until pinC.0 = 0
    Do : Loop Until pinC.0 = 1
    w0 = w0 + 1
  Loop

Start1:
  Pause 1000
  SerOut b.0, N2400, ( 254,$80, "   0.0 Litres" )
  Do
    Do : Loop Until w0 >= 40
    Do
      w0 = w0 - 40
      w1 = w1 + 1
    Loop While w0 >= 40
    BinToAscii w1, b11,b12,b13,b14,b15
    SerOut b.0, N2400, ( 254 )
    SerOut b.0, N2400, ( $80 )
    SerOut b.0, N2400, ( b11 )
    SerOut b.0, N2400, ( b12 )
    SerOut b.0, N2400, ( b13 )
    SerOut b.0, N2400, ( b14 )
    SerOut b.0, N2400, ( "." )
    SerOut b.0, N2400, ( b15 )
  Loop
Paraller tasking test results:
Fast waterspeed 5,3 litres
Slow waterspeed 4,5 litres
Because of 0,8 litres difference I did this test two times and got same results

Interrupt code

Code:
  Symbol INTERRUPT_MASK = %00000001

Main:
  Gosub Interrupt_Enable
  Pause 1000
  SerOut b.0, N2400, ( 254,$80, "0000.0 Litres" )
  Do
    Do : Loop Until w0 >= 40
    Do
      w0 = w0 - 40
      w1 = w1 + 1
    Loop While w0 >= 40
    BinToAscii w1, b11,b12,b13,b14,b15
    SerOut b.0, N2400, ( 254 )
    SerOut b.0, N2400, ( $80 )
    SerOut b.0, N2400, ( b11 )
    SerOut b.0, N2400, ( b12 )
    SerOut b.0, N2400, ( b13 )
    SerOut b.0, N2400, ( b14 )
    SerOut b.0, N2400, ( "." )
    SerOut b.0, N2400, ( b15 )
  Loop

Interrupt:
  If b10 = 0 Then
    w0 = w0 + 1
  End If

Interrupt_Enable:
  b10 = b10 ^ INTERRUPT_MASK
  SetInt b10, INTERRUPT_MASK
  Return
Interrupt testing results:
Fast waterspeed 5,5 litres
Slow waterspeed 4,7 litres
because of 0,8 litres difference I tested two times and got same results


So...In theory results shouldn't be this kind but I suppose there are many reasons which can cause this. Any ideas?

@Westaust
Don't worry. Earlier I had wondered why I can't use code tags in every threads. Thanks for that.
 

hippy

Technical Support
Staff member
So...In theory results shouldn't be this kind but I suppose there are many reasons which can cause this. Any ideas?
In the first DO-LOOP example I cannot see where b5 and b6 would actually be incremented so hard to tell what's going.

In the parallel tasking and interrupt versions it seems to be counting more pulses than there should be when fast filling. One would normally expect pulses to be missed and a lower count if pulses were coming in more quickly than the code could handle.

It could be that the pulse output isn't linearly proportional to the water flow. You might have to set particular flow rates and measure pulse rates with a frequency meter or scope.
 

Puuhaaja

Senior Member
In the first DO-LOOP example I cannot see where b5 and b6 would actually be incremented so hard to tell what's going.
There was one simple subprocedure where b5 and b6 was incremented. If I delete subprocedure and but b5-b6 incrementing to main program the whole code is working perfectly.
DO-LOOP with 32Mhz and 4 Mhz is working well and shows similar results with slow and fast waterspeed. In Picaxe datasheet there was mention that when reading inputs (if pinc.0=1 etc..) voltage should be above 0.8 x Picaxe voltage when reading that input is high and below 0.2 x Picaxe voltage when reading input to low. Hall sensor I'm using gives about 2.65V when it's high and 0.01V when it's low

Yesterday I tested open collector circuit Which means that hall sensor is switching transistor so that Picaxe could get +5V signal/puls. Results was still wrong when using Paraller tasking mode. I haven't yet tested how interrupt works with that.
Anyways..I think that in future this is not a problem. Recently I purchased 40x2 Picaxe. If I remember right there's 4 program slot which can be programmed. So one slot is scanning waterflow sensor and other slot is running lcd screen. I suppose that variables b0-b56 in 40x2 can be used in every 4 slot that 40x2 has.
 

inglewoodpete

Senior Member
Recently I purchased 40x2 Picaxe. If I remember right there's 4 program slot which can be programmed. So one slot is scanning waterflow sensor and other slot is running lcd screen. I suppose that variables b0-b56 in 40x2 can be used in every 4 slot that 40x2 has.
You only need to use the 2nd (3rd, 4th) slot when you have filled up the first one. There is no good reason to spread your program over several slots if you have not filled the first one. Slots are not the same as multitasking (used in the M2 series PICAXEs). Registers Eg b0-b55 are shared across all slots. There is no b56.
 

Puuhaaja

Senior Member
Thanks for informing me Inglewoodpete. I have now one program which need more than 2kB of code and more than 28 register variables. Little off topic but how those slot are working? Is mc starting from slot 0 and from the line 1. I suppose that after that it continues performing commands line by line until there's a command like run slot 1. After that it will continue in slot 1 line by line untils there's command run slot 2 etc..
 

inglewoodpete

Senior Member
I have used multi-slot working in several projects now. I found it best to have the program's kernel in Slot 0 and subroutines in Slot 1, 2, etc, although it is just as easy having program flow jump from any slot to another.

I documented my first multi-slot method in the last post here.
 

Puuhaaja

Senior Member
I'm sure that your post which you linked will help me when I start to do whole program. You said that slots are not same as multitasking. This is stupid question but does this means that 40x2 can't run more than one slot simultaneously.
 
Top