TickTimerTime

  • 1
  • 2
  • Page 1 of 2
Mr Crusty
 
Avatar
 
Subject:

TickTimerTime

 · 
Posted: 12.12.2011 - 20:17  ·  #1
Hi,
Clarification needed with the Function TickTimerTime.
In the Standard Driver pdf. it says that the timer is stopped and new values are written to the prescaler and compare registers.
It appears that the timer restarts after exiting the procedure, is this correct?


Regards
Crusty.
rh
Administrator
Avatar
Gender:
Location: Germany
Age: 24
Homepage: e-lab.de
Posts: 5558
Registered: 03 / 2002
Subject:

Re: TickTimerTime

 · 
Posted: 12.12.2011 - 20:51  ·  #2
Hello Crusty,

after calling TickTimerTime the application should call TickTimerStart because the Timer Interrupt maybe disabled at this time. Of course, all internal Vars became reset.

rolf
Gunter
Administrator
Avatar
Gender:
Location: Frankfurt Main / Germany
Posts: 1697
Registered: 02 / 2003
Subject:

Re: TickTimerTime

 · 
Posted: 12.12.2011 - 20:59  ·  #3
Hi Crusty,

have a look to the demo!

...
// 10usec repeated interrupt
// toggles the enabled output pin with 10usec high / 10usec low
TickTimerTime(10); // writing a new value automatically stops the timer
TickTimerStart; // timer restart
...

Gunter
Mr Crusty
 
Avatar
 
Subject:

Re: TickTimerTime

 · 
Posted: 12.12.2011 - 21:28  ·  #4
Hi Rolf, Gunter,

Thanks for fast reply.
Can you advise why I have to put a TickTimerStop in the interrupt routine.
In the simulator, interrupt continues after a new time is set in interrupt with TickTimerTime.
Am I doing something stupid?

Regards
Crusty

program TTTest;

{$NOSHADOW}
{ $WG} {global Warnings off}

Device = mega328, VCC=5;
{ $BOOTRST $03800} {Reset Jump to $03800}

Define_Fuses
// Override_Fuses;
NoteBook = A;
COMport = USB;
LockBits0 = [];
FuseBits0 = [];
FuseBits1 = [];
FuseBits2 = [];

Import SysTick, TickTimer;

From System Import LongWord;


Define
ProcClock = 16000000; {Hertz}
SysTick = 10; {msec}
StackSize = $0064, iData;
FrameSize = $0064, iData;
TickTimer = Timer1;

Implementation

{$IDATA}

{--------------------------------------------------------------}
{ Type Declarations }

type


{--------------------------------------------------------------}
{ Const Declarations }

{--------------------------------------------------------------}
{ Var Declarations }
{$IDATA}


{--------------------------------------------------------------}
{ functions }

Interrupt TIMER1COMPA; // TickTimer
begin

TickTimerTime(30);
//TickTimerStop;
end;



{--------------------------------------------------------------}
{ Main Program }
{$IDATA}

begin

TickTimerTime(20);
TickTimerstart;
EnableInts;
loop


endloop;
end TTTest.
rh
Administrator
Avatar
Gender:
Location: Germany
Age: 24
Homepage: e-lab.de
Posts: 5558
Registered: 03 / 2002
Subject:

Re: TickTimerTime

 · 
Posted: 13.12.2011 - 00:11  ·  #5
Hello Crusty,

you manipulate the ticktimer driver in the ticktimer interrupt??!!
Very strange...

rolf
Merlin
Administrator
Avatar
Gender:
Age: 24
Posts: 1373
Registered: 03 / 2005
Subject:

Re: TickTimerTime

 · 
Posted: 13.12.2011 - 10:52  ·  #6
Hi Mr Crusty.

Here is my guess.

