Is it possible to choose one of the two stored programs?

Andrei IRL

Senior Member
Hi again.

I want to use a strain gauge as an input device.

When a certain amount of force is applied a relay will actuate.

here is the problem
for some users i need to monitor PULL force which will give me increased READADC reading and based on that i can trigger rely when its larger then the preset value,
for other users i need to monitor PUSH force which will give me decreased READADC reading and based on that i can trigger relay when its smaller then the preset value.

The problem is, i need to be able to preset which program to run as one will have if< statement and the other will have if> statement. Can not run both statements at the same time as only need the relay to trigger for one of these conditions.,

Prior to changing the design to analog input, hence the need for READADC, i was working with digital input for this same function.
I had a small routine running up on program start that if one of the two buttons was pressed changed my variable to 0 or a 1 and that determined the direction of the force applied that the proximity sensor would use.

Now with strain gauge i want to have the same functionality.

I am maxed out on the inputs and outputs on my 08m2 chip so i can not put a selector switch to be used if that was possible.

Here is the initial code that i started working on (thanks to hippy for some help):

Code:
symbol sens=b9
read 1,sens
if pin5=1 then pull
if pin3=1 then push_1
  	
pull: 
	readadc 4,b8
 		if b8>sens then
  			let sens = b8
 		end if
	write 1,sens
goto main

push_1: 
	readadc 4,b8
 		if b8<sens then
   			let sens = b8
 		end if
	write 1,sens
goto main

main:       high greenled
		readadc 4,b7
		if b7>sens then fire
goto main
So the code above will set the largest or the smallest value read by READADC depending on which one of the two buttons was held pressed during program start up.
So then dependin on that i also would like to have the
Code:
if b7>sens then fire
to change from that to
Code:
if b7<sens then fire
depending on which one of the routines was ran before the main routine.
So the pull and push_1 routines are only possible to run upon initial power on.

I will also need to set a timer within pull and push_1 routines so they are running for about 30 seconds if activated.

I am not sure if the above is making a lot of sense to ye guys but will appriciate any help ye might provide.

Failing that i will have to switch to a larger chip and use a selector switch which will determine the routine to be ran, not sure if this is possible either at the moment.
 

hippy

Technical Support
Staff member
It might help to explain what you need in a clearer way; how a user would see it described in usage instructions they would be given is often the best way.

Don't so much worry about how it will do it; concentrate on how it will behave, how it is to be setup, used, and how it responds in use.
 

lbenson

Senior Member
If a hardware selector switch cannot be added (are you using C.5?), it would seem that any method of differentiation that you use will have to be via a program, so why not just have one program for the PULL and one for the PUSH, and label your programmed chips accordingly, even if only with a drop of nail polish or a piece of tape.
 

Andrei IRL

Senior Member
It might help to explain what you need in a clearer way; how a user would see it described in usage instructions they would be given is often the best way.

Don't so much worry about how it will do it; concentrate on how it will behave, how it is to be setup, used, and how it responds in use.

In the meantime we would recommend removing the WRITE commands from the code you have as they will be repeatedly writing to EEPROM and will quickly wear that out if unchecked.
Thanks very much for the feedback hippy.

The first part of the routine with the WRITE command will only be used during the initial set-up when PIN5 or PIN3 are high.
After the initial set up is done there will be no need for the user to press either one of these buttons so the PULL and PUSH routines will not be executed and the program jumps straight to the MAIN and loops on there.

This strain gauge will be used on a motorbike as a shift sensor.
For some users the direction of the force applied to the strain gauge will be in positive direction for other in negative , that will depend on individual bike and linkage set up.

this is how the instructions would look:
PUSH MODE:

-To set up the controller for "PUSH" direction press PUSH button on the controller and turn the ignition ON.
-This will turn the controller ON and put it into "Learn" Mode for PUSH direction for the length of 20 seconds.
-Green and Red LED's will be lit while in the "Learn Mode".
-No shift through the gears as during normal riding.
-Controller will sense the maximum effort that was required to change gears and will remember that "sensitivity".

After 20 seconds have passed the controller enters the MAIN routine and monitored the Strain gauge readings.
When reading are above the previously set value it will active a relay.

PULL MODE:

