calcule tmr0
Moderator: Benj
-
- Posts: 14
- Joined: Sun Feb 24, 2013 4:02 am
- Contact:
calcule tmr0
I wonder how and performed the calculation of the timer
I am using an example of the matrix.
TMR0
select clock source: internal clock (CLKO)
source edge select: high-to-low transitionn on TMR0 clock
1:8 prescaler rate
outcome and
8000000hz
976 563 hz frequency
I want to know how and made the calculation.
And how do the LED flashes 2 seconds for the calculation to get it
I am using an example of the matrix.
TMR0
select clock source: internal clock (CLKO)
source edge select: high-to-low transitionn on TMR0 clock
1:8 prescaler rate
outcome and
8000000hz
976 563 hz frequency
I want to know how and made the calculation.
And how do the LED flashes 2 seconds for the calculation to get it
-
- Posts: 714
- Joined: Wed Jan 31, 2007 12:41 pm
- Has thanked: 1 time
- Been thanked: 26 times
- Contact:
Re: calcule tmr0
Hello
have a look to a calculator.....
http://www.libstock.com/projects/view/3 ... calculator
Regards wolfgang
have a look to a calculator.....
http://www.libstock.com/projects/view/3 ... calculator
Regards wolfgang
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: calcule tmr0
Hi brunosilva
This is how I calculate Interrupt frequency:
1/((256-timer offset)*Prescaler Rate/(Clock Frequency/4))
=1/((256-0)*8/(8000000/4))
1/0.001024
= 976.5625Hz
This means that interrupt macro is accessed 976 times every second.
So if you use a integer variable called Count and you want to flash a LED connected to Porta0
Then within interrupt do:
Count = count + 1
If Count >= 1952 then Count = 0: LED_ON=!LED_ON :PortA0 LED_ON
LED_ON is a variable for sending to the port PortA0 output component macro
That should make LED change state every 2 seconds.
Note the timer offset is use to speed timer interrupt up
Timer interrupt triggers when internal register rolls over i.e 254,255,rolls over to 0
If tmr0 is assigned with a number (e.g 100) at the beginning of interrupt macro, then since after rollover instead of counting from 255,0,1,2 etc, it will go 255,0,100,101 etc
Hence rolls over quicker so interrupt frequency is increased.
If this offset is not used then a 0 is used in the calculation.
Try creating a flowchart with the above information to flash LED every two seconds.
If you get stuck then post what you have done so far, and I will take a look at it.
Also please don't double post with the same question.
Martin
This is how I calculate Interrupt frequency:
1/((256-timer offset)*Prescaler Rate/(Clock Frequency/4))
=1/((256-0)*8/(8000000/4))
1/0.001024
= 976.5625Hz
This means that interrupt macro is accessed 976 times every second.
So if you use a integer variable called Count and you want to flash a LED connected to Porta0
Then within interrupt do:
Count = count + 1
If Count >= 1952 then Count = 0: LED_ON=!LED_ON :PortA0 LED_ON
LED_ON is a variable for sending to the port PortA0 output component macro
That should make LED change state every 2 seconds.
Note the timer offset is use to speed timer interrupt up
Timer interrupt triggers when internal register rolls over i.e 254,255,rolls over to 0
If tmr0 is assigned with a number (e.g 100) at the beginning of interrupt macro, then since after rollover instead of counting from 255,0,1,2 etc, it will go 255,0,100,101 etc
Hence rolls over quicker so interrupt frequency is increased.
If this offset is not used then a 0 is used in the calculation.
Try creating a flowchart with the above information to flash LED every two seconds.
If you get stuck then post what you have done so far, and I will take a look at it.
Also please don't double post with the same question.
Martin
Martin
-
- Posts: 14
- Joined: Sun Feb 24, 2013 4:02 am
- Contact:
Re: calcule tmr0
When I know when I'm using a timer 8-bit and 16-bit
how do the calculation to get 3 seguindos in 16-bit
how do i get 3/2 with 8 bits.
cycle machine * preescaler * (so 8/16 - count value of timer 0)
3 000 000 = 0.5 * 128 * (65536 - x)
X = 65536-46875
x = 18661
How to do this using Flowcode without using code c
And if they give me a default value of 976 per second can I have only one I'm checking the examples of matrix but I'm still having trouble
to understand how and held the timer
Thank you
how do the calculation to get 3 seguindos in 16-bit
how do i get 3/2 with 8 bits.
cycle machine * preescaler * (so 8/16 - count value of timer 0)
3 000 000 = 0.5 * 128 * (65536 - x)
X = 65536-46875
x = 18661
How to do this using Flowcode without using code c
And if they give me a default value of 976 per second can I have only one I'm checking the examples of matrix but I'm still having trouble
to understand how and held the timer
Thank you
- Attachments
-
- 2. Interrupt every second test.fcf
- (10.5 KiB) Downloaded 287 times
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: calcule tmr0
Hi brunosilva
Sorry not got time this morning to answer properly.
Take a look at this post:
http://www.matrixmultimedia.com/mmforum ... 14&#p18514
Which should help set your flowchart up to change LED pattern every second.
You may find it better explaining in your native language.
Sorry not got time this morning to answer properly.
Take a look at this post:
http://www.matrixmultimedia.com/mmforum ... 14&#p18514
Which should help set your flowchart up to change LED pattern every second.
You may find it better explaining in your native language.
Martin
-
- Posts: 14
- Joined: Sun Feb 24, 2013 4:02 am
- Contact:
Re: calcule tmr0
I do not understand this calculation timer 0.
In this case he is using a 4 MHz clock that will generate him a time
61,035 hz and also has a delay in the program what it does?
then if it has a <61 seems more time passes than 1 second.
Its help me in my code below.
Sorry for the inconvenience could not understand right that part of TMR0.
thank you
In this case he is using a 4 MHz clock that will generate him a time
61,035 hz and also has a delay in the program what it does?
then if it has a <61 seems more time passes than 1 second.
Its help me in my code below.
Sorry for the inconvenience could not understand right that part of TMR0.
thank you
- Attachments
-
- 2. Interrupt every second Changed to 8MHz (2).fcf
- (11 KiB) Downloaded 262 times
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: calcule tmr0
The delay has not nothing to do with timer0 interrupt, it#s there to prevent issues if component macros are access too fast.
I just chose a random delay time.
So you can forget the delay for calculating interrupt times since interrupt times will stay the same not matter what the delay time is.
In your case it may work just fine without.
If it was me, I would want interrupt running as slow as possible.
So as explained in the link posted choose a prescaler rate of 1:128 since that will produce the lowest interrupt frequency(61.035HZ) that can be rounded to a whole number.
i.e its better to use 61.035 than 31.518 (prescaler rate 1:256)
Reason 1st one is only 0.035 away from a whole number.
Whereas second one is 0.518 away from 31 or 0.482 away from 32 so with both of these there will be higher timing errors.
I have adjusted flowchart with recommended interrupt settings for one second timing, but used the 1:128 which will be better.
The faster the interrupt is serviced then less time is available for the rest of your program.
So use the slowest interrupt time as possible.
If not you will face hardware issues.
Note: Simulation will take much longer that hardware.
Also if using a value higher than 255 e.g
If int_count < 976
Then you MUST use integer type and not byte type since bytes only go from 0 to 255
So if you change int_count from a byte to and integer in the flowchart you posted, that should also work.
I just chose a random delay time.
So you can forget the delay for calculating interrupt times since interrupt times will stay the same not matter what the delay time is.
In your case it may work just fine without.
If it was me, I would want interrupt running as slow as possible.
So as explained in the link posted choose a prescaler rate of 1:128 since that will produce the lowest interrupt frequency(61.035HZ) that can be rounded to a whole number.
i.e its better to use 61.035 than 31.518 (prescaler rate 1:256)
Reason 1st one is only 0.035 away from a whole number.
Whereas second one is 0.518 away from 31 or 0.482 away from 32 so with both of these there will be higher timing errors.
I have adjusted flowchart with recommended interrupt settings for one second timing, but used the 1:128 which will be better.
The faster the interrupt is serviced then less time is available for the rest of your program.
So use the slowest interrupt time as possible.
If not you will face hardware issues.
Note: Simulation will take much longer that hardware.
Also if using a value higher than 255 e.g
If int_count < 976
Then you MUST use integer type and not byte type since bytes only go from 0 to 255
So if you change int_count from a byte to and integer in the flowchart you posted, that should also work.
- Attachments
-
- 2. Interrupt every second Changed to 8MHz V2.fcf
- (11 KiB) Downloaded 298 times
Martin
-
- Posts: 14
- Joined: Sun Feb 24, 2013 4:02 am
- Contact:
-
- Posts: 14
- Joined: Sun Feb 24, 2013 4:02 am
- Contact:
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: calcule tmr0
Hi brunosilva,
You can try attached Flowchart.
Note: Clock speed is set for 8MHz which is what you stated in your first post.
If your using a different crystal (or resonator) then you will need to alter interrupt and count settings.
Best crystal or resonator for the job is a standard 19660800Hz (19.660800MHz)
Reason is because it allows more accurate timing when dividing down.
E.g You can select interrupt frequency of 75.000Hz, 150.000Hz, 300.000Hz etc.
You can try attached Flowchart.
Note: Clock speed is set for 8MHz which is what you stated in your first post.
If your using a different crystal (or resonator) then you will need to alter interrupt and count settings.
Best crystal or resonator for the job is a standard 19660800Hz (19.660800MHz)
Reason is because it allows more accurate timing when dividing down.
E.g You can select interrupt frequency of 75.000Hz, 150.000Hz, 300.000Hz etc.
- Attachments
-
- Five Minute Count OSC 8MHz V1.fcf
- (12.54 KiB) Downloaded 315 times
Martin
-
- Posts: 14
- Joined: Sun Feb 24, 2013 4:02 am
- Contact:
Re: calcule tmr0
thank you
If I want to use 5/2 and so make him repeat 5 times in the right program?
How do I work with the timer counter 0 as
I am not able to create a program that when I precionar the button 5 times turns on a led using timer 0
Thanks for the trouble
If I want to use 5/2 and so make him repeat 5 times in the right program?
How do I work with the timer counter 0 as
I am not able to create a program that when I precionar the button 5 times turns on a led using timer 0
Thanks for the trouble