View previous topic :: View next topic |
Author |
Message |
LEVENT
Joined: 04 May 2006 Posts: 16
|
counter problem |
Posted: Wed Aug 15, 2007 1:34 am |
|
|
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
|
|
Posted: Wed Aug 15, 2007 4:09 am |
|
|
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
|
|
Posted: Thu Aug 16, 2007 6:11 am |
|
|
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
|
|
Posted: Thu Aug 16, 2007 7:04 am |
|
|
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... |
|
|
|