TMR0 rollover value property missing

Use this section to discuss your embedded Flowcode projects.
Post Reply
KikeRico
Posts: 21
http://meble-kuchenne.info.pl
Joined: Wed Aug 10, 2022 1:42 am
Location: Mexico
Has thanked: 2 times
Been thanked: 7 times

TMR0 rollover value property missing

Post by KikeRico »

Dear FC9 team,

I'm testing interrupts with TMR1 in target PIC18F2331, and I found that in property window there isn't the rollover value to adjust the interrupt frequency. :o
Rollover value missing.PNG
Rollover value missing.PNG (18.07 KiB) Viewed 2374 times
But in the same window, for the TMR2 the rollover value is present. :shock:
Rollover value TMR2.PNG
Rollover value TMR2.PNG (17.19 KiB) Viewed 2374 times
What is the difference for this? Don't be supposed that for all Timers would be a rollover value to be adjusted by the user selection?

By the way, the TMR0 has the same missing rollover value issue.

Thanks for comment.

Best regards,
KikeRico

Steve-Matrix
Matrix Staff
Posts: 1253
Joined: Sat Dec 05, 2020 10:32 am
Has thanked: 167 times
Been thanked: 277 times

Re: TMR0 rollover value property missing

Post by Steve-Matrix »

Reading the datasheet, it looks like this device has a "period register" only on Timers 2 and 5, and this is used by the rollover value to adjust the interrupt frequency. Timers 0 and 1 do not have this feature.

KikeRico
Posts: 21
Joined: Wed Aug 10, 2022 1:42 am
Location: Mexico
Has thanked: 2 times
Been thanked: 7 times

Re: TMR0 rollover value property missing

Post by KikeRico »

Hi Steve,

I have looked in datasheet, and for TMR0 it have period registers of 8-bit or 16-bit,
TMR0 resgisters.PNG
TMR0 resgisters.PNG (63.33 KiB) Viewed 2337 times
And for TMR0 interrupt, it occurre when register roll-over from FF to 00 (8-bit mode) or from FFFF to 0000 (16-bit mode)
TMR0 interrupt.PNG
TMR0 interrupt.PNG (40.16 KiB) Viewed 2337 times
For TMR1 is almost the same.
TMR1 interrupt.PNG
TMR1 interrupt.PNG (29.08 KiB) Viewed 2337 times
Maybe the period registers for TMR0, TMR1 were not considered in FC interreuption window porting.

Do you think is possible to implement the roll-over (overflow) for TMR0, TMR1 in a C code module to adjust the interrupt frequency? :idea:

Best regards,
KikeRico

User avatar
p.erasmus
Valued Contributor
Posts: 434
Joined: Thu Dec 03, 2020 12:01 pm
Location: Russia / Россия
Has thanked: 104 times
Been thanked: 88 times

Re: TMR0 rollover value property missing

Post by p.erasmus »

Hi

If you need any other intterrupt time as given by the properties of the Interrupt Component you need to use the custom option and add C code to configure the Timer and set the Rollover yourself . If you select the Question mark in the property window the wiki will give you a full explenation of how the Interrupt Component functions,

here is the wiki for PIC Custom interrupts with and example for Timers

https://www.flowcode.co.uk/wiki/index.p ... -_PICmicro


P3.JPG
P3.JPG (33.42 KiB) Viewed 2328 times

In the standard properties of the Interrupt the component use the full range of the Timer Register that means it starts to count from zero(0) and at 65535 it rolls over and the Interrupt is triggered ,the time is based on your Clock frequency and the Timer pre-scaler value( it shows you the interrupt frequency) in the example below the clock is 19660800 and the pre-scaler is 16 now the Time = 1/frequency = 1/12000 = 83mSec. now if you change the prescaler the Interrupt frequency will change .example prescaler 64 then the Frequency is 300 again 1/300 = 333 mSec


P2.JPG
P2.JPG (31.06 KiB) Viewed 2328 times

Again if you would like to have a custom Timer Interrupt value (Time) then you need to select your own presaler value and set the Timer register at a preploaded value to achieve your required Time

Hope this clear your confusion with the Rollover value whih is essential the Timer register value as for PIC mcu's the Interrupt is fired or the Timer Roll over when the Timer Register reach the maximum value 256 for 8 bit and 65535 for 16 bit Timer modes

Note check your device datasheet as the newer pics had some register bit and names changed in order to specify the correct bits the example is based on the older PIC's be carefull with the names :D



P4.JPG
P4.JPG (50.16 KiB) Viewed 2328 times
Regards Peter - QME Electronics

KikeRico
Posts: 21
Joined: Wed Aug 10, 2022 1:42 am
Location: Mexico
Has thanked: 2 times
Been thanked: 7 times

Re: TMR0 rollover value property missing

Post by KikeRico »

Hi

p.erasmus thanks a lot for the explanation, it was very useful :)

I have tried some code in custom interrupt property and is quite straight forward to implement.
FC9 cip.PNG
FC9 cip.PNG (32.84 KiB) Viewed 2306 times
With this I can configure the TMRs as need for programming.

Best reagrds,
Enrique Arroyo.

User avatar
p.erasmus
Valued Contributor
Posts: 434
Joined: Thu Dec 03, 2020 12:01 pm
Location: Russia / Россия
Has thanked: 104 times
Been thanked: 88 times

Re: TMR0 rollover value property missing

Post by p.erasmus »

Hi Enrique,

Note if you preload the Timer High and Timer low with a value from which it starts to count (not from zero) till roll lover you can get any time period you like .

Happy you got it going good luck
Regards Peter - QME Electronics

Post Reply