interrupt problems!

sub-bg

New Member
I have written a program to control the servos of my device ,while a digital compass reads the direction and shows south.
The compass is working fine up until the point I jump to the interrupt to control the servos.The compass completely freezes .

My code is

--------------------------------------------------------------------------'+++++++++++++++++++++


SYMBOL TX_PIN = 0
'SYMBOL RX_PIN =
SYMBOL NORTH = pin7
SYMBOL EAST = pin6
SYMBOL SOUTH = pin5
SYMBOL WEST = pin4
SYMBOL Movs = B1 ' Declaring all Constants and Variables

dirsc = %00001110 ' Configuring Pins


init:
setint %00000001,%00000001 ' Defining Which Pin and State of Pin for Interrupt

main:

if North=0 and South=1 and East=1 and West=1 then label_18 ' North

if North=0 and South=1 and East=0 and West=1 then label_17 ' North East

if North=1 and South=1 and East=0 and West=1 then label_16 ' East

if North=1 and South=0 and East=0 and West=1 then label_15 ' South East

if North=1 and South=0 and East=1 and West=1 then label_14 ' South

if North=1 and South=0 and East=1 and West=0 then label_13 ' South West

if North=1 and South=1 and East=1 and West=0 then label_12 ' West

if North=0 and South=1 and East=1 and West=0 then label_11 ' North West

goto main ; *****

label_11:
low portc 1
low portc 2
low portc 3
low 3
low 2
low 1
low 0
high 4
serout 5,N2400,("2")
pause 500

goto main

label_12:
low portc 1
low portc 2
low portc 3
low 4'let pins = %01000 'Turns LED2 on
low 2
low 1
low 0
high 3
serout 5,N2400,("3")
pause 500


goto main

label_13:
low portc 1
low portc 2
low portc 3
low 4'let pins = %00100 'Turns LED3 on
low 3
low 1
low 0
high 2
serout 5,N2400,("4")
pause 500

goto main

label_14:
low portc 1
low portc 2
low portc 3
low 4
low 3
low 2
low 1
low 0
high 1
serout 5,N2400,("5")
pause 500


goto main

label_15:
low portc 1
low portc 2
low portc 3
low 4
low 3
low 2
low 1
high 0
serout 5,N2400,("6")
pause 500

goto main

label_16:
low portc 1
low portc 2
low 4
low 3
low 2
low 1
low 0
high portc 1 'Turns LED6 on
serout 5,N2400,("7")
pause 500

goto main

label_17:
low portc 1
low portc 3
low 4
low 3
low 2
low 1
low 0
high portc 2 'Turns LED7 on
serout 5,N2400,("8")
pause 500
goto main

label_18:
low portc 2
low portc 3
low 4
low 3
low 2
low 1
low 0
high portc 3 ' Turns LED8 on
serout 5,N2400,("1")
pause 500
goto main

Interrupt:
SERIN 0,N2400,b1
moving:

servopos 6,147 ‘ move servo to one end
servopos 7,150 ‘ move servo to one end
pause 2000 ‘ wait 2 seconds

select case Movs

case = 111 'Moving Forward
servopos 6,149 'move servo to one end
servopos 7,151 'move servo to one end
pause 2000 'wait 2 second

case = 110 'Moving Left
servopos 6,149 ‘ move servo to one end
servopos 7,149 ‘ move servo to one end

case = 101 'Moving Right
servopos 6,151 ‘ move servo to one end
servopos 7,151 ‘ move servo to one end

case = 100 'Moving Back
servopos 6,151 ‘ move servo to one end
servopos 7,149 ‘ move servo to one end

end select

let Movs=0
Do
Loop Until Pin0 = 0
setint %00000001,%00000001 ' Defining Which Pin and State of Pin for Interrupt

RETURN





-----------------------------------------------------------------------


I want the compass to carry on functioning whilst i just to the interrupt

who do I achieve this??

This is really urgent . I have to submit my project in 2hour:confused::eek:

Thank you:)
 

westaust55

Moderator
Sub-bg,

1. As I have stated in one of your earlier posts about the same program

You do NOT need to start a new thread for the same topic,


2. You are not reading the information given to you in the previuos thread.
Please read this post (again):
http://www.picaxeforum.co.uk/showthread.php?p=94320

or are you hoping someone will give you fully functioning code rather than examples?



3. your interrupt code may be easier to read/understand if you replacw variable b1 with its alias

Code:
Interrupt:
SERIN 0,N2400, [B][COLOR="Red"]Movs[/COLOR][/B]
moving:

4. Finally, please enclose your program code in [code] and [/code] markers
please read: http://www.picaxeforum.co.uk/showthread.php?t=7679
 
Last edited:

hippy

Ex-Staff (retired)
Have you tried adding SERTXD commands in the code to trace where it is going, where it is getting to and where not ? That way you can find where it is going to and where it is getting stuck, from that you have the reason it's stuck then you can investigate why.

My first instincts are SERIN is hanging, not receiving any data, b1 gets a value through SERIN which doesn't match what the SELECT-CASE options are so whatever is meant to be happening doesn't, or it reaches the "Do:Loop Until Pin0 = 0" but pin0 is never zero.

Unfortunately debugging other people's code just by looking at it takes time, especially where how it works and what it is meant to do and how isn't described. You have a 'digital compass' reading something, but it's not clear what that is, what it's reading, nor what the servos are doing or why.

That information may not be necessary, but some indication of what does work, where the code is getting stuck, will help people make educated guesses as what is going wrong. Don't forget that you have a more detailed understanding of your project than anyone else has and what is "obvious" to you can be a mystery to others.

Pragmatically you have to accept that this issue may not get resolved before the deadline, so make sure you have everything else sorted out as best you can to secure some positive outcome even if it is not working. It may be better to spend some time documenting why it doesn't work and the steps needed to fix it than try and fix it in a tight schedule and under pressure. If the project was over-ambitious or just too complicated to get working and debugged in the timeframe saying so may help mitigate it not working.
 

westaust55

Moderator
compass and interrupt problems

You have a 'digital compass' reading something, but it's not clear what that is, what it's reading, nor what the servos are doing or why.
The compass has 4 digital outputs via open collector outputs.
These are connected to inputs 4 to 7.

I enquired if sub-bg has pull up resistors but no response. Seems the compass side may be working and interrupts is the key problem.
 

hippy

Ex-Staff (retired)
The compass has 4 digital outputs ... Seems the compass side may be working and interrupts is the key problem.
Aha! The fog is clearing, thanks.

The compass is an output device feeding into the PICAXE. One half ( non-interrupt part ) of the code reads that compass sets various I/O high, low, sends SEROUT data, loops forever. The interrupt part SERIN's from a PC and adjusts some servos, exits. The closed-loop parts of the system are irrelevant in terms of the raw processing done.

So, by 'compass freezing' it's likely to mean the code reading the compass not being executed so not doing anything rather than the compass itself freezing, and that is symptomatic of entering the interrupt and never returning.

SERTXD within the interrupt to determine where the code gets to would be my approach to debugging as suggested earlier. Though given the interrupt is from pin0, the same pin SERIN reads, I suspect it is the earlier advice which hasn't yet been taken on board about not being able to receive SERIN data via interrupt in the way it still seems to be being used in this version of the code.
 
Last edited:
Top