Automatic "zero-point" detection, how?

KTarke

Senior Member
In another thread, I solved, how to utilize Picaxe's TOUCH -command to detect something else than living material (dry "dead" material, water level)

It seems, that "real world" apps (sensoring) is not as interesting in this forum, as coding. That is why, I am starting a new thread, for the code.

After getting ground data from sensing materials, I am thinking about a code, that can determine a "zero-point" for touch-command, and transfer it to the main program.

The main program senses material level in a container. How much the reading rises, when material reaches the sensor is (roughly) known. But the value in a empty container is not known! (depends on the material/size of the container)

The subroutine, I am thinking of, should read the " base value" in a empty container, and store it (permanently) somewhere. The main program then uses this value as a "zero point" (=empty) and uses "predicted" (by material) value to determine, when material level has reached the sensor.
The "sensitivity" should also be adjustable...

Anyway, subroutine that determines the base value, is to be called only when asked! (not every time program starts! f.e.x after a power down)
After a power down, the main program should read the "base value" from a stored location.

The "base value" represents a empty container. When sensed reading rises to a predicted value (=base+known rise when contact) ,main program decides, that sensor has detected material, and something has to be done.

I have had "gray hair" with Picaxe's IF-command, since it does not compare variables the same way, that common BASIC-languages...
Here is the same problem. If the "base-value" is stored in a variable, how do I execute: IF read value > base value + predicted contact value rise , THEN gosub do something...

Another subroutine (called) should be able to change the "predicted rise of the value ,when contact" (= sensitivity), and store the new value (permanently) somewhere.

I could do this this on my own, in a rude and space-consuming way, but I am asking the forum for hints ,for doing it in a more sophisticated way!

Ideas?
 

hippy

Technical Support
Staff member
If you want to do ...

If a > b + c Then

You need to do ....

z = b + c
If a > z Then

Or ...

z = a - c
If z > b Then

Which to use may depend on underflow or overflow conditions.
 

KTarke

Senior Member
If you want to do ...

If a > b + c Then

You need to do ....

z = b + c
If a > z Then

Or ...

z = a - c
If z > b Then

Which to use may depend on underflow or overflow conditions.
Yes, that is the way, things has to be done... since Picaxe's If-statement (unfortunately) does not tolerate calculations in the statement...
That was just, what I was "complaining" about. It would be much more undestandable code, if I could write: IF "name" - "other name" < "third name", THEN...

But the real question was another. (I did not form it clearly enough)

When using 18M2, what is the best place to store (power down-proofly)
a WORD (subroutine reads a value from touch16 command and stores it, to be the "base" value...)
I very well know, that answer to this question can be found in manuals... but just now I am tired, when had completed the task with the mechanical part of touch-sensors, and want to get even started with the program... So, I do not have energy to teach my self the new things in 18M2-part, I just ask those, who know without searching!

So, my question is: where is a good place to store (if not in the chip, then I must use the LCD for storage (if I remember right, there is a few bytes available)) Before I have used X2-parts, and there is some permanent bytes to use... how about M2-parts?
(I have just started using M2, and concentrated all my energy in testing the touch-feature. Just don't yet know anything else about the M2)

I think, auto-calibration-subroutine could be useful to others too, even when using touch with a finger...
Always, if the user is not the same as the programmer... there should be an easy way to recalibrate sensitivity (without the need of cable or source code!)

Just now, my creativity is low, and need some ideas (pushing...) to get started in the project.
 

hippy

Technical Support
Staff member
On-chip EEPROM would be the most logical answer. Generally all PICAXE are the same with respect to core features.
 
Top