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 support@ccsinfo.com

Help me with timer in PIC16F887

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



Joined: 10 Mar 2010
Posts: 10

View user's profile Send private message

Help me with timer in PIC16F887
PostPosted: Tue May 18, 2010 12:41 am     Reply with quote

Hi everybody !

I want to control a DC motor. I use PWM module and timer 0 and timer 1 :

+ Timer 0 : Used to calculate timer.
+ Timer 1 : Used to read pulse from encoder to calculate speed of motor

(timer 2 was used to PWM module)

This is my code :

Code:

   SETUP_TIMER_1(T1_EXTERNAL|T1_DIV_BY_1);
   SETUP_TIMER_0(T0_INTERNAL|T0_DIV_1);



But only timer 0 work, timer 1 doesn't work. (Value of timers is display on PC screen)

When I change code to :
Code:

   SETUP_TIMER_1(T1_INTERNAL|T1_DIV_BY_1);
   SETUP_TIMER_0(T0_EXTERNAL|T0_DIV_1);


In this case, only timer 1 work, timer 0 doesn't work.

If I change this code to :
Code:

   SETUP_TIMER_1(T1_EXTERNAL|T1_DIV_BY_1);
   SETUP_TIMER_0(T0_EXTERNAL|T0_DIV_1);


Both timer 0 and timer 1 work.

I don't know why. Please help me ! Thanks a lot !
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue May 18, 2010 12:48 pm     Reply with quote

1. Are you testing this in Proteus ?
Sometimes Proteus won't work, depending upon the order of the lines
of code.

2. Are you using interrupts with either Timer0 or Timer1 ?

3. What is your compiler version ?
pk178



Joined: 10 Mar 2010
Posts: 10

View user's profile Send private message

PostPosted: Wed May 19, 2010 6:33 am     Reply with quote

I solved this problem.

The problem is timer 0 overflow too fast, so encoder pulse can't increase. After that, I increase prescaler of timer 0 to 256 and it worked ok.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 19, 2010 12:22 pm     Reply with quote

That was one of my suspicions. That's why I asked in #2 if you were
using interrupts. It's similar to the problem in this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=42222
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