View previous topic :: View next topic |
Author |
Message |
harshanahnd
Joined: 22 Nov 2008 Posts: 11
|
|
Posted: Wed Jan 14, 2009 9:47 am |
|
|
That keyword does not work. Actually there is no keyword as such. I learn that just by not specifying the bit value you get a 16bit timer by default.
Code: |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
|
|
|
|
c0de
Joined: 14 May 2007 Posts: 14
|
Re: Timers - what you should know |
Posted: Wed Apr 01, 2009 7:47 am |
|
|
Hello.
I have a question regarding this tutorial.
In this case:
Code: | void main() {
int i;
setup_timer_0(RTCC_INTERNAL|RTTC_8_BIT|RTCC_DIV_4);
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);
...
i=0;
while(TRUE); // loop forever
} |
the first interrupt occurs after 1024us and using timer0low = timer0low + 6; in the interrupt function the next interrupts occur after 1000us (if I'm not wrong).
Is it possible to have something like in the next code, in order to make the 1st interrupt occur after 1000us? (Or, can we change the timer value while it counts?)
Code: | void main() {
setup_timer_0(RTCC_INTERNAL|RTTC_8_BIT|RTCC_DIV_4);
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);
timer0low = timer0low + 6; // <-----
while(TRUE){ // loop
....
}
} |
Thank you. |
|
|
mutthunaveen
Joined: 08 Apr 2009 Posts: 100 Location: Chennai, India
|
this is absolutely super bro |
Posted: Mon Sep 14, 2009 6:01 am |
|
|
Really I am new to PIC and this gave me clear cut picture of timer based interrupts. Now I am very good at the timer based interrupt concept.
I have a doubt. Can I enable multiple timers such as timer 0, timer 1, and timer2 in a single program?
Could you please write a tutorial on step by step implementation of counter.
I will be very glad if concept known persons start posting tutorials like this with their individual topics (PWM, ADC, ext interrupt, counter, about flags etc) in the CCS. (too much)
It will be very much useful for newbee like me.
Thanks in advance. If you post a new thread on counters or any other. |
|
|
Baesy
Joined: 06 Nov 2009 Posts: 4
|
Timer0 Interrupt with PIC18F45K20 |
Posted: Fri Nov 06, 2009 4:27 am |
|
|
Hello
I work with the "MPLAB IDE" development environment, the CCS C Compiler and the "PIC18F45K20" (from the PicKit3). I want to program a example project with the Timer0. He should give an interrupt, when the timer overflows. I look in the CCS description and try different syntaxes, but it doesn't work. I know how an interrupt works, but I don't know how I have to write it. I have just a few experience in c-programming, but I haven't work with the CCS Compiler. I hope anybody can help me.
Code: |
#include "18F45K20.h"
#fuses INTRC,NOWDT,NOPROTECT,NOMCLR
#int_timer0
timer0_isr()
{
OUTPUT_BIT(PIN_D0, 1);
clear_interrupt(int_timer0);
}
void main(void)
{
setup_timer_0(RTCC_INTERNAL|RTCC_8_BIT|RTCC_DIV_2);
enable_interrupts(GLOBAL);
set_tris_d(0);
set_tris_b(1);
set_timer0(0);
while (1);
} //main
|
PS: Sorry for my english, I'm a Student from Switzerland. |
|
|
rhaguiuda
Joined: 05 Sep 2007 Posts: 46 Location: Londrina - Brazil
|
|
Posted: Fri Nov 06, 2009 6:40 am |
|
|
Hi Baesy
There are some considerations about your code.
You don`t need to clear_interrupt. CCS compiler does that auto for you.
And your code isn`t working because you must enable timer0 interrupt, not only the Global Interrupt. PIC microcontroller has individual interrupt switches.
Use:
Code: | enable_interrupts (INT_TIMER0); |
Hope that helps. _________________ Give a man a fish and you'll feed him for a day. Teach a man to fish, and you'll feed him for a lifetime. |
|
|
Baesy
Joined: 06 Nov 2009 Posts: 4
|
|
Posted: Fri Nov 06, 2009 7:19 am |
|
|
Thanks a lot. It works now. |
|
|
Charliem
Joined: 01 Mar 2010 Posts: 12
|
|
Posted: Wed Mar 10, 2010 8:11 pm |
|
|
About the tutorial at the start of this post.... what pic has a 16bit timer0? _________________ Regards
Charlie M |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1908
|
|
Posted: Thu Mar 11, 2010 8:19 am |
|
|
A lot of them do. Timer 0 of the 18F4520 is 8/16 bit selectable. |
|
|
Charliem
Joined: 01 Mar 2010 Posts: 12
|
|
Posted: Thu Mar 11, 2010 6:15 pm |
|
|
Ok I was thinking of 16F pics. _________________ Regards
Charlie M |
|
|
pacman91
Joined: 17 Jun 2011 Posts: 28 Location: Malaysia
|
|
Posted: Fri Jun 17, 2011 7:11 am |
|
|
I also using PIC18f4520 now, got 4 timer, timer0,1,2,3, alot make confuse eh, but after i saw this post, make me learn much more than i read in the text book i borrow=.=......good job, luv this guy have passion to explain all the things |
|
|
steve.term@yahoo.co.uk
Joined: 09 Nov 2012 Posts: 1
|
Internal Clock Divide by 4 |
Posted: Fri Nov 09, 2012 12:13 pm |
|
|
Hi Guys,
Great topic, thanks for all the info. Can someone explain why the internal clock divides the primary osc by 4? What's the thinking behind that?
Also if I then use a 4x prescaler does that mean its actually a divide by 16 relative to the external osc?
Thanks,
Steve |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Fri Nov 09, 2012 12:21 pm |
|
|
Quote: | Great topic, thanks for all the info. Can someone explain why the internal clock divides the primary osc by 4? What's the thinking behind that? |
Probably because it make the timers advance once per instruction cycle which for many processors is 4 cycles of the crystal (or whatever).
Quote: |
Also if I then use a 4x prescaler does that mean its actually a divide by 16 relative to the external osc? | Yes
Mike |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1908
|
Re: Internal Clock Divide by 4 |
Posted: Fri Nov 09, 2012 12:53 pm |
|
|
steve.term@yahoo.co.uk wrote: | Hi Guys,
Great topic, thanks for all the info. Can someone explain why the internal clock divides the primary osc by 4? What's the thinking behind that?
Also if I then use a 4x prescaler does that mean its actually a divide by 16 relative to the external osc?
Thanks,
Steve |
Consult your PIC's datasheet. The 16F- and 18F- series PICs I'm familiar with have this internal divide by 4 but the dsPICs (the ones I've played with) have a divide by 2. |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Fri Nov 09, 2012 4:09 pm |
|
|
It seems to be consistent.
With the 16 & 18 series devices the master clock divides by 4 for the timers and the instruction cycle.
For the dsPICs the master clock divides by 2 for both.
Mike
EDIT The (I believe now defunct) Harris RTX2000 devices executed most instructions at a rate of one instruction per clock cycle. |
|
|
|