CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

timer0 external input

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
johnl



Joined: 30 Sep 2003
Posts: 120

View user's profile Send private message

timer0 external input
PostPosted: Wed Dec 29, 2004 8:50 pm     Reply with quote

In simulation, timer 1 counts external pulses from a switch properly, but timer 0 does not. Is there something I am missing with the code? (if not then it's probably my simulator.)

The compiler is version 3.214.

Code:
/////////  timer0bug.c ///////////////////////////
#include <18F452.h>

#FUSES HS,NOBROWNOUT,NOWDT,NODEBUG,NOLVP,NOPROTECT

#use delay(clock=20000000)

#byte PORTB=0xF81
#byte PORTD=0xF83

void portinit(void);

main()
  {
   portinit();
   setup_timer_0(RTCC_EXT_L_TO_H);
   setup_timer_1(T1_EXTERNAL  );
   set_timer0(0);
   set_timer1(0);
   while(1)
         {         
         delay_ms(100);
         PORTB=(byte)get_timer0();
         PORTD=(byte)get_timer1();
         }
  }


portinit()
  {
   set_tris_a(0b00010000);      // all port A outputs except A4 for timer0  input
   set_tris_b(0b00000000);      // all port B outputs
   set_tris_c(0b00000001);      // all port C outputs except C0 for timer1  input
   
   set_tris_d(0b00000000);      // all port D outputs
   set_tris_e(0b00000000);      // all port E outputs
   

   }


Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Thu Dec 30, 2004 5:45 am     Reply with quote

Keep in mind that RA4/T0CKI pin is a Schmitt Trigger input and an open drain output. All other RA port pins have TTL input levels and
full CMOS output drivers.
Guest








Re: timer0 external input
PostPosted: Thu Dec 30, 2004 6:47 am     Reply with quote

Check the prescalers.
Timer0 can only count every other pulse.
Timer1 can count all pulses.

setup_timer_0(RTCC_EXT_L_TO_H | RTCC_DIV_2);

setup_timer_1(T1_EXTERNAL | T1_DIV_BY_1);
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Dec 30, 2004 7:17 am     Reply with quote

I guess that Guest meant that in your example program the Timer0 is configured to divide by 2. If you don't specify the prescaler value, then it defaults to a divide by 2, a stupid default value.

If you want timer0 not to divide the input signal, then configure it as
setup_timer_0(RTCC_EXT_L_TO_H | RTCC_DIV_1);
johnl



Joined: 30 Sep 2003
Posts: 120

View user's profile Send private message

PostPosted: Thu Dec 30, 2004 8:35 am     Reply with quote

The prescaler doesn't seem to be an issue since timer0 is not counting at all. Port B always shows a count of zero (the pre-loaded value) regardless of the number of input pulses.

Haplo, A4 is an input so the open drain doesn't matter. I tested the A4 pin as an input and it works. I also tested timer0 with the internal clock and it works. I just can't get the A4 pin to work as an input to timer0.

It seems like thing are pointing to my simulator....

Thanks to all.
ljbeng



Joined: 10 Feb 2004
Posts: 205

View user's profile Send private message

PostPosted: Thu Dec 30, 2004 9:04 am     Reply with quote

I am using the 18F4620 and RA4 is incrementing timer 0 just fine. If you look at the chip data book, reading timer 0 (get_timer0()) will return a 16 bit value and is prescaled 2:1.
johnl



Joined: 30 Sep 2003
Posts: 120

View user's profile Send private message

PostPosted: Thu Dec 30, 2004 9:09 am     Reply with quote

ljbeng - Are you using similar code (or my code)?
johnl



Joined: 30 Sep 2003
Posts: 120

View user's profile Send private message

PostPosted: Thu Dec 30, 2004 7:14 pm     Reply with quote

I just confirmed that it does work in hardware -so the simulator has a problem.

Thanks to all who responded.

Happy New Year.
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Fri Dec 31, 2004 2:21 am     Reply with quote

What simulator are you using?
johnl



Joined: 30 Sep 2003
Posts: 120

View user's profile Send private message

PostPosted: Fri Dec 31, 2004 8:45 am     Reply with quote

I am using Proteus VSM. Overall it works well and saves developing time. It's really handy to work out many code and hardware issues without having to prototype hardware.

Some of the models for PIC12 and PIC18 have bugs but they are working on that.


John
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
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


Powered by phpBB © 2001, 2005 phpBB Group