|
|
View previous topic :: View next topic |
Author |
Message |
Torsten Könemann Guest
|
Simple Timer Question ?!? |
Posted: Fri May 09, 2003 9:04 am |
|
|
I wrote a little PIC code (16F84,6MHz) using the timer0.
Every ISR (#INT_Timer0) i change the state of pina0.
I setup the timer with
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_4);
so i expect RTCC Clock of 1.46KHz (0.68ms) as
6MHz/(4*256*4)=1.46KHz
But with a Scope i see that the one state has a time of 0.27ms
Why isn't it 0.68ms long??
I hope its only a little mistake...but i can't find it:-)
Thanks for help!
___________________________
This message was ported from CCS's old forum
Original Post ID: 14297 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: Simple Timer Question ?!? |
Posted: Fri May 09, 2003 11:43 am |
|
|
:=I wrote a little PIC code (16F84,6MHz) using the timer0.
:=Every ISR (#INT_Timer0) i change the state of pina0.
:=I setup the timer with
:=setup_timer_0(RTCC_INTERNAL|RTCC_DIV_4);
---------------------------------------------------
What is your version of the compiler ?
___________________________
This message was ported from CCS's old forum
Original Post ID: 14302 |
|
|
Torsten Könemann Guest
|
Re: Simple Timer Question ?!? |
Posted: Sat May 10, 2003 11:44 am |
|
|
:=:=I wrote a little PIC code (16F84,6MHz) using the timer0.
:=:=Every ISR (#INT_Timer0) i change the state of pina0.
:=:=I setup the timer with
:=:=setup_timer_0(RTCC_INTERNAL|RTCC_DIV_4);
:=---------------------------------------------------
:=
:=What is your version of the compiler ?
PCW Compiler
IDE Version 3.11
PCB Version 3.088
PCM Version 3.088
PCH Version 3.088
Any ideas??
___________________________
This message was ported from CCS's old forum
Original Post ID: 14343 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: Simple Timer Question ?!? |
Posted: Sun May 11, 2003 3:15 pm |
|
|
:=:=What is your version of the compiler ?
:=
:=PCW Compiler
:=IDE Version 3.11
:=PCB Version 3.088
:=PCM Version 3.088
:=PCH Version 3.088
:=
---------------------------------------------------------
I installed PCM vs. 3.088 and made a small test program, below.
This program worked OK. I'm using an 8 MHz crystal, and on
the oscilloscope I saw a square wave that is about 500 us high,
and 500 us low.
The 8 MHz crystal gives a 2 MHz instruction cycle clock.
Then divide that by the specified pre-scaler value of 4 to
give a 500 KHz clock for Timer0. So the clock period is 2 us.
Then Timer0 rolls over every 256 clocks, so 256 x 2 us =
512 us. So that works out correctly. I saw Pin A0 change
state about every 500 us (approximately) on my scope, and
that's what the calculations show that it should be.
I'm using a 16F877 instead of a 16F84, but you should get
a similar result.
Try this test program and see if it works for you.
(You will need to change the #use delay statement to be 6 MHz,
and also change the #fuses so they are correct for a 16F84).
<PRE>
#include "c:\Program Files\Picc\Devices\16F877.H"
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 8000000)
<BR>
<BR>
#int_timer0
void timer0_isr(void)
{
static short pin_state = 0;
<BR>
if(pin_state)
output_high(PIN_A0);
else
output_low(PIN_A0);
<BR>
pin_state = ~pin_state;
<BR>
}
//=====================================
void main()
{
<BR>
set_timer0(0);
setup_timer_0( RTCC_INTERNAL | RTCC_DIV_4);
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);
<BR>
<BR>
while(1);
}
</PRE>
___________________________
This message was ported from CCS's old forum
Original Post ID: 14361 |
|
|
Torsten Könemann Guest
|
Re: Simple Timer Question ?!? |
Posted: Mon May 12, 2003 2:45 am |
|
|
:=:=:=What is your version of the compiler ?
:=:=
:=:=PCW Compiler
:=:=IDE Version 3.11
:=:=PCB Version 3.088
:=:=PCM Version 3.088
:=:=PCH Version 3.088
:=:=
:=---------------------------------------------------------
:=
:=I installed PCM vs. 3.088 and made a small test program, below.
:=This program worked OK. I'm using an 8 MHz crystal, and on
:=the oscilloscope I saw a square wave that is about 500 us high,
:=and 500 us low.
:=
:=The 8 MHz crystal gives a 2 MHz instruction cycle clock.
:=Then divide that by the specified pre-scaler value of 4 to
:=give a 500 KHz clock for Timer0. So the clock period is 2 us.
:=Then Timer0 rolls over every 256 clocks, so 256 x 2 us =
:=512 us. So that works out correctly. I saw Pin A0 change
:=state about every 500 us (approximately) on my scope, and
:=that's what the calculations show that it should be.
:=
:=I'm using a 16F877 instead of a 16F84, but you should get
:=a similar result.
:=
:=Try this test program and see if it works for you.
:=(You will need to change the #use delay statement to be 6 MHz,
:=and also change the #fuses so they are correct for a 16F84).
:=
:=<PRE>
:=#include "c:\Program Files\Picc\Devices\16F877.H"
:=#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
:=#use delay(clock = 8000000)
:=<BR>
:=<BR>
:=#int_timer0
:=void timer0_isr(void)
:={
:=static short pin_state = 0;
:=<BR>
:=if(pin_state)
:= output_high(PIN_A0);
:=else
:= output_low(PIN_A0);
:=<BR>
:=pin_state = ~pin_state;
:=<BR>
:=}
:=
:=
:=//=====================================
:=void main()
:={
:=<BR>
:= set_timer0(0);
:= setup_timer_0( RTCC_INTERNAL | RTCC_DIV_4);
:= enable_interrupts(INT_RTCC);
:= enable_interrupts(GLOBAL);
:=<BR>
:=<BR>
:=while(1);
:=}
:=</PRE>
Thanks for your advice!
My program is nearly the same :-))
I found the mistake this morning. It wasn't the pic or the code. No it was the Scope!! It calibrated it new and now it workes fine...
Thanks again for your reply...
Torsten
___________________________
This message was ported from CCS's old forum
Original Post ID: 14370 |
|
|
|
|
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
|
Powered by phpBB © 2001, 2005 phpBB Group
|