Timer works at double speed compared to what the calculator

Timer Calculator is a free software development tool used for easier calculation of timer interrupts.
Post Reply
Author
Message
Malmir
Posts: 23
Joined: 11 Jan 2016 23:00
Location: Copenhagen Denmark

Timer works at double speed compared to what the calculator

#1 Post by Malmir » 20 May 2018 15:02

Hi.
I like this timer calculator Tool, but not my chip :D. I have tried to do some clicks at 2.5 ms and 100 ms. Both are calculated in the calculator software. But when running in the chip I get clicks at 1.25 ms and 50 ms.
Any clues ??? I am so tired now, that i for sure might see the error, without knowing it :D.
Thanks in advance :D
BRGDs
Klavs.
Attachments
DDB_MKII.zip
(1.39 KiB) Downloaded 137 times

User avatar
marko.stankovic
mikroElektronika team
Posts: 108
Joined: 18 Dec 2017 15:44

Re: Timer works at double speed compared to what the calcula

#2 Post by marko.stankovic » 21 May 2018 11:36

Hi,

Can you tell me which microcontroller and the oscillator you use?

Best regards,
Marko Stankovic.

Malmir
Posts: 23
Joined: 11 Jan 2016 23:00
Location: Copenhagen Denmark

Re: Timer works at double speed compared to what the calcula

#3 Post by Malmir » 22 May 2018 09:49

Ups Sorry.
I use a STM32F103R8 with an external 8MHz crystal.

andreadipietro
Posts: 4
Joined: 21 Dec 2018 10:30

Re: Timer works at double speed compared to what the calcula

#4 Post by andreadipietro » 03 Jan 2019 20:41

Hello!, I have same problem! Any solution? LD1 on clicker 2 blink much speed than I predict.

//Timer0
//Prescaler 1:32; TMR0 Preload = 3036; Actual Interrupt Time : 1

//Place/Copy this part in declaration section
void InitTimer0(){
T0CON = 0x84;
TMR0H = 0x0B;
TMR0L = 0xDC;
GIE_bit = 1;
TMR0IE_bit = 1;
}

void Interrupt(){
if (TMR0IF_bit){
TMR0IF_bit = 0;
TMR0H = 0x0B;
TMR0L = 0xDC;
//Enter your code here
}
}

Thanks.

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: Timer works at double speed compared to what the calcula

#5 Post by stefan.filipovic » 04 Jan 2019 14:29

Hi,

I realized from this part of the code that you use Clicker 2 for PIC18, but I'm not sure whether it's for PIC18FK or PIC18FJ, I guess that's the Clicker 2 for PIC18FJ.
I tried this with the Clicker 2 for PIC18FJ in several ways, but unfortunately, I was not able to reproduce this issue successfully.
Could you please attach a minimal project which reproduces this issue?

Kind regards,
Stefan Filipović

andreadipietro
Posts: 4
Joined: 21 Dec 2018 10:30

Re: Timer works at double speed compared to what the calcula

#6 Post by andreadipietro » 04 Jan 2019 18:51

Thanks dear,

this is my project. And the proof of issue. :lol:
Attachments
These are my settings.
These are my settings.
screen.jpg (296.11 KiB) Viewed 5952 times
Video that show issue.
Video that show issue.
20190104_184818.gif (3.04 MiB) Viewed 5952 times
0-99 Counter.rar
Project.
(9.77 MiB) Downloaded 124 times

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: Timer works at double speed compared to what the calcula

#7 Post by stefan.filipovic » 08 Jan 2019 09:28

Hi,

I just tested your project on my Clicker 2 for PIC18FJ, and unfortunately, it works as it should work.
Can you tell me does the LD1 and LD2 blinking separately with the 1s delay after loading the hex file which I just attached?

Kind regards
Attachments
Test.zip
(928 Bytes) Downloaded 119 times
Stefan Filipović

andreadipietro
Posts: 4
Joined: 21 Dec 2018 10:30

Re: Timer works at double speed compared to what the calcula

#8 Post by andreadipietro » 08 Jan 2019 16:27

Here, the frequency..
Attachments
Oscilloscope
Oscilloscope
20190108_153403.jpg (3.02 MiB) Viewed 5929 times

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: Timer works at double speed compared to what the calcula

#9 Post by stefan.filipovic » 10 Jan 2019 09:46

Hi,

I just noticed that you are using the bootloader for programming.
In this case, if you use USB HID Bootloader you should use PLL in the config bits (on the top of the main function you also should put this code line PLLEN_bit = 1; ) and set MCU frequency to 48MHz, also you will need to generate Timer Interrupts for this MCU frequency.

Please find your modified project in the attachment.

Kind regards,
Attachments
0-99 Counter.zip
(9.97 MiB) Downloaded 121 times
Stefan Filipović

andreadipietro
Posts: 4
Joined: 21 Dec 2018 10:30

Re: Timer works at double speed compared to what the calcula

#10 Post by andreadipietro » 10 Jan 2019 17:14

Hi dear!

Finally, we are in the point! Now everything works! Thank you!

PLLEN_bit = 1; and Timer Calculator on 48Mhz.

This is an indirect way, but it works.

:D :D :D :D :D :D :D :D :D

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: Timer works at double speed compared to what the calcula

#11 Post by stefan.filipovic » 10 Jan 2019 17:42

Hi,

You're welcome.

I'm glad that we managed to solve this.

Kind regards,
Stefan Filipović

Post Reply

Return to “Timer Calculator”