Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 03:51 07 May 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Interrupt Issue

Author Message
jman

Guru

Joined: 12/06/2011
Location: New Zealand
Posts: 711
Posted: 08:04pm 05 Feb 2016
Copy link to clipboard 
Print this post

Hi
Please take a look at the code below the issue
is that when the SetTick command is run from an interrupt
it does not work. If I run the settick command directly or before
an interrupt it works as expected.
What am I missing or is there a bug in the firmware

This is with a 44Pin MX170 MM v5.1


SetPin 8, Din
SetPin 9, Din


Main:
If Pin(8) = 0 Then GoTo TickTest
If Pin(9) = 0 Then GoTo ITest
GoTo Main

ITest:
Temp=0:Print "Interupt Loop"
SetPin 36, IntL, TickTest

Do
Loop
End

TickTest:
Temp=0:Print "Got Here"
SetPin 36, Off

SetTick 300, OutInt, 2 'This does NOT run from Interrupt

Do While Temp < 10
Print Temp
Loop

SetTick 0, 0, 2

End

'==============================================
OutInt:
If OutC = 1 Then
OutC=0 : IReturn
EndIf
OutC=1 : Temp=Temp+1
IReturn

'==============================================


Many Thanks
Jman
 
PicFan
Senior Member

Joined: 18/03/2014
Location: Austria
Posts: 133
Posted: 12:08am 06 Feb 2016
Copy link to clipboard 
Print this post

I think that is a problem with the Interrupt priority, the SETTICK have the lowest priority ?

Also i think it is not good a "do while" loop in a Interruptroutine ?
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3668
Posted: 01:20am 06 Feb 2016
Copy link to clipboard 
Print this post

I hope that's deliberately contrived (and horrid) code.

You want to keep any interrupt short. Preferably no PRINTs, too.

If you turn it into a more sane sample - which may be longer - does it then work?
If not, post it.

Yo might like to avoid IReturn and use a SUB in every case. Right now you even have TickTest apparently for an interrupt but no IReturn. It's not going to end well!!

JohnEdited by JohnS 2016-02-07
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 02:47am 06 Feb 2016
Copy link to clipboard 
Print this post

There is nothing in the SETTICK command that would stop it from running correctly from within an interrupt. It just sets up the relevant registers and exits.

I suspect that it is something within your code.

EDIT: I think that I can see the problem. You run SETTICK from within an interrupt and your code will only exit this interrupt when the SETTICK interrupt has been called 10 times. But MMBasic will not service the SETTICK interrupt because it is already within an interrupt - you will never receive an interrupt within an interrupt.

GeoffEdited by Geoffg 2016-02-07
Geoff Graham - http://geoffg.net
 
jman

Guru

Joined: 12/06/2011
Location: New Zealand
Posts: 711
Posted: 10:46am 06 Feb 2016
Copy link to clipboard 
Print this post

Hi
Ok so JohnS did not like the test code yes it was just test code.
Please see below and hopefully this is a better explanation
It seems that the SetTick command does not start until after
the interrupt routine has exited.

The code below uses SetTick then a pause at the start to prove
SetTick works during a pause

With the Interrupt routine the SetTick only starts after the pause
(ie the IReturn)

Hopefully this explains it a bit better

Regards
Jman

SetTick 500, OutInt, 2
Pause 5000
Print "Pause end"
SetTick 0, 0, 2

SetPin 8, Din
SetPin 36, INTL, ITest

Main:
If Pin(8) = 0 Then GoSub TickTest
GoTo Main

TickTest:
Print "Got Here from Button 1"
SetTick 500, OutInt, 2
Pause 5000
Return


ITest:
Print "Got Here from Interrupt"
SetPin 36, Off
SetTick 500, OutInt, 2

Pause 5000

IReturn


'==============================================
Sub OutInt
Print "Got here OutInt "
End Sub
'==============================================

 
BobD

Guru

Joined: 07/12/2011
Location: Australia
Posts: 935
Posted: 11:44am 06 Feb 2016
Copy link to clipboard 
Print this post

jman
If I recall correctly, somewhere in the older manuals and maybe in the more recent ones, there used to be a listing of interrupt priorities. Also noted was that lower priority interrupts were masked off while a higher (or any?) interrupt was in progress. Also mentioned was that interrupts are not hardware but software and are processed at the end of the current instruction unless masked.

If I'm correct, would that make sense of your problem? It's too early in the morning for me to try analysis on it and we won at cricket and we didn't even have to bowl underarm.
Bob
 
jman

Guru

Joined: 12/06/2011
Location: New Zealand
Posts: 711
Posted: 12:08pm 06 Feb 2016
Copy link to clipboard 
Print this post

  BobD said   jman
If I recall correctly, somewhere in the older manuals and maybe in the more recent ones, there used to be a listing of interrupt priorities. Also noted was that lower priority interrupts were masked off while a higher (or any?) interrupt was in progress. Also mentioned was that interrupts are not hardware but software and are processed at the end of the current instruction unless masked.

If I'm correct, would that make sense of your problem? It's too early in the morning for me to try analysis on it and we won at cricket and we didn't even have to bowl underarm.
Bob


So right you are from the manual page 40

"During the processing of an interrupt all other interrupts are disabled until the interrupt subroutine returns."

Great so now I know
Thanks for the help

Regards
Jman
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024