Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

LOAD value in HELP

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Various
View previous topic :: View next topic  
Author Message
hgrueneis

Bascom Member



Joined: 04 Apr 2009
Posts: 902
Location: A-4786 Brunnenthal

austria.gif
PostPosted: Thu Sep 24, 2015 8:08 pm    Post subject: LOAD value in HELP Reply with quote

The Load value in Help is not supposed to be calculated from 256 but 255 for 8-bit Timers.
"Load Timer0, 10", will load the timer with a value of 245.
Respectively for 16-bit, not from 65536 but 65535.
Count position and count value differ by 1.
Not a big deal but it can have a big effect.
Best regards
Hubert

Quote of text in LOAD HELP:

The TIMER0 does not have a reload mode. But when you want the timer to generate an interrupt after 10 ticks for example, you can use the LOAD statement.

It will do the calculation : (256-value)

So LOAD TIMER0, 10 will load the TIMER0 with a value of 246 so that it will overflow after 10 ticks.

TIMER1 is a 16 bit counter so it will be loaded with the value of 65536-value.
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5922
Location: Holland

blank.gif
PostPosted: Thu Sep 24, 2015 8:24 pm    Post subject: Reply with quote

i do not understand what you mean.
from the help and my understanding of timers :

Quote:
The counting direction is always up (incrementing), and no counter clear is performed. The counter simply
overruns when it passes its maximum 8-bit value (MAX = 0xFF) and then restarts from the bottom (0x00).
In normal operation the Timer/Counter Overflow Flag (TOV0) will be set in the same timer clock cycle as
the TCNT0 becomes zero.


this means that the overflow occurs when timer goes from 255 to 0.
when you load 246 in the timer we get after 10 ticks an overflow.

i have glared at code all day so i could be missing something. please point out what it is i am missing.

_________________
Mark
Back to top
View user's profile Visit poster's website
hgrueneis

Bascom Member



Joined: 04 Apr 2009
Posts: 902
Location: A-4786 Brunnenthal

austria.gif
PostPosted: Thu Sep 24, 2015 11:54 pm    Post subject: Reply with quote

Yes, I know.
Maybe I did not express myself the right way.
The fact is, that there is no value of 256 in an 8-bit system,
other than an overflow that would again represent 0.
The overflow occurs to 0 from 255 Value (the 256th counter state with value 255).
There is no 256 which would be H100 or B1_0000_0000 and therefore 9-bit,
overflow without an additional complete clock cycle to go to 0.
After value 255 it goes directly to B0000_0000.
At least that is my view of the matter.
Best regards
Hubert
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5922
Location: Holland

blank.gif
PostPosted: Fri Sep 25, 2015 3:21 pm    Post subject: Reply with quote

yes i know all that Very Happy
but this is what i wrote ;
it will do the calculation : (256-value)

So LOAD TIMER0, 10 will load the TIMER0 with a value of 246 so that it will overflow after 10 ticks.

To make it simpler here is a value for 1 : 256-1=255.
So when i want the timer to overflow after one tick, i need to load 255. with one clock , the timer overflows to 0 causing the interrupt flag to be set.
I hope it is clear now.

_________________
Mark
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Various All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum