View previous topic :: View next topic |
Author |
Message |
njepsen
Joined: 13 Aug 2007 Posts: 469
|
Posted: Thu Oct 19, 2017 11:25 pm Post subject: Problem with timer2 |
|
|
I seem to have a problem with timer2 (8 bit timer in Atmega1284). The following code only runs fine:
Code: |
'*******************************************************************************
$regfile = "m1284pdef.dat" 'my processor
$crystal = 9830400 'system crystal
$framesize = 800 ' Located at top of 16k of SRAM
$hwstack = 550 '
$swstack = 550
$frameprotect = 1
'timer 2 = 8 bit
Config Timer2 = timer,prescale =1024 'rolls over 9830400/(1024 x 256) = 37.5 times per sec '
On Timer2 Timer2overflow:
enable timer2
start timer2
do
print #1, "flag =";secflagb
loop
'******************
timer2overflow:
incr secflagb
return
'**************
|
But the following code only runs the int sub once. Maybe I'm misinterpreting the help about using a sub/end sub with 'on interrupt':
Code: |
'*******************************************************************************
$regfile = "m1284pdef.dat" 'my processor
$crystal = 9830400 'system crystal
$framesize = 800 ' Located at top of 16k of SRAM
$hwstack = 550 '
$swstack = 550
$frameprotect = 1
declare sub timer2overflow()
'timer 2 = 8 bit
Config Timer2 = timer,prescale =1024 'rolls over 9830400/(1024 x 256) = 37.5 times per sec '
On Timer2 gosub Timer2overflow()
enable timer2
start timer2
do
print #1, "flag =";secflagb
loop
'******************
sub timer2overflow()
incr secflagb
end sub
'**************
|
(BASCOM-AVR version : 2079 , Latest : 2.0.7.8 ) _________________ Neil |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2259
|
Posted: Fri Oct 20, 2017 1:22 am Post subject: Re: Problem with timer2 |
|
|
njepsen wrote: | Code: | On Timer2 gosub Timer2overflow() |
| Where did you read to use this 'gosub'? |
|
Back to top |
|
|
njepsen
Joined: 13 Aug 2007 Posts: 469
|
Posted: Fri Oct 20, 2017 1:50 am Post subject: |
|
|
I did say, I may be misreading the help. I infered from the implication given below in the help for ' on interrupt', and 'on
var', that gosub was needed. Clearly ( actually not so clear to me) it is not. Thanks for the confirmation as always Rudolf.
neil
Quote: |
Label
The label to jump to if the interrupt occurs.
When using a label, you need to use a RETURN to resume the main program.
The label may also be a sub routine. When using a sub routine, the sub routine needs to end with END SUB like any normal sub routine.
|
This from On Value.
Quote: |
Syntax
ON var [GOTO] [GOSUB] label1 [, label2 ] [,CHECK]
|
_________________ Neil |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2259
|
Posted: Fri Oct 20, 2017 2:11 am Post subject: |
|
|
Why do you quote 'On Value' at all, while you need to use 'On Interrupt'?
If you check about the correct command, there's no mention of goto or gosub and assuming parameters for one command would be valid for a completely different one, which only sounds a bit similar, is kinda odd.
There's a short sample in the help using syntax 'On Interrupt Sub', which should make usage clear. |
|
Back to top |
|
|
njepsen
Joined: 13 Aug 2007 Posts: 469
|
Posted: Fri Oct 20, 2017 3:33 am Post subject: |
|
|
For goodness sake Rudolf, you asked me " Where did you read to use this 'gosub'?", and I told you. The help on 'on interrupt' says "like any normal subroutine" so it should be understandable that the use of 'gosub' in the call might be implied here. Sorry - my mistake.
You obviously have a far better understanding of the Atmega devices and Bascom that most of us mere plebs, & I speak for myself when I say that we all value your expertise, but the aggressive manner of some of your replies sometimes prevents me from asking a question that you might find trivial, or stupid, and I quake in terror at the possible response from MWS; I do willingly concede however that you are always correct, factual and extremely helpful.
kind regards
neil _________________ Neil |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2259
|
Posted: Fri Oct 20, 2017 6:41 am Post subject: |
|
|
No need for sarcasm.
To misunderstand On Value for On Interrupt is simply nonsense and does not reflect your knowledge level.
We are in a very specific technical forum, where it's neither my duty nor interest to make you feel cozy.
Means I write the obvious and I do not wrap it in flower printed gift paper.
If that hurts your delicate self-esteem, do we have a problem then?
Why do you even bother about the sound of my answer?
You do not know me personally and never will, we don't have to be friends either.
Simply take information useful for you out of my reply and ignore what you don't like. |
|
Back to top |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1161 Location: France
|
Posted: Fri Oct 20, 2017 1:57 pm Post subject: |
|
|
on value gosub label0, label1, means
you make a jump to a label when value
gosub label0
---
---
label0:
print value
return
maybe you can use gosub to jump to a sub but, IMHO, it is not write in the help
remember the labels must be after the End
JP |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2259
|
Posted: Fri Oct 20, 2017 2:55 pm Post subject: |
|
|
Duval JP wrote: | on value gosub label0, label1, means
you make a jump to a label when value |
Most important keyword here is value, a variable, which makes this command an indexed goto/gosub, the index obviously needs to be variable at runtime, otherwise this command would make no sense.
On Interrupt Label however points from a constant address Interrupt within the interrupt vector table to an also fixed address Label within user-code area.
As all vector addresses and user-code is hard-coded at compile-time, respectively written into flash at program-time, they are obviously constants.
Thus one function excludes the other already by purpose and parameters, and (theoretically) can't be mistaken for the other.
Only because a taxidermist sounds a bit like taxman, they still do very different things. |
|
Back to top |
|
|
AdrianJ
Joined: 16 Jan 2006 Posts: 2483 Location: Queensland
|
Posted: Sat Oct 21, 2017 1:50 am Post subject: |
|
|
I think you are all missing the point here.
The On Interrupt command expects either a label to jump to, or an old style subroutine ( gosub ), which is only a label anyway, except its piece of code ends with a RET ( Return in Basic ). After the ON Interrupt, the compiler 'knows' that the code for that label is an interrupt, and therefore puts a RETI in the code, rather than a RET.
But the modern SUB construction is a different kettle of fish entirely, and accepts possible passed parameters by pushing them on the stack. For sure its target is still a label, but internally it accepts other stuff as well. In doing so, it ( probably ) makes no alllowance for a different return opcode, since it must also handle pulling possible parameters off the stack.
I guess there is no reason why it could not do this, but AFAIK at the moment it does not. Maybe since the use of GOSUB is almost entirely forgotten now, it would be worth cjhanging the compiler to do this. But there are still some restrictions, in that you cant pass parameters to an interrupt. Somene would be sure to try, and then wonder why they get nonsense, just like the OP used a SUB instead of a GOSUB and got something unexpected. These two things can be used interchangeably in main code, but not in an interrupt. _________________ Adrian Jansen
Computer language is a framework for creativity |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2259
|
Posted: Sat Oct 21, 2017 7:38 am Post subject: |
|
|
AdrianJ wrote: | I think you are all missing the point here. | Hear, hear.
The forum's members were waiting for someone to enlighten them.
Quote: | just like the OP used a SUB instead of a GOSUB and got something unexpected. | In case you missed the point: The OP got something unexpected not because he used the SUB()- instead of the Label-Style.
He got it because he misused the declaration 'On Interrupt' and added a 'gosub', where none belongs.
It is not about 'new' Sub-Style, as if this would be the culprit, it would be actually a bug.
Next time the OP will add a 'goto' to the 'On Interrupt' declaration. Where will the uC jump to after finished ISR then?
Quote: | Maybe since the use of GOSUB is almost entirely forgotten now, it would be worth cjhanging the compiler to do | It would be nonsense to discuss about changing the compiler's syntax acceptance to create a cure for a sickness that does not exist, as:
Quote: | Somene would be sure to try, and then wonder why they get nonsense... | Sure, tomorrow someone will try to feed the Bascom-compiler with lorem ipsum text and wonders it won't compile. So what? |
|
Back to top |
|
|
hgrueneis
Joined: 04 Apr 2009 Posts: 902 Location: A-4786 Brunnenthal
|
Posted: Sat Oct 21, 2017 5:24 pm Post subject: |
|
|
'ON INTERRUPT'
is explained in detail in the HELP (with examples).
I really do not understand the commotion here.
Just read the manual.
Regards
Hubert |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5905 Location: Holland
|
Posted: Sun Oct 22, 2017 8:06 pm Post subject: |
|
|
I had a look at the help and i can understand the confusion. I added this to make it more clear :
[PICTURE notice.jpg]Unlike the ON VALUE statement, the ON INTERRUPT does not accept GOTO or GOSUB. The GOSUB/GOSUB tells the compiler that ON VALUE is used rather than ON INTERRUPT. Since interrupt sources are constants with an address, the compiler is happy to accept ON INT0 GOSUB which will do something entirely different than you expect. _________________ Mark |
|
Back to top |
|
|
AdrianJ
Joined: 16 Jan 2006 Posts: 2483 Location: Queensland
|
Posted: Mon Oct 23, 2017 1:14 am Post subject: |
|
|
Aha ! I see. I must admit I have not read the Help on this for a long time.
The ON (VALUE) GOTO/GOSUB construction is not an interrupt at all, its what was called a computed GOTO in old Basic.
And the ON (INTERRUPT) can use a SUB...END SUB label as well as the old GOSUB type subroutine label. Thats useful to know.
But its easy to get these two mixed up, thanks for clearing that up Mark. _________________ Adrian Jansen
Computer language is a framework for creativity |
|
Back to top |
|
|
|