Interrupt not interrupting.

#1
Hello all,

I'm hoping for some assistance in solving a problem that I suspect has become my not being able to see the wood for the trees. The example attached is the simplest that I have been able to reduce the problem to, while still keeping the functionality I need and the problem visible.

The purpose of the exercise is to arbitrate a bus to determine which of M PICAXEs is permitted to transmit over a serial bus. I have only one wire available, so the idea is that any chip wanting to transmit must first activate this signal with a pulse (a so-called primer pulse) that is unique in length to itself. All chips measure the length of the pulse. I needn't go any further with the description because not even this first bit is working!

Please load and run the attachments. U1 is the transmitter and U2 the receiver. U3 is used purely to trigger U1, which correctly pulls the arbitration signal, FRED_ENG, active and then enters state FSM_StopPrimer. U2 responds to the change in FRED_ENG and enters state FSM_MeasPrimer. So far, so good. At the end of the primer pulse, U1 releases FRED_ENG and enters state FSM_Relax, which is also correct and, in fact, U1 will continue to behave correctly. The problem, however, is with U2, which does not respond to FRED_ENG being released at the end of the primer pulse. This I do not understand at all. The B.7 ports are hard wired together, the pull ups are activated (there are external pull ups anyway), the interrupts on both U1 and U2 are set up identically (SETINT 0x80, 0x80, B), and the signal at B.7 goes to logic 1 for more than 10 ms, surely an aeon in terms of triggering an interrupt. U1 does respond, but U2, apparently set up identically, doesn't. Can anyone see why?

I've tried applying a pulse from an external source directly to FRED_ENG and this does trigger the interrupt.

I'm fairly new to PICAXEs and am still groping around a bit when it comes to coding. If anyone has any constructive comments on how I might do things better then they'd be much appreciated.

Roger.


View attachment InterruptTest.DSN
View attachment InterruptTest28X2.bas
 

hippy

Technical Support
Staff member
#3
Your code is far too complicated for anyone to quickly get to grips with it and figure out what it should be doing, or is doing, let alone determine why it is not working as desired.

You really need simple programs with the fewest lines of code to demonstrate what the apparent flaw is.
 
#4
It's taken me several hours to get it down to this. I have tried to simplify it further but then I lose both the problem and the functionality I need. I'll try again.
 

hippy

Technical Support
Staff member
#5
You need to forget functionality for now. You need to be able to identify exactly what the problem is and create code which demonstrates the failing.

Once that is done, the issue can be resolved and then functionality can be added.

The best approach is often to go back to the most basic code. In this case determining if you can have the two recognise and acknowledge the signalling and handshaking. If so then incrementally build on that in small amounts.

If it all keeps working then well and good. Otherwise there should come a point where what was working stops working. At that point analysing what the change is which stops it working may reveal what the problem is.
 
#6
By getting rid of the functionality completely, it turns out that the problem can be exposed very simply. In fact, it's now so simple that either I'm doing something fundamentally I shouldn't be doing or there's a bug. I've modified the schematic a little and the code a lot. Both chips run the same code. The results are consistent. When B.7 is set to an input and the line is pulled high, the transmitter (U1 as the code is written) interrupts correctly, the receiver (U2) doesn't. By varying the length of the PAUSE at line 28, you can see very easily (set the oscilloscope at time zero with a one-shot trigger) that this pause has to expire before the interrupt is handled.

The roles of U1 and U2 can be swapped by changing lines 13 and 23 to: IF pinA.0 = 1 THEN. Now U2 (this time, the transmitter) interrupts correctly and U1 (the receiver) doesn't.

View attachment InterruptTest.bas
View attachment InterruptTest.DSN
 
Top