Interrupt pin 5 08M2

bag57pipe

New Member
I have searched the forum and not found any mention of using Pin C.5 on an 08M2 for an interrupt, it's probably a rather dubious practice but possibly handy when all else fails. It occurred to me that providing pin C.5 on the 08M2 is kept low during power up the pin may be useable for an interrupt IF, and I mean IF the editor can be conned into accepting. Set int %00100000,%00100000 will cause a syntax error as to be expected however setint %00100000,Var does not the code below illustrates my point.
Code:
#no_data
Setfreq m4
#terminal 4800

                Disconnect'........................!!! USE HARD RESET!!! normal download disabled

                Sertxd ("STARTING PROGRAM",cr,lf)'.This should only execute once
               
                B0=32'.............................Use pin C.5 as an interrupt
                setint %00100000,B0'...............Interupt on pin C.5 IF pin 5 held highB0
                pause 3000'........................Keep things a readable speed          
Start:          
            Do  
                    'Youre program goes here
                    Sertxd ("Looping waiting for interrupt",cr,lf)
                    pause 500
            Loop  



Interrupt:
            Do
                    Sertxd ("Interrupt detected",cr,lf)  
               
                    Pause 500  
                        B1=PinsC AND %00100000'....Read pin 5 is it still high
                        If B1 =0 then Rdo_int'.....B0=0 interrupt cleared jump out of loop
            Loop
Rdo_int:                Sertxd ("Interrupt reset",cr,lf)
   
                    setint %00100000,B0
                   
        Return
 

Flenser

Senior Member
The web version of the manuals are sometimes more up-to-date than the pdf versions.

The web version of the manual for setint has this extra info for the 08M2: "08M2 only inputs C.1 to C.4 may be used"
 

bag57pipe

New Member
Hi
The manual is pretty comprehensive, however considering it is an educational resource it would be unwise to list any quirks (and there are a few) that may cause problems for students. A high going interrupt on pin 5 seems to work, it is as I already said of limited use and a bit dubious. At first I thought I was just causing a reset but the code above seems to disprove that as once it is running following an interrupt as it does not pass start again.
I used this as well as enabling the pin 5 weak pullup in the code in my previous post (a bit of a rat's nest I' afraid) as a last resort. I'm posting in the sand box at the moment because I have not yet got the hang of using the forum
 

AllyCat

Senior Member
Hi,

That's very interesting and definitely IS useful. I've been considering an "update" to my "Using HSERIN with an 08M2" thread, the problems of which have now been largely "Solved" (eventually in a more recent thread, post #22). But there was still the "annoyance" that a second pin was needed for the interrupt input (mentioned in paragraph 5 of post #1 in my original thread).

So, I've revised your code to be a little more "User Friendly", with fewer "magic numbers" and to operate "automatically". It works with both positive and negative-going interrupts, but it might need the "22k" programming resistor to be increased (much higher values are acceptable) so that the Weak Pullup resistor can always generate the interrupts.

Code:
#picaxe 08m2
#no_data
#terminal 4800

Symbol Leg2 = S_W6						; Use a variable that won't conflict with a "normal" Program
	Leg2 = 32							; Use pin C.5 for interrupt input
	Disconnect							; May need a HARD RESET !!! normal download disabled
	Sertxd ("STARTING",cr,lf)			  	        ; This should only execute once
	Setint Leg2,Leg2 						; Interrupt on pin C.5 IF pin 5 held high
	Pause 1000							; Keep things at a readable speed          
Main:          
	Do  									; Program can go here
		Sertxd ("Waiting, time= ",#time,cr,lf)
		Pause 1000
		If pinsC => Leg2 then
			Pullup OFF
		Else
			Pullup Leg2
		Endif
	Loop until time > 10
	Reconnect
	Sertxd("READY")
	Stop
Interrupt:
	Sertxd ("Interrupted",cr,lf)  
	Pause 500  
	b1 = PinsC AND Leg2					; Read pin 5
	If b1 > 0 then
		Pullup OFF
		Setint Leg2,Leg2
	Else
		Pullup Leg2
		Setint Leg2,0
	Endif
	Sertxd ("Interrupt done",cr,lf)
	Return
Note that this "trick" is probably limited to the 08M2 because the PE uses PortB and PortC names interchangeably for the 08M2. PICaxe (M2) Interrupts are only available on Port C, and also the "internal" ports of the "base PIC" chips of the 14 and 20M2s refer to (some) different pins compared with the PICaxe names and pin numbers.

Cheers, Alan.
 
Last edited:

bag57pipe

New Member
Looking at allycats revision to my code I obviously have a lot to learn, the work moving hserein to c.5 is very interesting. With the wide range picaxe of chips and their varying architectures it is unlikely that messing with the internals will have the same or any effect on different chips. I can't really claim credit for the interrupt idea, some of the other members of the forum had pointed out that the editor does not check every detail and that using a variable instead of a literal is enough to avoid a syntax error for some illegal commands, BUT no guarantees the dodge will work. My motivation for trying a C.5 interrupt was I needed to poll the pin without slowing down an already very slow program and still keep the pin as a serial input. I spend a lot of time trying to get the 08M2 to do more than it should, a waste of time perhaps, but then again so are crosswords, my idea of heaven would be a ten pin picaxe.
 

Flenser

Senior Member
FYI. This link to a thread from 2009 where Dave E cut the last 6 pins of a 14X2 chip to get X2 features in an 8-pin chip: 14X2
 

inglewoodpete

Senior Member
I think InglewoodPete did that some 10-12 years ago, cutting off the bottom pins on a 14-pin chip. Worked, as I recall. Literally a hack.
Actually not a hack. I mounted an SMD 20X2 on a small PCB, with a 14 pin DIP socket on the other side. The 20 pin SMD is about the same physical size is a 14 pin DIP. I did it when the only option in 14 pins was the 14M, which had quite limited code space. Nowadays, I'd use a 14M2 but a 20X2 is much more powerful than a 14M2.
 

bag57pipe

New Member
I don't think I'm ready to attack with the hacksaw yet, Inglewood Pete probably has the best idea, sometimes a lowish pin count is all you need but the increased performance you get with some of of the bigger chips is handy. Dare I mention micromite do a MX170 32 bit 28 pin down to 8 pin, Dil, I was wondering if it would make a good maths co-processor, it is programmed in basic and handles maths with about as much precision as you are likely to need but I don't think it's quite as forgiving as picaxe basic.
 

inglewoodpete

Senior Member
I use both brands of chip. I prefer the PICAXE because it is simpler to use. However, the PICAXE's speed and integer-only maths can occasionally be a limitation but there are many ways to work around this. A carefully coded PICAXE is a very capable little beast.
 

bag57pipe

New Member
I started using basic with a Tandy TRS80 and lost interest when the dark prince of Microsoft and IBM gave us the PC . After a very long break started with picaxe around 2003, it was an uphill struggle at first then I realised I was trying too hard! I think basic in general and picaxe in particular are underated because simple is assumed to mean inferior.
I have dabbled with assembler, Great cow basic, Proton basic and Arduino they all have a steep learning curve compared to picaxe and required more investment in time and effort than the project could justify. Considering picaxe was intended as an educational tool I find its versatility is quite amazing, that said how about an 08M3 with 32 bit math and a 12bit ADC wow!
 
Top