Touch sensor and interrupt with a picaxe 08M2

nanogear

Member
Hello and thank you in advance...

Well, I have a code that activate and deactivate two relays. This code is a state machine running depending on the values of a certain sensor. All automatically without human intervention.

I am trying to use a touch sensor that, when pressed and released, interrupts the code and execute a subrutine to turn off the relays and then do nothing, just wait until the same touch sensor is pressed and released again to resume the execution of the code.

To simplify the explanation we can imagine that the code just turn on and off the pin B.2 of the picaxe.

I have something like this but my code is a mess and I know there is a very simple way to achieve this but I can't find a simply logic :(

Code:
setint %00001000,%00001000,C                 ; interrupt when pinC.3 goes high
symbol TOUCHCONFIG = %00001001              

main:	
        high B.2
        pause 1000
        low B.2
      touch16 [TOUCHCONFIG], C.4,w0		   ; read value into w0
	   if w0 > 3600 then 
	      high C.3
	      else
	      low C.3
	   endif
	   goto main
	

     
interrupt:	
            pause 500
            high B.2			      
            pause 1000
            low B.2
		if pinC.3 = 1 then interrupt	   ; loop here until the interrupt cleared
		pause 1000 			         
		setint %00001000,%00001000,C	   ; re-activate interrupt
		return
Please help me with ideas or examples. I am learning a lot and I am very happy to use this picaxe microprocessors.


Thank you so much,


Nanogear
 
Last edited:

techElder

Well-known member
Nanogear, you don't have to use the optional "[TOUCHCONFIG]". Change the configuration if the default settings won't work for you.

You didn't say what problem you are experiencing, if any.

Remember that your touch sensor hardware has to be electrically isolated from your finger. Don't touch the sensor directly.

Your code looks minimal as it is.

Confusing, but if you add the "touch" section of code to your state machine code you are already "interrupting" your code so why add the interrupt code?
 
Last edited:

nanogear

Member
Nanogear, you don't have to use the optional "[TOUCHCONFIG]". Change the configuration if the default settings won't work for you.

You didn't say what problem you are experiencing, if any.

Confusing, but if you add the "touch" section of code to your state machine code you are already "interrupting" your code so why add the interrupt code?
Thank you Texasclodhopper,

The touch sensor is isolated and works great.

Then, the touch section of code is like an interrupt? working in parallel?

My problem is that I just need a simple way to interrupt the execution of the principal code and then execute a loop subrutine when touch sensor pressed and released. But I think there is another way easier than my logic. My logic say that when a touch sensor is pressed and released then I need to put high an output so in that way "setint" can be executed with the interrupt subrutine...

Just need a better way(ideas) to achieve this


Thank you a lot!!!
 

techElder

Well-known member
"... My logic say that when a touch sensor is pressed and released then I need to put high an output so in that way "setint" can be executed with the interrupt subrutine...
..."​

My point to you is that if you put the touch sensor statement in the middle of your principle code, then you've already "interrupted" your principle code! No need for the "setint" routine at all.

Just debounce the touch routine and go do whatever you want.
 

nanogear

Member
"... My logic say that when a touch sensor is pressed and released then I need to put high an output so in that way "setint" can be executed with the interrupt subrutine...
..."​

My point to you is that if you put the touch sensor statement in the middle of your principle code, then you've already "interrupted" your principle code! No need for the "setint" routine at all.

Just debounce the touch routine and go do whatever you want.
Thanks, That is what now I am doing. Not using setint.

code:
Code:
symbol TOUCHCONFIG = %00001001

main:	
        touch16 [TOUCHCONFIG], C.4,w0	
	if w0 > 3600 then 
	   goto subrutine		                  
	   else 
	   goto main 
	endif
	return
	
subrutine: 
           low B.2
           pause 2000
           high B.2 , B.0
           time = 0
           do
               touch16 [TOUCHCONFIG], C.4,w0	
	         if w0 > 3600 then 
           loop
           end if
           goto main
How can I do the following: if I push for 2 seconds and release the touch sensor, then the picaxe enter to a loop. If I push again for 2 seconds and release the touch sensor, then exit the loop.

Thank you in advance
 
Top