-To set up the controller for "PULL" direction press PULL button on the controller and turn the ignition ON.
-This will turn the controller ON and put it into "Learn" Mode for PULL direction for the length of 20 seconds.
-Green and Red LED's will be lit while in the "Learn Mode".
-No shift through the gears as during normal riding.
-Controller will sense the maximum effort that was required to change gears and will remember that "sensitivity".

After 20 seconds have passed the controller enters the MAIN routine and monitored the Strain gauge readings.
When reading are below the previously set value it will active a relay.

I have this project working very well at the moment with the proximity sensor but i would like to take it to the next level by using strain gauge, as it offers more friendly set up and more accurate operation.

I have the the amp for the strain gauge designed and it will be outputting 2.5V when the strain gauge is at zero force.
It will swing either way from 2.5 volts depending on the direction of applied load.

The thing is, i can only have either PUSH or PULL mode working at any one time and the controller needs to remember what mod it was set up for upon restart.


Hope the explanation above is more clear.

Thanks very much in advance for any ideas.
 

Andrei IRL

Senior Member
Ok, an update , i think i have it sorted.
what i did was, while running set-up routines i give either the very minimum value or the very maximum value to one of the my two variables knowing that it can not be met.
So only one of the If's will be operational.

There is only one thing left to figure out, how do i go about timing the PULL and PUSH_1 routines to 20 seconds loop?

So if button is pressed upon PICAXE power on the program jumps to PULL routine performing READADC for 20 seconds and then just come out of it after and run the MAIN routine?

I suppose i could just power the PICAXE OFF and BACK ON and the prigram will skip PULL and PUSH routines as no buttons will be pressed going straight to the main program.
 
Last edited:

hippy

Technical Support
Staff member
This strain gauge will be used on a motorbike as a shift sensor.
This makes it a safety critical system. Inadvertent or incorrect operation may have serious adverse consequences. We would not recommend the use of a PICAXE in such an application.

If I read it right then the specification is -

1) A unit which can determine if a gear lever is being pushed-down or pulled-up through monitoring a strain gauge and will adjust its output accordingly.

2) The unit can be programmed to set the amount of pressure which determines gear lever pushed-down or pulled-up activation.
 

Andrei IRL

Senior Member
This makes it a safety critical system. Inadvertent or incorrect operation may have serious adverse consequences. We would not recommend the use of a PICAXE in such an application.

If I read it right then the specification is -

1) A unit which can determine if a gear lever is being pushed-down or pulled-up through monitoring a strain gauge and will adjust its output accordingly.

2) The unit can be programmed to set the amount of pressure which determines gear lever pushed-down or pulled-up activation.
Cheers hippy,

The device is for race bikes ONLY and i have built safe fail into the design of it.

You are correct with your assumptions 1 and 2.

I am not sure if you have seen the post i just put up a minute ago before you did, i have current code there.
But i am struggling to come up with a LOOP condition based on time for a small part of the routine.
 

oracacle

Senior Member
This appears to be a quick shifter type arrangement. While a nice feature to be able to have it be able to work for both normal road bike as well as bikes with a gearbox setup for track use, makes me wonder how it would compare to commercial units.
My street triple came with one and its brilliant fun when there are no speed limits and due to the work triumph have put into it, it work better than most at lower RPMs too. it alters the amount of time the spark is killed depending on the engine speed and gear selection.

The problem I can see with the sensitivity training part of the system is the fact that changing using the clutch will offer little to no mechanical resistance - and thus very little effort. No if crash changing is used during the programming stage quite a large amount of force could be applied before the gear change happens if the rider isn't very well versed in the technique. I had to increase the force I applied to the lever when moving to the quick shifter as before I had one I would apply a small force before a gear change, close the throttle very briefly and then re-open it, gear change would then be complete with only very small amounts of force needed (fast but not as fast as the 0.05 second of the quick shifter).

If indeed you are making a quick shifter I would take a look at using and X2 picaxe and the comparator interrupt facility they come with, you can have an empty loop once the interrupt is done. With the picaxe running @ 64mhz response time can be less the 200us
 

Andrei IRL

Senior Member
This appears to be a quick shifter type arrangement. While a nice feature to be able to have it be able to work for both normal road bike as well as bikes with a gearbox setup for track use, makes me wonder how it would compare to commercial units.
My street triple came with one and its brilliant fun when there are no speed limits and due to the work triumph have put into it, it work better than most at lower RPMs too. it alters the amount of time the spark is killed depending on the engine speed and gear selection.

