Truncated match.
PICList
Thread
'Helping someone new to this...'
2000\05\15@195447
by
Samuel Ace Winchenbach
|
Hello all.
I am working on a small robot project and need to generate a pulse at 40 -
60 hz (from what I have read so far on servos) that is accurate to within
.01 ms. I will be using a 16F84 and a 10.0 MHz ceramic resonator. I have
done the following math...
10000000 cycle/sec * 1 instruction/4 cycles = 2500000 instructions/sec.
now assuming that I do not prescale it... I also have 2500000 TMR0
Increases/sec.
2500000 TMR0 Increases/sec * 1 loop/X TMR0 Increases = 1000 loops/sec
X = 2500 TMR0 Increases = 10 * 250 TMR0 increases
with this in mind I wrote a simple function in PIC C (I do not assembler...
I really wish I did)
void delay(long int times, int cycles)
{
long int i;
for(i = 0;i < times;i++)
{
TMR0 = 0;
while(TMR0 < cycles);
}
}
so to use this function I should call it like this:
while(1)
{
servo = 1 //turn the servo bit on
delay(10,250); //delay for 1 ms.
servo = 0; //turn the servo bit off.
delay(xxx,xxx); //where xxx,xxx is the numbers needed for a 40hz pulse)
}
unfortunately there is a abit of error somewhere in my method, can anyone
help me track it down? I believe it has to do with the fact that I am not
incorperating the amout of time it takes to execute the instructions in
calling the "delay" routine, and each instruction within that routine. any
help would be much appreciated as would any comments on the method I am
choosing to do this. Also could anyone recommend any good PIC books to
help a begginer get started with PIC Assembler?
Thanks,
Sam
2000\05\15@202847
by
Plunkett, Dennis
16/5/2000
First question is what is the accuracy of your resonator? You have
imposed a requirement of 400ppm.
All that aside at the frequency your are running at the time that it takes
to call the function is a very small percentage of the error.
Can you give us more of an explanation, what is the error that you are
observing etc
Dennis
> {Original Message removed}
2000\05\15@210907
by
Samuel Ace Winchenbach
|
Thanks for your reply.
I am using a 10.000 MHz ceramic resonator with an accuracy of +/- .5%
more or less I am trying to figure out how to do timing as accurately as
possible. I know there is error because using my delay function I calculate
the delay I would need to make an LED blink at 1 Hz...(.5 seconds) using the
method I mentioned earlier:
10000000 cycles/sec * 1 inst./4 cycles = 2500000 inst./sec = 2500000 TMR0
Incs/sec
2500000 TMR0 incs/sec * 1 loop/X TMR0 incs = 2 loops/sec
X = 1250000 TMR0 incs = 5000 * 250 TMR0 incs = .5 secs/loop
here is the code:
#include <16f84.h>
//================================
#pragma config |= 0x3FFF,WDTE=off,FOSC=HS
#pragma bit servo @ PORTA.1
//================================
//do times*cycles TMR0 Increments.
void delay(long int times, int cycles)
{
long int i;
for(i = 0;i < times;i++)
{
TMR0 = 0;
while(TMR0 < cycles);
}
}
//=============================================================
void main(void)
{
INTCON = 0x00;
OPTION = 0x00;
TRISA = 0x00;
while(1) //Create a 1 Hz pulse
{
servo = 0; //Turns LED on (PORTA.1 used to sink current)
delay(5000,250); //delays .5 sec
sevro = 1; //Turns LED off)
delay(5000,250); //delays .5 sec
}
}
//=============================================================
I could tell just by looking at the LED that it was not blinking at 1Hz. It
was going much more slowly than that, closer to .5 Hz. Tomorrow I will be
able to go down to the Electronics lab and use the HP O-Scopes to see
exactly what is going on. But somewhere there is considerable error in my
ways. The only thing that I can think of is.. that I should not set TMR0 =
0, because by the time I get there a certain about of cycles have already
occurred. I would just like to know the best way to solve this problem.
Thanks again,
Samuel
> -----Original Message-----
>
> First question is what is the accuracy of your resonator? You have
>imposed a requirement of 400ppm.
>All that aside at the frequency your are running at the time that it takes
>to call the function is a very small percentage of the error.
>Can you give us more of an explanation, what is the error that you are
>observing etc
> Sam
2000\05\15@213353
by
Samuel Ace Winchenbach
|
Sorry... I have a modification, that was an old version of the code... in
that last version, the prescaler was assigned to TMR0... the code should
look like:
#include <16f84.h>
//================================
#pragma config |= 0x3FFF,WDTE=off,FOSC=HS
#pragma bit servo @ PORTA.1
//================================
//do times*cycles TMR0 Increments.
void delay(long int times, int cycles)
{
long int i;
for(i = 0;i < times;i++)
{
TMR0 = 0;
while(TMR0 < cycles);
}
}
//=============================================================
void main(void)
{
INTCON = 0x00;
OPTION = 0x08; //assign prescaler to WDT
TRISA = 0x00;
while(1) //Create a 1 Hz pulse
{
servo = 0; //Turns LED on (PORTA.1 used
to sink current)
delay(5000,250); //delays .5 sec
sevro = 1; //Turns LED off
delay(5000,250); //delays .5 sec
}
}
//=============================================================
This is the code that seems to blink the LED at .5 Hz, instead of 1 Hz.
Sorry about that, opened the wrong source code file
More... (looser matching)
- Last day of these posts
- In 2000
, 2001 only
- Today
- New search...