TickTimers generate interrupts and are stopped/started by a combination of interrupt flags and enable/disable interrupts. You need to be aware that entering an interrupt routine has an implied disabling of interrupts and exiting it (which generates a RETI rather than a RET) re-enables interrupts. I don't know the exact mechanism but I am guessing that the enabling of interrupts on exiting the procedure in this case restarts the timer countdown.

I would recommend that you use flags or pipes and manipulate the timer outside the interrupt.

Regards

Merlin
Mr Crusty
 
Avatar
 
Subject:

Re: TickTimerTime

 · 
Posted: 13.12.2011 - 21:02  ·  #7
Hi Merlin, Rolf and Gunter,

Thanks for all the feedback.
I agree that it's a bit odd to put the manipulation of TickTimer in the interrupt.
Especially as this takes some time to complete. No longer being used.

However I did some more tests and I still find that in the simulator TickTimer, if already started, does no stop and does not need a new implicit TickTimerStart after the use of TickTimerTime.

Not a problem as I am using a TickTimerStop where required.

I include the 3 bits of code that I have tried in the testing.

Again many thanks for the support of the team and other users

Regards
Crusty. :-)

program TTT_2;

{$NOSHADOW}
{ $WG} {global Warnings off}

Device = mega328p, VCC=5;
{ $BOOTRST $03800} {Reset Jump to $03800}

Define_Fuses
// Override_Fuses;
NoteBook = A;
COMport = USB;
LockBits0 = [];
FuseBits0 = [];
FuseBits1 = [];
FuseBits2 = [];

Import SysTick, TickTimer;

From System Import LongWord;


Define
ProcClock = 16000000; {Hertz}
SysTick = 10; {msec}
StackSize = $0064, iData;
FrameSize = $0064, iData;
TickTimer = Timer1;

Implementation

{$IDATA}

{--------------------------------------------------------------}
{ Type Declarations }

type


{--------------------------------------------------------------}
{ Const Declarations }

{--------------------------------------------------------------}
{ Var Declarations }
{$IDATA}
Var
Dummy, Flag : Boolean;

{--------------------------------------------------------------}
{ functions }

Interrupt TIMER1COMPA; // TickTimer
begin
Flag := True; //set breakpoint in simulator here
end;



{--------------------------------------------------------------}
{ Main Program }
{$IDATA}
{
begin
Dummy := False;
TickTimerTime(40); //TickTimer does not interrupt as never started
EnableInts;
loop
While Dummy = False Do
NOP;
EndWhile;
endloop;
end TTT_2.
}
{
begin
Dummy := False;
TickTimerTime(40);
TickTimerStart; //TickTimer Interrupts always as no stop
EnableInts;
loop
While Dummy = False Do
NOP;
EndWhile;
endloop;
end TTT_2.
}
begin
Dummy := False;
Flag := False;
TickTimerTime(40);
TickTimerStart;
EnableInts;
loop
While Dummy = False Do
If Flag = True then TickTimerTime(60); //TickTimer interrupts even after new value set.
Flag := False;
Endif;
EndWhile;
endloop;
end TTT_2.
rh
Administrator
Avatar
Gender:
Location: Germany
Age: 24
Homepage: e-lab.de
Posts: 5558
Registered: 03 / 2002
Subject:

Re: TickTimerTime

 · 
Posted: 14.12.2011 - 21:28  ·  #8
Hello Crusty,

I checked the driver and found out that the Timer Interrupt is not disabled with "TickTimerTime".
So calling this function the interrupt still fires without a "TickTimerStart". If this behaviour is not desired I can change it.

rolf
  • 1
  • 2
  • Page 1 of 2
Selected quotes for multi-quoting:   0

Registered users in this topic

Currently no registered users in this section

The statistic shows who was online during the last 5 minutes. Updated every 90 seconds.
MySQL Queries: 15 · Cache Hits: 14   133   147 · Page-Gen-Time: 0.021381s · Memory Usage: 2 MB · GZIP: on · Viewport: SMXL-HiDPI