The problem I can see with the sensitivity training part of the system is the fact that changing using the clutch will offer little to no mechanical resistance - and thus very little effort. No if crash changing is used during the programming stage quite a large amount of force could be applied before the gear change happens if the rider isn't very well versed in the technique. I had to increase the force I applied to the lever when moving to the quick shifter as before I had one I would apply a small force before a gear change, close the throttle very briefly and then re-open it, gear change would then be complete with only very small amounts of force needed (fast but not as fast as the 0.05 second of the quick shifter).

If indeed you are making a quick shifter I would take a look at using and X2 picaxe and the comparator interrupt facility they come with, you can have an empty loop once the interrupt is done. With the picaxe running @ 64mhz response time can be less the 200us
Thanks very much for the input oracacle.
This is exactly what i am designing.

I have already made a number if units using a different type of sensor (proximity sensor) similar to the way Bazzaz system work.

But everyone is running strain gauge sensors these days so i would like to use it as well.

Would you be able to provide a little more information on the X2 chip please?

I am not familiar on what extra options they offer when compared to an M2 chip.
 

oracacle

Senior Member
her is the X2 summary found on the picaxe website
http://www.picaxe.com/docs/picaxex2.pdf

the X2s can normally run faster clock speeds, have more storage space and a few other bits (including analogue comparator), there are also a few thing that they don't have (multi tasking).

if you were to use the comparator on the 20x2 (pins b.2 and b.3, you don't have to use both) you could in theory actually use the same programme and just change the interrupt flags to match the settings. You will loose some resolution as there are only 32 possible selection on the internal voltage ladder but this should still be more than enough resolution for what you need

both these will be needed, refer to manual 2 for more information on the comparator and its IVR
comparator setup
http://www.picaxe.com/BASIC-Commands/Advanced-PICAXE-Configuration/compsetup/
setintflags
http://www.picaxe.com/BASIC-Commands/Interrupts-and-Multi-Tasking/setintflags/
 

Andrei IRL

Senior Member
her is the X2 summary found on the picaxe website
http://www.picaxe.com/docs/picaxex2.pdf

the X2s can normally run faster clock speeds, have more storage space and a few other bits (including analogue comparator), there are also a few thing that they don't have (multi tasking).

if you were to use the comparator on the 20x2 (pins b.2 and b.3, you don't have to use both) you could in theory actually use the same programme and just change the interrupt flags to match the settings. You will loose some resolution as there are only 32 possible selection on the internal voltage ladder but this should still be more than enough resolution for what you need

both these will be needed, refer to manual 2 for more information on the comparator and its IVR
comparator setup
http://www.picaxe.com/BASIC-Commands/Advanced-PICAXE-Configuration/compsetup/
setintflags
http://www.picaxe.com/BASIC-Commands/Interrupts-and-Multi-Tasking/setintflags/
Thanks very much.

I will have a good read of the information and link you have provided.

Thanks again.
 

Andrei IRL

Senior Member
Think i figured out my last issue i was having with running a routine for a sertain length of time.

I just used
DO WHILE TIME<20
TIME=TIME+1
.....................
LOOP

command.
 

Dave Spider

New Member
Hello, I seem to think you are set on the use of a strain gauge ? I do not see any advantage to this approach to the end need. A simple two switch arrangement would be a more positive and fool proof method to sense shifter position. Another line to the Ignition switch to detect the start of the bike first time to "Calibrate" shift position being "First gear". You could even put a single digit to show the transmission gear position on the handle bar. This way you could count the transitions from first to third without a problem. Also, a motor bike is a very noisy electrical generator that would be hard to "Filter out" of a strain gauge electronics. Sometimes the best way is often times the easy one.
 

oracacle

Senior Member
the problem with the switches as far as I can see is that the have to e quite precisely adjusted, specially if it a close ratio box. the lever moves a matter of millimetres under that situation.
If the switches were easy and cheap then manufactures would use that route.
 

Andrei IRL

Senior Member
Switches are a definite no go unfortunately.

90% of all of the devices of this type are strain gauge now.

It is possible to make a "smart" learning device by using strain gauge.

I'll be working on this and see where it gets me.

Thanks very much for the input.
 
Top