Timer1 not running (on Mega 162) : solved

General discussion on mikroPascal PRO for AVR.
Post Reply
Author
Message
lemiceterrieux
Posts: 39
Joined: 12 Nov 2020 19:51

Timer1 not running (on Mega 162) : solved

#1 Post by lemiceterrieux » 13 Jan 2023 17:16

Hello ... This program should make Timer1 count at Fclk/1024 (in my case about 9KHz) and display the high byte on Leds connected to PortB (towards Vcc) and stop when the value is 251 ... but the display remains desperately "off".

program Timer;

{ Declarations section }

begin
{ Main program }
PortB := $FF;
DdrB := $FF;

TCCR1A := 0;
TCCR1B := 5; // Prescaler divide by 1024
SFIOR.7 := 0;
TCNT1H := 0;
TCNT1L := 0;
Repeat
PortB := TCNT1H Xor $FF;
Until (TCNT1H > 250);
Repeat Until False;
end.

And here comes the corrected version :

program Timer;

{ Declarations section }
Var Dummy1, Dummy2 :Byte;

begin
{ Main program }
PortB := $FF;
DdrB := $FF;

TCCR1A := 0;
TCCR1B := 5; // Prescaler divide by 1024
SFIOR.7 := 0;
TCNT1H := 0;
TCNT1L := 0;
Repeat
Dummy1 := TCNT1L;
Dummy2 := TCNT1H Xor $FF;
PortB := Dummy2;
Until (TCNT1H > 250);
Repeat Until False;
end.

Vicious, isn't it ? One MUST read the two registers of Timer1, otherwise it does not work ...
From France, SESSENHEIM

User avatar
Tanja_Kovacevic
mikroElektronika team
Posts: 98
Joined: 09 Aug 2021 11:39

Re: Timer1 not running (on Mega 162) : solved

#2 Post by Tanja_Kovacevic » 03 Feb 2023 11:17

Hi,

Very interesting.
Thank you for sharing the issue including your solution.

Kind regards,
Tanja

User avatar
Tanja_Kovacevic
mikroElektronika team
Posts: 98
Joined: 09 Aug 2021 11:39

Re: Timer1 not running (on Mega 162) : solved

#3 Post by Tanja_Kovacevic » 09 Feb 2023 11:18

Hi,

There is an explanation in the datasheet
in the section named "Accessing 16-bit Registers"
(on page 109 https://ww1.microchip.com/downloads/en/ ... asheet.pdf)


Kind regards,
Tanja

Post Reply

Return to “mikroPascal PRO for AVR General”