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

counter problem

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



Joined: 04 May 2006
Posts: 16

View user's profile Send private message

counter problem
PostPosted: Wed Aug 15, 2007 1:34 am     Reply with quote

hi everbody
I have written a program to control dc motor and I must follow cm data to stop dc motor when it reach its target. I have used encoder (100pals per 1tour) to count the palses.I used timer0 module like this :

#include <16F877.h>
#fuses HS,NOWDT,NOLVP
#use delay(clock=20000000) //one instruction=0.2us
#use rs232(baud=9600, xmit=PIN_c6, rcv=PIN_c7)
.
.
.
setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1);
.
.
.
set_timer0(0);
while(cm < target){
count = get_timer0(0);
if(count > 100) {cm ++; set_timer0(count-100); count = 0;}
}

I used this code : set_timer0(count-100); to don't lose pulses after 100 pulses...
but although my lots of experiments I can't fix cm result exactly.Sometimes result is true but sometimes false.
Where is the problem? Is there a problem from timer0 module? or I used wrong codes?
LEVENT



Joined: 04 May 2006
Posts: 16

View user's profile Send private message

PostPosted: Wed Aug 15, 2007 4:09 am     Reply with quote

I have an another question :
when my pic16f877 runs some codes, at the same time does increase timer0 whith external pulses? Does timer0 module run and increase independent from pic's other operations?
ckielstra



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

View user's profile Send private message

PostPosted: Thu Aug 16, 2007 6:11 am     Reply with quote

LEVENT wrote:
when my pic16f877 runs some codes, at the same time does increase timer0 whith external pulses? Does timer0 module run and increase independent from pic's other operations?
Yes. Timer0 will continue counting in the background independent of other things the processor is doing.

Quote:
but although my lots of experiments I can't fix cm result exactly.Sometimes result is true but sometimes false.
I can't follow you here. What do you mean with the result not being exactly? You say result is true or false. What is result? Please explain more.
LEVENT



Joined: 04 May 2006
Posts: 16

View user's profile Send private message

PostPosted: Thu Aug 16, 2007 7:04 am     Reply with quote

thanks a lot my friend. your answer enough for me. I have wondered about timer0 modules principle and I have learned from your answer.
For my first question, I think that there are some ripples from my encoder and I can reduce them with some capacitances.I will try this thanks a lot...
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